Skip to content

Commit ad427bc

Browse files
balasankarcAndrew Patterson
andcommitted
Merge branch '5660-pg_upgrade_with_tmp_dir' into 'master'
pg-upgrade: Do not check data_dir free space for for --tmp-data_dir Closes #5660 See merge request https://gitlab.com/gitlab-org/omnibus-gitlab/-/merge_requests/6987 Merged-by: Balasankar 'Balu' C <[email protected]> Approved-by: Hossein Pursultani <[email protected]> Approved-by: Balasankar 'Balu' C <[email protected]> Co-authored-by: Andrew Patterson <[email protected]>
2 parents 2c7516b + 3dd5f3e commit ad427bc

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ def tmp_data_dir
4848
@tmp_data_dir = @tmp_dir ? "#{@tmp_dir}/data" : data_dir
4949
end
5050

51-
def enough_free_space?(dir)
52-
space_needed(dir) <= space_free(dir)
51+
def enough_free_space?(dir, needed)
52+
needed <= space_free(dir)
5353
end
5454

5555
def space_needed(dir)

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,18 +189,25 @@
189189
Kernel.exit 0
190190
end
191191

192+
total_space_needed = 0 # in MiB
192193
unless options[:skip_disk_check]
193-
check_dirs = [@db_worker.tmp_dir]
194-
check_dirs << @db_worker.data_dir if pg_enabled || patroni_enabled
195-
check_dirs << File.join(@attributes['gitlab']['geo_postgresql']['dir'], 'data') if geo_enabled
194+
check_dirs = {}
195+
check_dirs[@db_worker.data_dir] = 0 if pg_enabled || patroni_enabled
196+
check_dirs[File.join(@attributes['gitlab']['geo_postgresql']['dir'], 'data')] = 0 if geo_enabled
197+
check_dirs.each_key do |dir|
198+
check_dirs[dir] = @db_worker.space_needed(dir)
199+
total_space_needed += check_dirs[dir]
200+
end
201+
# We need space for all databases if using --tmp-dir.
202+
check_dirs = { @db_worker.tmp_dir => total_space_needed } if @db_worker.tmp_dir
196203

197-
check_dirs.compact.uniq.each do |dir|
204+
check_dirs.each do |dir, space_needed|
198205
unless GitlabCtl::Util.progress_message(
199206
"Checking if disk for directory #{dir} has enough free space for PostgreSQL upgrade"
200207
) do
201-
@db_worker.enough_free_space?(dir)
208+
@db_worker.enough_free_space?(dir, space_needed)
202209
end
203-
log "Upgrade requires #{@db_worker.space_needed(dir)}MB, but only #{@db_worker.space_free(dir)}MB is free."
210+
log "Upgrade requires #{space_needed}MB, but only #{@db_worker.space_free(dir)}MB is free."
204211
Kernel.exit 1
205212
end
206213
next

spec/chef/gitlab-ctl-commands/lib/gitlab_ctl_pg_upgrade_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def stub_postgresql_json_attributes(config = nil)
6868
"df -P --block-size=1m #{@dbw.data_dir} | awk '{print $4}'", nil, 123
6969
).and_return("Available\n220000")
7070

71-
expect(@dbw.enough_free_space?(@dbw.data_dir)).to eq(false)
71+
expect(@dbw.enough_free_space?(@dbw.data_dir, 440000)).to eq(false)
7272
end
7373

7474
it 'detects when there is enough available disk space for upgrade' do
@@ -80,7 +80,7 @@ def stub_postgresql_json_attributes(config = nil)
8080
"df -P --block-size=1m #{@dbw.data_dir} | awk '{print $4}'", nil, 123
8181
).and_return("Available\n250000")
8282

83-
expect(@dbw.enough_free_space?(@dbw.data_dir)).to eq(true)
83+
expect(@dbw.enough_free_space?(@dbw.data_dir, 100000)).to eq(true)
8484
end
8585
end
8686

0 commit comments

Comments
 (0)