update_pending_builds! when transferring group or project causes CrossDatabaseModificationAcrossUnsupportedTablesError
Per https://docs.gitlab.com/ee/development/database/multiple_databases.html#removing-cross-database-transactions we do not allow you to write to 2 different databases within the context of a single transaction.
Currently this is happening when transferring a group at:
-
update_pending_builds!
inGroups::TransferService
https://gitlab.com/gitlab-org/gitlab/-/blob/4fa116b0a9822f76e257c26199673319db7b2913/app/services/groups/transfer_service.rb#L32 -
update_pending_builds!
inProjects::TransferService
https://gitlab.com/gitlab-org/gitlab/-/blob/4fa116b0a9822f76e257c26199673319db7b2913/app/services/projects/transfer_service.rb#L253 1.update_group_attributes -> inherit_group_shared_runners_settings -> Groups::UpdateSharedRunnersService
https://gitlab.com/gitlab-org/gitlab/blob/master/app/services/groups/transfer_service.rb#L214 - Also possibly happening in other usages of
Groups::UpdateSharedRunnersService
such asGroups::UpdateService
but at a glance this service is not using a transaction in the same way as the transfer service so it may not have this issue, though we should validate that
How to test this
This failure has been added to either spec/support/database/cross-database-modification-allowlist.yml
or an explicit allow_cross_database_modification_within_transaction
has been wrapped around the offending code. Removing the corresponding allowlist item and running any RSpec test that executes this code path should reveal the problem
$ rspec
How to fix this
This failure has been added to either spec/support/database/cross-database-modification-allowlist.yml
or an explicit allow_cross_database_modification_within_transaction
has been wrapped around the offending code. A fix for this problem should remove the corresponding allowlist items.
See possible solutions for this at https://docs.gitlab.com/ee/development/database/multiple_databases.html#removing-cross-database-transactions .
You may also be able to search for fixes to similar problems or you can ask in #g_sharding
if something is unclear.