Skip to content

Commit d87516c

Browse files
balasankarcibaum
andcommitted
Merge branch 'fix-geo-pg-upgrade-calls' into 'master'
Ensure post upgrade steps are run after geo_pg_upgrade See merge request https://gitlab.com/gitlab-org/omnibus-gitlab/-/merge_requests/7247 Merged-by: Balasankar 'Balu' C <[email protected]> Approved-by: Douglas Barbosa Alexandre <[email protected]> Approved-by: Javiera Tapia <[email protected]> Approved-by: Dustin Collins <[email protected]> Approved-by: Balasankar 'Balu' C <[email protected]> Reviewed-by: Balasankar 'Balu' C <[email protected]> Reviewed-by: Ian Baum <[email protected]> Co-authored-by: Ian Baum <[email protected]>
2 parents c5702a1 + 3cd54e0 commit d87516c

File tree

6 files changed

+33
-22
lines changed

6 files changed

+33
-22
lines changed

files/gitlab-cookbooks/gitlab-ee/recipes/geo-postgresql.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
geo_pg_helper = GeoPgHelper.new(node)
3131

32+
database_version = geo_pg_helper.database_version || geo_pg_helper.version
33+
3234
directory node['gitlab']['geo_postgresql']['dir'] do
3335
owner postgresql_username
3436
mode '0755'
@@ -107,7 +109,8 @@
107109
options({
108110
log_directory: logging_settings[:log_directory],
109111
log_user: logging_settings[:runit_owner],
110-
log_group: logging_settings[:runit_group]
112+
log_group: logging_settings[:runit_group],
113+
database_version: database_version.major
111114
}.merge(params))
112115
log_options logging_settings[:options]
113116
end
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/bin/sh
22
exec 2>&1
33
<%= render('mount_point_check.erb') %>
4-
exec chpst -P -U <%= node['postgresql']['username'] %>:<%= node['postgresql']['group'] %> -u <%= node['postgresql']['username'] %>:<%= node['postgresql']['group'] %> /opt/gitlab/embedded/bin/postgres -D <%= File.join(node['gitlab']['geo_postgresql']['dir'], 'data') %>
4+
exec chpst -P -U <%= node['postgresql']['username'] %>:<%= node['postgresql']['group'] %> \
5+
-u <%= node['postgresql']['username'] %>:<%= node['postgresql']['group'] %> \
6+
/opt/gitlab/embedded/postgresql/<%= @options[:database_version] %>/bin/postgres \
7+
-D <%= File.join(node['gitlab']['geo_postgresql']['dir'], 'data') %>

files/gitlab-cookbooks/postgresql/recipes/bin.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@
2020
geo_pg_helper = GeoPgHelper.new(node)
2121
omnibus_helper = OmnibusHelper.new(node)
2222
postgresql_install_dir = File.join(node['package']['install-dir'], 'embedded/postgresql')
23-
24-
if Services.enabled?('postgresql')
25-
running_db_version = pg_helper.database_version
26-
elsif Services.enabled?('geo_postgresql')
27-
running_db_version = geo_pg_helper.database_version
28-
end
23+
running_db_version = if Services.enabled?('geo_postgresql') && !Services.enabled?('postgresql')
24+
geo_pg_helper.database_version
25+
else
26+
pg_helper.database_version
27+
end
2928

3029
db_version = node['postgresql']['version'] || running_db_version
3130
db_path = Dir.glob("#{postgresql_install_dir}/#{db_version}*").min if db_version

files/gitlab-cookbooks/postgresql/recipes/standalone.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
options({
1616
log_directory: logging_settings[:log_directory],
1717
log_user: logging_settings[:runit_owner],
18-
log_group: logging_settings[:runit_group],
18+
log_group: logging_settings[:runit_group]
1919
}.merge(params))
2020
log_options logging_settings[:options]
2121
end

files/gitlab-ctl-commands/lib/gitlab_ctl/pg_upgrade.rb

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module GitlabCtl
1616
class PgUpgrade
1717
include GitlabCtl::Util
1818
attr_accessor :base_path, :data_path, :tmp_dir, :timeout, :target_version, :initial_version, :psql_command, :port
19+
1920
attr_writer :data_dir, :tmp_data_dir
2021

