-
-
Notifications
You must be signed in to change notification settings - Fork 263
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
Db2 forupdate fix #3446
Db2 forupdate fix #3446
Conversation
Did we use "forUpdate" in a wrong way? This was done with a try(Transaction txn = DB.beginTransaction()) {
List configs = DB.find(DirectoryScanConfig).where(...).forUpdate().findList(); // other thread will block here
// scan the directory in the config(s)
} Now we found out, that this might be the wrong way. Reasons:
Nevertheless, we need something to do a synchronization over DB. FYI: This locking is also used on DbMigration for some platforms |
|
||
start = System.currentTimeMillis() - start; | ||
|
||
assertThat(start).isGreaterThan(2800); |
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.
here we check, if the second thread blocks, while the first thread locks the data for at least 3000 ms.
@@ -57,6 +57,6 @@ public PlatformIdGenerator createSequenceIdGenerator(BackgroundExecutor be, Data | |||
@Override | |||
protected String withForUpdate(String sql, Query.LockWait lockWait, Query.LockType lockType) { | |||
// NOWAIT and SKIP LOCKED not supported with Db2 | |||
return sql + " for update"; | |||
return sql + " with rs use and keep update locks"; |
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.
rs = read stablility
Maybe relevant doc links:
https://www.ibm.com/docs/en/db2/11.5?topic=statement-update-clause
https://www.ibm.com/docs/en/db2/11.5?topic=statement-isolation-clause
https://www.ibm.com/docs/en/db2/11.5?topic=issues-isolation-levels
https://www.ibm.com/docs/en/db2/11.5?topic=statement-lock-request-clause
No, you used it in the way I would expect.
Yes, DB2 is taking its own approach/syntax here imo (which I think is confusing).
Not for DB2 though, DB2 is using "LogicalLocking" for DbMigration. So yes, I'm happy with this PR. |
Hello Rob,
In our application we assume that the forUpdate() query locks the selected rows (that read access from another thread is no longer possible). It works on MariaDb and SqlServer, but not on Db2.
The DB2 documentation states that the rows are locked but are not protected against write access: https://www.ibm.com/docs/en/db2/11.5?topic=statement-update-clause
We found out that if you add an orderBy("id") to the query, the locking also works under DB2. In our opinion it is just a workaround and not the solution. (And we do not understand why)
We found another way for DB2 forUpdate() to lock the rows: with
rs use and keep update locks
Can you please look at the PullRequest and give us feedback?
Best regards
Noemi