Skip to content

Destroying a Ci::JobArtifact causes a CrossDatabaseModificationAcrossUnsupportedTablesError creating geo_job_artifact_deleted_events

Problem

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.

We have such an error caused by after_destroy :log_geo_deleted_event.

  16) Ci::JobArtifact#destroy creates a JobArtifactDeletedEvent                                                                                                                                          
      Failure/Error: raise Database::PreventCrossDatabaseModification::CrossDatabaseModificationAcrossUnsupportedTablesError, message                                                                    
                                                                                                                                                                                                         
      Database::PreventCrossDatabaseModification::CrossDatabaseModificationAcrossUnsupportedTablesError:                                                                                                 
        Cross-database data modification of 'gitlab_ci, gitlab_main' were detected within a transaction modifying the 'ci_job_artifacts, geo_job_artifact_deleted_events' 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. 

Solution

See https://docs.gitlab.com/ee/development/database/multiple_databases.html#removing-cross-database-transactions .

This probably best handled with after_commit on destroy.

Edited by Dylan Griffith