-
Notifications
You must be signed in to change notification settings - Fork 47
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
Add support for AWS MCS (Amazon Keyspaces) #56
base: master_v4
Are you sure you want to change the base?
Conversation
And on my Windows machine there is something wrong with two tests:
they are trying to open jar:file:C:/Users/MVASIL~1/AppData/Local/Temp/Test14094071718996507780.jar
The code is: However it works with: EDIT |
@@ -365,13 +343,12 @@ private void executeStatement(String statement, DbMigration migration) { | |||
* @param wasSuccessful indicates if the migration was successful or not | |||
*/ | |||
private void logMigration(DbMigration migration, boolean wasSuccessful) { | |||
BoundStatement boundStatement = logMigrationStatement.bind(wasSuccessful, migration.getVersion(), | |||
executor.execute(format(INSERT_MIGRATION, getTableName()), wasSuccessful, migration.getVersion(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logMigration query should include keyspace name. When using AWS Keyspaces, having multiple tables with the same name (even if they're in different keyspaces), sometimes makes the tool insert log entries into improper tables (or executing the query ends with an exception about insufficient access rights, depending on IAM policy configuration). Consider the following scenario:
Keyspaces: A, B, C
Tables: A.schema_migration, B.schema_migration, C.schema_migration
Query in the BoundStatement: "insert into schema_migration (applied_successful, version, script_name, script, executed_at) values(?, ?, ?, ?, ?)"
The above statement executed in the context of keyspace A will sometimes end up modifying the contents of the table B.schema_migration or C.schema_migration.
I was able to avoid this problem by modifying the query and explicitly stating the keyspace name:
"insert into %s.%s (applied_successful, version, script_name, script, executed_at) values(?, ?, ?, ?, ?)"
Not sure what is the root cause - perhaps it's because I'm using datastax driver 3.7.2 and it's not properly taking into account the context in which the query is executed? (ignoring USE keyspace?). Then again, modifying the statement here would avoid any ambiguity (related to the driver etc.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Nihilum. I will include this in the refactoring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is included in my last commit.
First of all thanks for this pull request. I will have a look at it in the next couple of days. Has been some crazy times lately and I did not yet have the time. Sorry for that! |
Hi, sorry, it took me obviously longer than a couple of days. Home Office, Covid and Home Schooling did its thing :( Do you see any issue if instead of creating this Executor abstraction we would introduce something like an ExecutionHandler that would have beforeExecution() and afterExecution() methods? That is something I am anyway planning to do to keep the whole thing more open for modifications while not having to modify central code places for every new feature. As far as I can see the AWS scenario is behaving like the normal scenario except that some things need to be done after execution of the statement, right? One of the main problems I see here is that we now throw away the PreparedStatements after they have been executed. At least for the logMigration that will most likely end up in quite some warnings in the log file coming from the datastax driver. Cheers |
Hi, If you responded in one month, I am responding in one year :) Mihai |
This reverts commit 541e604.
Never mind. I've added: |
I've made a refactoring based on your comment. Can you take a look? |
@patka we are also planning to leverage this. would be great of you could take a look |
@vaibhavflip Thanks for letting me know that you will use this. Trust me, I want to ship it as much as you but I am currently in the situation that many people are in, meaning that although officially kindergarten and schools are open, in reality they are closed as either their personel is sick or there are reported casis of Covid and they are closed because of this. At the moment I am already happy when I manage my day job and take care of my kids. Therefore I am very sorry but I cannot give you an ETA for it as it is also a bigger feature but I definitely want to look at it. |
Hello, ant plan to release this ? |
Yes, I do have a plan to release it but it requires some work and I do not know when I will find the time for it. That is currently my main blocker for this. |
AWS MCS executes all DDLs asynchronously.
As discussed in
issue 51
after executing a ddl, the tables are not ready only after some time and the subsequent migration scripts will fail.
I've added support for an "Executor" of cql statements. The default one (SimpleExecutor) only forwards to the CqlSession.
There is support in org.cognitor.cassandra.migration.Database for autodetecting if it running against aws and choose AwsMcsExecutor instead of SimpleExecutor.
AwsMcsExecutor detects if there is a ddl to be executed, extract the name of the table or keyspace, then pause the execution until the table or keyspace is ready.
There is not yet support for DROP KEYSPACE and ALTER KEYSPACE. It is tested with my use case with few create table and insert statements.