-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix duplicate key value violation in setValues DB function #27576
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
Conversation
0e674ce to
4302287
Compare
|
@DeepDiver1975 is extremely hard to debug, OCA\Encryption\Tests\MigrationTest::testUpdateDBExistingNewConfig. How can I run this one test as single? I guess I need to setup encryption on local instance, sth else ? It fails because I removed preconditions from |
lib/private/DB/Connection.php
Outdated
| }, array_merge($keys, $values)) | ||
| ); | ||
| return $insertQb->execute(); | ||
| } catch (ConstraintViolationException $e) { |
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.
I am extremely unhappy with this line -> we have 3 options:
- writing specialized queries everywhere instead of universal "set"
- doing workaround as it is now
- writing this properly, but this will require additional query, and we would need a transaction here to ensure ACID principles are preserved in case of concurent accesses and be sure the ConstraintViolationException never happens
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.
And we already are doing transaction to oc_properties properly
| private function updateProperties($fileId, $properties) { |
4302287 to
ee5b47a
Compare
|
Current implementation will basicaly first perform select and insert if possible or knowing record does not exists (NOT EXISTS even wrapped by INSERT is very quick in that case), it will do update. Simple and easy. Problem here is that we need proper ACID handling maybe with transaction? Tried also with ON DUPLICATE KEY UPDATE, but this is not working in SQLLite, so we cannot do it in one query and we need transaction 🔢 |
lib/private/DB/Connection.php
Outdated
|
|
||
| /** | ||
| * Insert or update a row value | ||
| * Insert or update a row value. For safety, user of the method should lock table and begin/end transaction |
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.
don't lock - lock is bad - doesn't work with galery cluster and breaks on mysql master replicatin
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.
but transaction I is supported isnt it? Will erase it, but generaly I think better would be to have transaction in place there, what do you think @DeepDiver1975
|
@DeepDiver1975 Any decision regarding the comment there? Should I play with transaction there or leave as it is, since it solves the general issue? |
ee5b47a to
4993b96
Compare
|
I'm not convinced with the solution. We should keep using the query builder if possible. In addition, the |
|
Should I write another PR killing \OC\DB\Adapter @jvillafanez ? Can we lock table with QueryBuilder as in adapter and replicate other functions ? @DeepDiver1975 @PVince81 What was the reasoning behind the Adapter? |
|
Any update and input here? In the issue #23213 it seems really problem to solve, and this fixes it. |
4993b96 to
6ba2ae3
Compare
|
I guess we can go with this solution in order to fix the issue. |
|
@PVince81 @DeepDiver1975 anything I did not think here and could be important? This is quick change actualy. |
6ba2ae3 to
6bc82e2
Compare
|
@PVince81 @DeepDiver1975 @jvillafanez Just retested everything, and this fixes the issue for PostgreSQL #23213. It would be good to have it, to avoid the issues and save time of e.g. @pako81 which customer changed that query so that it does not log warning. |
|
So the change looks ok. @mrow4a did you find out from old commit logs / PRs if there are clues why this wasn't directly done with |
|
@PVince81 what do we do with this PR? |
|
|
I dont know, my quick guess is that someone though it will just be faster or that function did not exist yet there. I can research if you want, but it needs to be done like it is now, or we drop the support for sqlite and write it properly with ON DUPLICATE KEY UPDATE (which I guess is no go :>) |
|
@mrow4a I'm fine with your change. I just want to make sure there wasn't an explicit decision in the past to not use it. I hope you're right and it's simply that the method did not exist yet. |
|
@mrow4a how was the research ? |
|
Original implementation: #18531. Seems insertIfNotExists was considered but ignored for no real reason. We should use insertIfNotExists as this is polluting SQL error logs at the moment. |
|
@tomneedham sounds good, then let's get this in. Thanks |
|
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This fixes #23213 issue when one changes the oc_preferences in OC10.