diff options
Diffstat (limited to 'lib/gitlab/database/query_analyzers/prevent_cross_database_modification.rb')
-rw-r--r-- | lib/gitlab/database/query_analyzers/prevent_cross_database_modification.rb | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/gitlab/database/query_analyzers/prevent_cross_database_modification.rb b/lib/gitlab/database/query_analyzers/prevent_cross_database_modification.rb index 2e3db2a5c6e..a604f79dc41 100644 --- a/lib/gitlab/database/query_analyzers/prevent_cross_database_modification.rb +++ b/lib/gitlab/database/query_analyzers/prevent_cross_database_modification.rb @@ -56,6 +56,9 @@ module Gitlab context[:transaction_depth_by_db][database] -= 1 if context[:transaction_depth_by_db][database] == 0 context[:modified_tables_by_db][database].clear + + # Attempt to troubleshoot https://gitlab.com/gitlab-org/gitlab/-/issues/351531 + ::CrossDatabaseModification::TransactionStackTrackRecord.log_gitlab_transactions_stack(action: :end_of_transaction) elsif context[:transaction_depth_by_db][database] < 0 context[:transaction_depth_by_db][database] = 0 raise CrossDatabaseModificationAcrossUnsupportedTablesError, "Misaligned cross-DB transactions discovered at query #{sql}. This could be a bug in #{self.class} or a valid issue to investigate. Read more at https://docs.gitlab.com/ee/development/database/multiple_databases.html#removing-cross-database-transactions ." @@ -87,6 +90,8 @@ module Gitlab all_tables = context[:modified_tables_by_db].values.map(&:to_a).flatten schemas = ::Gitlab::Database::GitlabSchema.table_schemas(all_tables) + schemas += ApplicationRecord.gitlab_transactions_stack + if schemas.many? message = "Cross-database data modification of '#{schemas.to_a.join(", ")}' were detected within " \ "a transaction modifying the '#{all_tables.to_a.join(", ")}' tables." \ |