patka / cassandra-migration

Schema migration library for Cassandra
MIT License
152 stars 47 forks source link

[Question] Is the library safe for simultaneous usage when deploying on multiple nodes? #40

Closed igrishaev closed 5 years ago

igrishaev commented 5 years ago

Hi!

I'm interested in the following scenario. We deploy our app in k8s which spawns multiple versions of it. Every time the app starts, it runs its migrations. So I wonder if the library provides some way to prevent concurrent migrations?

Because in JDBC world, even though each migration is run inside a transaction, they either lock the migration table for reading or insert a temporary flag in the database meaning that somebody is running the migration process at the moment. As a result, only one node or Pod succeeds in running their migrations.

Does the library provide any kind of locking or a temporary flag maybe? Or did I miss something?

Ivan

patka commented 5 years ago

Hi Ivan,

currently there is no such option available and the library relies on the user to make sure it runs only on one node. This is actually a very good question and I think I should address it in the README somehow.

In order to solve this, I could imagine to have something inside the database that will be set/checked with a statement that has consistency level all configured but I have to do some research on that if it would really prevent two nodes from starting the migration.

So, as of now you can either mark one of your application nodes as being the master (there is a pull request that I am currently reviewing that will provide the option in Spring to enable or disable the migration process) or use some sort of consensus protocol to let the application nodes figure it out by themselves.

Best Patrick

igrishaev commented 5 years ago

Thank you, I've figured out with custom code. Closing.