Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrations fail when slave replication is running significantly behind master #336

Closed
edhgoose opened this issue Aug 11, 2015 · 4 comments · Fixed by #479
Closed

Migrations fail when slave replication is running significantly behind master #336

edhgoose opened this issue Aug 11, 2015 · 4 comments · Fixed by #479
Labels

Comments

@edhgoose
Copy link

Hi,

We have a problem where our build script will fail if run after another longer running migration.

If our build script executes and starts running a long migration it'll randomly (it appears) pick one of our three database instances, where 2 are slaves and one is master. The following can happen:

  1. Migration begins on randomly chosen database instance. Let's say the master is picked.
  2. Migration is large, and replication is unusually slow so the 2 slaves lag behind.
  3. Build completes, but replication still running.
  4. A new build (e.g. a hotfix) is kicked off.
  5. Migrations runs again, but picks a slave this time - i.e. one of the database instances which is running behind.
  6. It checks the migrations, and decides the migration hasn't been run yet because the replication hasn't finished.
  7. Build fails because of an integrity constraint - the change it wants to apply has already been (at least partially) applied.

I'd expect, or assume there would be an option, to force the migrations to operate against the master (or a specific) database.

I'm using MySQL in Amazon's RDS if that helps.

Thanks!
Ed

@edhgoose edhgoose changed the title Migrations fail when slave is running behind a master Migrations fail when slave replication is running significantly behind master Aug 11, 2015
@stof
Copy link
Member

stof commented Aug 11, 2015

Are you using the MasterSlaveConnection of DBAL ?

@edhgoose
Copy link
Author

Yes, I believe so. We're using it with Symfony2 and our configuration looks like this:

doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                driver:   "%database_driver%"
                host:     "%database_host%"
                port:     "%database_port%"
                dbname:   "%database_name%"
                user:     "%database_user%"
                password: "%database_password%"
                charset:  utf8mb4

and in doctrine_slaves.yml:

doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                slaves:
                    readonlyslave2:
                        host:     "%database_host_slave2%"
                        port:     "%database_port%"
                        dbname:   "%database_name%"
                        user:     "%database_user%"
                        password: "%database_password%"
                        charset:  utf8mb4
                    readonlyslave3:
                        host:     "%database_host_slave3%"
                        port:     "%database_port%"
                        dbname:   "%database_name%"
                        user:     "%database_user%"
                        password: "%database_password%"
                        charset:  utf8mb4

@stof
Copy link
Member

stof commented Aug 11, 2015

OK, then I have an idea to fix it. Expect it to be submitted in the next few days

@edhgoose
Copy link
Author

Magnificent, thank you very much.

chrisguitarguy added a commit to chrisguitarguy/migrations that referenced this issue Jul 6, 2016
And account for uses of `MasterSlaveConnection`. If there is a
`MasterSlaveConnection` in use, the migrations system should always talk
to master just incase replication is behind the next migration
execution.

Should (hopefully) close doctrine#336
mikeSimonson pushed a commit that referenced this issue Jul 7, 2016
And account for uses of `MasterSlaveConnection`. If there is a
`MasterSlaveConnection` in use, the migrations system should always talk
to master just incase replication is behind the next migration
execution.

Should (hopefully) close #336
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants