Class: Import::ReassignPlaceholderThrottling

Inherits:
Object
  • Object
show all
Defined in:
lib/import/reassign_placeholder_throttling.rb

Defined Under Namespace

Classes: DatabaseHealthStatusChecker

Constant Summary collapse

DATABASE_TABLE_HEALTH_INDICATORS =
[Gitlab::Database::HealthStatus::Indicators::AutovacuumActiveOnTable].freeze
GLOBAL_DATABASE_HEALTH_INDICATORS =
[
  Gitlab::Database::HealthStatus::Indicators::WriteAheadLog,
  Gitlab::Database::HealthStatus::Indicators::PatroniApdex
].freeze
DatabaseHealthError =
Class.new(StandardError)

Instance Method Summary collapse

Constructor Details

#initialize(import_source_user) ⇒ ReassignPlaceholderThrottling

Returns a new instance of ReassignPlaceholderThrottling.



14
15
16
17
18
# File 'lib/import/reassign_placeholder_throttling.rb', line 14

def initialize(import_source_user)
  @import_source_user = import_source_user
  @reassigned_by_user = import_source_user.reassigned_by_user
  @unavailable_tables = []
end

Instance Method Details

#db_health_check!Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/import/reassign_placeholder_throttling.rb', line 41

def db_health_check!
  return if Feature.disabled?(:reassignment_throttling, reassigned_by_user)

  stop_signal = Rails.cache.fetch("reassign_placeholder_user_records_service_db_check", expires_in: 30.seconds) do
    gitlab_schema = :gitlab_main

    health_context = Gitlab::Database::HealthStatus::Context.new(
      DatabaseHealthStatusChecker.new(import_source_user.id, self.class.name),
      schema_connection(gitlab_schema),
      []
    )

    Gitlab::Database::HealthStatus.evaluate(health_context, GLOBAL_DATABASE_HEALTH_INDICATORS).any?(&:stop?)
  end

  raise DatabaseHealthError, "Database unhealthy" if stop_signal
end

#db_table_unavailable?(model_relation) ⇒ Boolean

The #db_table_unavailable? check is behind a feature flag that we intend not to roll out. The flag is a conservative measure to allow us to enable it IF it’s determined that we should be delaying reassignments when tables are being autovacuumed. See gitlab.com/gitlab-org/gitlab/-/issues/525566#note_2418809939.

TODO Remove the following block of code, and all related code (unavailable_tables, #db_table_unavailable?, and DATABASE_TABLE_HEALTH_INDICATORS) as part of gitlab.com/gitlab-org/gitlab/-/issues/534613

If table health check fails, skip processing this relation and move on to the next one. We later raise a DatabaseHealthError to reschedule the reassignment where the skipped relations can be tried again.

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
# File 'lib/import/reassign_placeholder_throttling.rb', line 32

def db_table_unavailable?(model_relation)
  return false if Feature.disabled?(:reassignment_throttling, reassigned_by_user)
  return false if Feature.disabled?(:reassignment_throttling_table_check, reassigned_by_user)
  return false unless autovacuum_active?(model_relation)

  unavailable_tables << model_relation.table_name
  true
end

#unavailable_tables?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/import/reassign_placeholder_throttling.rb', line 59

def unavailable_tables?
  unavailable_tables.any?
end