-
Notifications
You must be signed in to change notification settings - Fork 31
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
[Help] Running multiple migratedb tool in parallel #49
Comments
Hi @dmourao, Thanks for reporting this issue! It is true that scala-forklift lacks support for parallel runs on the same database. I imagine that the migration tool will only be executed during deployment, not on productions, and only one application is responsible for running the migrations, but that certainly excludes some special scenarios. I wonder what is the reason that you will need all replicas to update the same database? Are they running the same script or are they updating disjoint parts/tables of the same database? Is the motivation that you run migrations in parallel to speed up the migration process or there are other reasons? |
Hi @lastland , and thanks for your response. In fact, when N replicas start (at the same time), i only want that one of the replicas do the migration process, while other replicas just waits. We are using kubernetes for deployment and management of our cloud solution. When kubernetes deploys my application (N replicas), each replica at boot/startup is trying to ensure that database is created or updated, doing the migrate-db process. Each replica is executing the same SQL script. First i was thinking to lock |
Locking Another possibility is to have a designated replica to do the migrations. If your application is using a master+replicas architecture, then the master node sounds like a perfect place to do this job. Otherwise, maybe you can distinguish one replica from others? IMHO, this may be a better design as this mechanism does not rely on the features of your migration tools or databases---this is good because if you have some other shared resource you would like to set up, you can use the same method without relying on a lock mechanism on that shared resource. However, I may not be making sense as I am just speculating without looking at your application. 😛 |
Locking table could be done using Postgres command LOCK (table-level lock); or row-level lock (using select for update): https://www.postgresql.org/docs/11/explicit-locking.html However, to do that, locking primitives must be invoked inside transaction being opened that does the migration (executed by EDIT2: locking table before each Migration (1.scala, 2.scala, etc), like i said, will not work too. Other replicas will wait for the unlock, but will execute the same Migration code and will fail. |
Hello,
Recently, we've introduced scala-forklift in our cloud applications, that are running at kubernetes.
Some applications have replicas and this means that migratedb-tool (using forklift) runs (when application is restarted), in parallel, among other replicas to work on same database.
We have some issues trying to run migratedb-tool in parallel - it seams that it lacks support for parallel runs on same database.
There is a way to lock database during migration ?
The text was updated successfully, but these errors were encountered: