Uh oh!
There was an error while loading. Please reload this page.
Catch UniqueConstraintViolationException inside insertIfNotExist - #12371
Conversation
This is the most common case for the usage of this method. See also #12369 and the linked tickets. Signed-off-by: Morris Jobke <hey@morrisjobke.de>
MorrisJobke
commented
Nov 9, 2018
@obel1x This is basically the more general approach. |
nickvergessen
commented
Nov 9, 2018
Well this basically "breaks" the case when you have a unique key which is not the pattern you are trying to match, but that does not sound like a valid usecase to me, so I'm fine with this. Let's hope it finally kills these reports. |
MorrisJobke
commented
Nov 9, 2018
That's also what I thought, I will check if any existing app does that, but I don't expect it. |
kesselb
commented
Nov 9, 2018
😕 If this is not a valid usecase and unique key are working for all supported dbms why do you still use this "fake" atomic insert approach here? Is the above not working? Do i miss something? (I have to admit, I feel a little stupid right now 🤣) |
MorrisJobke
commented
Nov 9, 2018
I guess it's fine then. The only problem with this is that the unique index needs to be in place. WIth the other logic it's also detected if the unique index is not in place. So we maybe want to go for the "first select and if no result insert with a wrapping of the insert". |
nickvergessen
commented
Nov 9, 2018
@danielkesselberg well you can use insertIfNotExists without having a unique key on your table. |
MorrisJobke
commented
Nov 9, 2018
The only problem with this approach seems to be this deadlock somehow. But I have no idea how to reliably trigger this one in a test environment. |
MorrisJobke
commented
Nov 9, 2018
Also thinking about this a bit and the better approach to this would be to deprecate this method and do this just properly in the application logic: try {
$db->insert(...);
} catch(UniqueConstraintViolationException$e) {
// already in there
}Then the developer does not trust us to do this correct, but is properly aware of the situation and just does it in the right way. |
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
MorrisJobke
commented
Nov 9, 2018
I would still go for this PR here and backport it. Then also replace the existing occurrences. I added the deprecation message as well to this PR. |
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
MorrisJobke
commented
Nov 12, 2018
I fixed the unit test. This is now good to go into 15. I would do this for 15 only and do separate PRs, that replace the insertIntoIfNotExist with a proper handling in the application itself, which then also could be more easily ported to older versions. |
* fixes#9305 by not being prone to the race condition in insertIfNotExists * fixes#6899 by not using a query that can result in a deadlock * replaces the insertIfNotExists call with an insert which is wrapped into a try-catch block * followup to #12371 Signed-off-by: Morris Jobke <hey@morrisjobke.de>
…al config tables * followup to #12371 Signed-off-by: Morris Jobke <hey@morrisjobke.de>
* fixes#9305 by not being prone to the race condition in insertIfNotExists * fixes#6899 by not using a query that can result in a deadlock * replaces the insertIfNotExists call with an insert which is wrapped into a try-catch block * followup to #12371 Signed-off-by: Morris Jobke <hey@morrisjobke.de>
* fixes#9305 by not being prone to the race condition in insertIfNotExists * fixes#6899 by not using a query that can result in a deadlock * replaces the insertIfNotExists call with an insert which is wrapped into a try-catch block * followup to #12371 Signed-off-by: Morris Jobke <hey@morrisjobke.de>
…al config tables * followup to #12371 Signed-off-by: Morris Jobke <hey@morrisjobke.de>
This is the most common case for the usage of this method.
See also #12369 and the linked tickets.
oc_filecache#6608oc_filecache#12343