2122
def initialize(base_path, data_path, target_version, tmp_dir = nil, timeout = nil, psql_command = nil, port = nil)
@@ -26,7 +27,7 @@ def initialize(base_path, data_path, target_version, tmp_dir = nil, timeout = ni
2627
@target_version = target_version
2728
@initial_version = fetch_running_version
2829
@port = port || public_node_attributes['postgresql']['port']
29-
@psql_command ||= "gitlab-psql"
30+
@psql_command = psql_command || "gitlab-psql"
3031
end
3132

3233
def data_dir
@@ -136,6 +137,10 @@ def upgrade_artifact_exists?(path)
136137
!Dir.empty?(path)
137138
end
138139

140+
def log(message)
141+
$stderr.puts message
142+
end
143+
139144
def run_pg_upgrade
140145
unless GitlabCtl::Util.progress_message('Upgrading the data') do
141146
begin
@@ -147,17 +152,17 @@ def run_pg_upgrade
147152
"-B #{target_version_path}/bin "
148153
)
149154
rescue GitlabCtl::Errors::ExecutionError => e
150-
$stderr.puts "Error upgrading the data to version #{target_version}"
151-
$stderr.puts "STDOUT: #{e.stdout}"
152-
$stderr.puts "STDERR: #{e.stderr}"
155+
log "Error upgrading the data to version #{target_version}"
156+
log "STDOUT: #{e.stdout}"
157+
log "STDERR: #{e.stderr}"
153158
false
154159
rescue Mixlib::ShellOut::CommandTimeout
155-
$stderr.puts
156-
$stderr.puts "Timed out during the database upgrade.".color(:red)
157-
$stderr.puts "To run with more time, remove the temporary directory #{tmp_data_dir}.#{target_version.major},".color(:red)
158-
$stderr.puts "then re-run your previous command, adding the --timeout option.".color(:red)
159-
$stderr.puts "See the docs for more information: https://docs.gitlab.com/omnibus/settings/database.html#upgrade-packaged-postgresql-server".color(:red)
160-
$stderr.puts "Or run gitlab-ctl pg-upgrade --help for usage".color(:red)
160+
log
161+
log "Timed out during the database upgrade.".color(:red)
162+
log "To run with more time, remove the temporary directory #{tmp_data_dir}.#{target_version.major},".color(:red)
163+
log "then re-run your previous command, adding the --timeout option.".color(:red)
164+
log "See the docs for more information: https://docs.gitlab.com/omnibus/settings/database.html#upgrade-packaged-postgresql-server".color(:red)
165+
log "Or run gitlab-ctl pg-upgrade --help for usage".color(:red)
161166
false
162167
end
163168
end

files/gitlab-ctl-commands/pg-upgrade.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,15 +366,16 @@ def patroni_leader_upgrade
366366
def patroni_replica_upgrade
367367
stop_database
368368
create_links(@db_worker.target_version)
369-
common_post_upgrade(false)
369+
common_post_upgrade(!@geo_pg_enabled)
370+
cleanup_data_dir
370371
geo_pg_upgrade
371372
end
372373

373374
def patroni_standby_leader_upgrade
374375
stop_database
375376
create_links(@db_worker.target_version)
376377
remove_patroni_cluster_state
377-
common_post_upgrade(false)
378+
common_post_upgrade(!@geo_pg_enabled)
378379
geo_pg_upgrade
379380
end
380381

@@ -469,7 +470,6 @@ def geo_secondary_upgrade(tmp_dir, timeout)
469470
end
470471

471472
geo_pg_upgrade
472-
common_post_upgrade
473473
end
474474

475475
def geo_pg_upgrade
@@ -493,6 +493,7 @@ def geo_pg_upgrade
493493
rescue GitlabCtl::Errors::ExecutionError
494494
die "Error running pg_upgrade on secondary, please check logs"
495495
end
496+
common_post_upgrade
496497
end
497498

498499
def get_locale_encoding

0 commit comments

Comments
 (0)