-
Notifications
You must be signed in to change notification settings - Fork 66
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
BatchUpdateException when reordering elements of 1-m relationship as List<> (join table) - with testcase #464
Comments
Log of DataStore.Native: This was produced by reducing the child count to 3 and doing an element 'switch' at index 1 i.e. the first and second element should change places: The first 3 "paragaphs" are the creation of the 3 child elements.
Update version number of top level object
Delete the record from the join table at index = 1
Decrement the idx of the record following the one that was just deleted. It's current idx = 2 so it satisifes > 1 condition in where clause. It's idx will be set to 2 - 1 = 1.
Next is two identical updates which cause all elements (i.e. idx > -1) to be incremented... twice! Why the duplication?
I'm not sure if Datastore.Native performs logging before execution or after successful execution. The exception logs seem to indicate that the issue occurs on the issue of an INSERT and we don't see that in the logs so perhaps Native logging occurs only after successful execution - it would be interesting to see the details of the record it was attempting to insert. Ideally it would have idx = 0 but given that the insert gives a "can't add duplicate" error it might be inserting a record with idx = 2 or 3 as they are the indices of the existing records in the join table. |
I've found a possible cause of the issue: (Note: not the root cause of the issue but still likely to be incorrect code!) In internalShiftBulk there was maybe a "copy/paste" glitch when the code for building bulk shift statement (shiftBulkStmt) was based on the existing "one at a time" shift statement (shiftStmt). In internalShiftBulk (full source code below), a local variable shiftBulkStmt is established which holds the return of getShiftBulkStmt() however, when executedStatementUpdate is called the statement passed in is not the local variable shiftBulkStmt but the attribute shiftStmt (the "one at a time" statement").
Result of testing with change to shiftBulkStmtChanging shiftStmt to shiftBulkStmt did not fix the issue - it still raises an exception when attempting the insert. |
JoinListStore: reversion to non bulk shift in 'internalAdd' resolves issue for now - not optimized but at least it doesn't crash. It appears as though the original 'single shift' code was still present but commented out. I uncommented it and commented out the call to internalShiftBulk and the test case now succeeds:
|
… AbstractlistStore - did not resolve issue datanucleus#464 Reverted JoinListStore#internalAdd to non bulk shift insertion strategy and the exception of issue datanucleus#464 no longer occurs.
Summary
Switching the order of two elements in a List throws an exception. This code was previously working but now throws an exception since upgrading to DN-rdbms with the bulk shift optimization:
This issue can be reproduced with a single class via the attached testcase. A bug appears to be introduced to DN since the bulk shift optimization was implemented to improve the performance of element reordering in 1-m relationships. Code that has been working for many years started raising this exception after we upgraded to dn-rdbms version: 5.2.12.
Outline of the bug and testcase
This results in a BatchUpdateException: INSERT INTO failure with details: Duplicate entry '1-10' for key 'composite_childobjects.PRIMARY'
It works fine on H2 (and maybe other DBs?) but fails on MySQL for some reason - for this reason the test case must use MySQL 8+
The testcase assumes a MySQL DB at localhost with a database called dntest with username: dntest and password: dntest
Environment
OS: both Windows + Linux
dn-core version: 5.2.11
dn-rdbms version: 5.2.12
mysql versions tested so far: 8.0.28, 8.0.32
Testcase
reorderingElementsInJoinTable1mImpl.zip
The text was updated successfully, but these errors were encountered: