Creating a pipeline with deployments/environments/others 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. Creating a pipeline with deployments/environments writes to the environments
and deployments
table in the context of a transaction that is already writing to the ci_pipelines
(among other CI tables).
To reproduce I needed to remove this test from the allowlist https://gitlab.com/gitlab-org/gitlab/blob/master/lib/gitlab/database/gitlab_schemas.yml and see the failure:
$ rspec ./spec/lib/gitlab/ci/templates/AWS/deploy_ecs_gitlab_ci_yaml_spec.rb:53
Failures:
1) Deploy-ECS.gitlab-ci.yml the created pipeline when running a pipeline for a branch when deploying to ECS Fargate creates the expected jobs
Failure/Error: raise CrossDatabaseModificationAcrossUnsupportedTablesError, message
Gitlab::Database::QueryAnalyzers::PreventCrossDatabaseModification::CrossDatabaseModificationAcrossUnsupportedTablesError:
Cross-database data modification of 'gitlab_ci, gitlab_main' were detected within a transaction modifying the 'ci_pipelines, ci_stages, ci_builds, ci_builds_metadata, deployments' tables.Please
refer to https://docs.gitlab.com/ee/development/database/multiple_databases.html#removing-cross-database-transactions for details on how to resolve this exception.
For now we have added this violation to the allowlist https://gitlab.com/gitlab-org/gitlab/-/blob/master/spec/support/database/cross-database-modification-allowlist.yml .
The problem seems to exist for all the following tables:
deployments
environments
deployment_clusters
- probably others
Possible solutions
You can see a similar fix in !73042 (merged) which may well be applicable here too.