summaryrefslogtreecommitdiff
path: root/lib/gitlab/database/reindexing/index_selection.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/database/reindexing/index_selection.rb')
-rw-r--r--lib/gitlab/database/reindexing/index_selection.rb21
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/gitlab/database/reindexing/index_selection.rb b/lib/gitlab/database/reindexing/index_selection.rb
index 2d384f2f9e2..ebe245bfadb 100644
--- a/lib/gitlab/database/reindexing/index_selection.rb
+++ b/lib/gitlab/database/reindexing/index_selection.rb
@@ -12,6 +12,10 @@ module Gitlab
# Only consider indexes beyond this size (before reindexing)
INDEX_SIZE_MINIMUM = 1.gigabyte
+ VERY_LARGE_TABLES = %i[
+ ci_builds
+ ].freeze
+
delegate :each, to: :indexes
def initialize(candidates)
@@ -30,13 +34,24 @@ module Gitlab
# we force a N+1 pattern here and estimate bloat on a per-index
# basis.
- @indexes ||= candidates
- .not_recently_reindexed
- .where('ondisk_size_bytes >= ?', INDEX_SIZE_MINIMUM)
+ @indexes ||= relations_that_need_cleaning_before_deadline
.sort_by(&:relative_bloat_level) # forced N+1
.reverse
.select { |candidate| candidate.relative_bloat_level >= MINIMUM_RELATIVE_BLOAT }
end
+
+ def relations_that_need_cleaning_before_deadline
+ relation = candidates.not_recently_reindexed.where('ondisk_size_bytes >= ?', INDEX_SIZE_MINIMUM)
+ relation = relation.where.not(tablename: VERY_LARGE_TABLES) if too_late_for_very_large_table?
+ relation
+ end
+
+ # The reindexing process takes place during the weekends and starting a
+ # reindexing action on a large table late on Sunday could span during
+ # Monday. We don't want this because it prevents vacuum from running.
+ def too_late_for_very_large_table?
+ !Date.today.saturday?
+ end
end
end
end