-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Rewrite JdbcOrphanLockAwareIdempotentRepository::insert to not rely on exception #9286
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
- the initial exception will mark the transaction as dirty, blocking subsequent changes - not all databases support rollback of DDL (e.g MySQL, older Oracle DBs)
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 If necessary Apache Camel Committers may access logs and test results in the job summaries! |
Components tested:
|
|
@turing85 I can't understand
What is the stack trace for the next creation sql? |
Reproducer:
|
|
An alternative solution would be to:
This would look something like this ( |
|
Thanks @turing85 for sharing and I will check it. |
|
@zhfeng this got a lot more complicated. As soon as we set the route This is due to the fact that we try to commit a local transaction (through I haven't checked yet if this also affects other components, but I suspect it does. This seems to be a general issue. |
|
Hi @turing85 I can re-producer the issue with It only needs to change
I think this might be a limitation on |
|
Just get something from https://stackoverflow.com/questions/10399727/psqlexception-current-transaction-is-aborted-commands-ignored-until-end-of-tra It confirms that this is an expected behavior on |
|
OK, I tried the following configurations and it can work with "%dev":
quarkus:
datasource:
db-kind: postgresql
devservices:
properties:
autosave: always
flyway:
migrate-at-start: false |
|
@turing85 I also investigate
public Route(@SuppressWarnings("CdiInjectionPointsInspection") DataSource dataSource,
@SuppressWarnings("CdiInjectionPointsInspection") TransactionManager transactionManager) {
TransactionTemplate template = new TransactionTemplate(new JtaTransactionManager(transactionManager));
idempotentRepository =
constructRepository(dataSource, template);
}
private static JdbcMessageIdRepository constructRepository(DataSource dataSource, TransactionTemplate template) {
final JdbcMessageIdRepository repository =
new JdbcMessageIdRepository(dataSource, template, ROUTE_ID);
repository.setCreateTableIfNotExists(true);
return repository;
}I test it locally and it should work with |
|
I would say this is a great example for using Thanks a lot! |
@zhfeng I can confirm that the issue does not occur with h2. |
|
@turing85 is it OK to close this PR and maybe we can add a NOTE with |
|
@zhfeng I think it is not only postgres; db2 might also be affected. |
|
Please check https://jdbc.postgresql.org/documentation/use/ for |
It could be good but I wonder if |
This query is vendor-specific. But this part does not seem to be coupled to the global transaction manager, hence we might be in the clear here. The critical part is the |
|
If I uderstand correctly, you were wanting to seperate the transaction in |
|
Either this or rewrite |
|
@zhfeng I revised tie PR:
With those changes and your comment about the |
Components tested:
|
|
@turing85 Well done! - I will have a look today. |
Components tested:
|
|
Can we also have the catch duplicate exception still just in case it still happens in some of the other databases ? |
I belive that there will be no |
Ok perfect |
|
@turing85 One more question: If I understand correctly, this |
@zhfeng Hmm... we could use |
|
@zhfeng An I am not sure if this is a good user experience; those queries are complex... |
|
I think this PR is good as-is. And agree its better to support existing databases as-is. We had SQL for many many decades and UPSERT is not common practice and every database is a bit special. |
|
@davsclaus should I then squash and push again, or will you guys squash on merge? |
|
github has a squash and merge button that we use |
|
Thanks @turing85 for your contributions! |
|
@zhfeng you're welcome 🙂 I'll add the example when I have some spare time. |
Rewrote
JdbcOrphanLockAwareIdempotentRepository::insertto not rely on an exception. The exception caused problems with postgresql databases ifautosave=alwayswas not set.