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

Database concurrency issues #1435

Closed
ashtripathi opened this issue Sep 16, 2016 · 1 comment
Closed

Database concurrency issues #1435

ashtripathi opened this issue Sep 16, 2016 · 1 comment

Comments

@ashtripathi
Copy link

What version of Flyway are you using?

4.0.3

Which client are you using? (Command-line, Java API, Maven plugin, Gradle plugin, SBT plugin, ANT tasks)

Java API

What database are you using (type & version)?

Oracle 12.1.0.2.0 & MySQL 5.6

What operating system are you using?

Linux Docker Containers

What did you do?

We're using Flyway to execute the initial DB migration scripts before starting our webapp. Since our webapp is packaged inside a docker alpine image & is run as a swarm of containers simultaneously, all different container nodes start executing the migration scripts together on a single centralized database instance (Oracle 12c or MySQL) and the migration fails on all but one node.

The configuration is pretty straight-forward:

        final Flyway flyway = new Flyway();
        flyway.setDataSource(datasource);
        flyway.setLocations("filesystem:"+script.getAbsolutePath());
        flyway.migrate();
        flyway.validate();

and the containers of our webapp are brought up using:

docker service create --replicas=10 .....database properties

What did you expect to see?

Shouldn't flyway be using database locks and allow just one container service to create the database? We expected to see any one node to successfully create the database while others say something like 'no migration necessary'.

What did you see instead?

All nodes (except one) throw FlywayExceptions saying

org.flywaydb.core.internal.dbsupport.FlywaySqlScriptException:
Script failed
-------------
SQL State  : 42000
Error Code : 955
Message    : ORA-00955: name is already used by an existing object
Line       : 17
Statement  : CREATE TABLE "MYWEBAPP"."schema_version" (
    "installed_rank" INT NOT NULL,
    "version" VARCHAR2(50),
    "description" VARCHAR2(200) NOT NULL,
    "type" VARCHAR2(20) NOT NULL,
    "script" VARCHAR2(1000) NOT NULL,

or

org.flywaydb.core.api.FlywayException: Found non-empty schema "MYWEBAPP" without metadata table! Use baseline() or set baselineOnMigrate to true to initialize the metadata table.
        at org.flywaydb.core.Flyway$1.execute(Flyway.java:943)
        at org.flywaydb.core.Flyway$1.execute(Flyway.java:917)
        at org.flywaydb.core.Flyway.execute(Flyway.java:1373)

Is there something obvious that we are missing?

Thanks!

@axelfontaine
Copy link
Contributor

Duplicate of #1067

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants