Open rinaldodev opened 3 weeks ago
@marcosgopen
Thanks @rinaldodev for your reproducer. As expected the db2 throws the exception 'ERROR: duplicate key value violates unique constraint "users_name_key"'. So the second prepare fails and the transaction is rolled back. And I can see that the rollback throws "XAException.XAER_RMERR" because the prepared transaction does not exist. I need to check if this is the expected behaviour. cc @graben
@rinaldodev: Could you please look at what happens if you use Agroal DataSource instead of the Narayana unpooled one.
@rinaldodev: Could you please look at what happens if you use Agroal DataSource instead of the Narayana unpooled one.
My original tests were with Agroal, that's when I saw it happening. I removed it from this reproducer just to reduce the scope. My original test is here: https://github.com/apache/camel-spring-boot-examples/pull/141
I can augment this one with Agroal if you believe it's necessary.
Hi @rinaldodev, I think you bumped into JBTM-3843. There is an upstream PR (on hold) to fix this issue and a PR to fix/discuss how pgjdbc handles rollback invocations when there has been a constraint violation during the prepare phase. We'll keep you posted
Hi @rinaldodev, I think you bumped into JBTM-3843. There is an upstream PR (on hold) to fix this issue and a PR to fix/discuss how pgjdbc handles rollback invocations when there has been a constraint violation during the prepare phase. We'll keep you posted
Thanks a lot. I'll follow this issue.
@rinaldodev: Could you please look at what happens if you use Agroal DataSource instead of the Narayana unpooled one.
My original tests were with Agroal, that's when I saw it happening. I removed it from this reproducer just to reduce the scope. My original test is here: https://github.com/apache/camel-spring-boot-examples/pull/141
I can augment this one with Agroal if you believe it's necessary.
I think it's not necessary at the moment. Let's wait for the Narayana patch to be committed.
I have set up a reproducer that uses 2 PostgreSQL databases enlisted in a XA transaction. It is a modified version of narayana-spring-boot-sample-2pc. One of the databases has a UNIQUE column while the other doesn't. The reproducer is available here: https://github.com/rinaldodev/narayana-spring-boot/tree/2ds-2pc-test.
I see a behavior that I'm not sure if it's expected:
PREPARE
is called for db1 (non-unique), works fine (TwoPhaseOutcome.PREPARE_OK
)PREPARE
is called for db2 (unique), db returns constraint violation as expected (TwoPhaseOutcome.PREPARE_NOTOK
)ROLLBACK PREPARED
is called for db1, works fines (TwoPhaseOutcome.FINISH_OK
)ROLLBACK PREPARED
is called for db2, but fails because the prepared transaction doesn't exist (TwoPhaseOutcome.HEURISTIC_HAZARD
)Is step 4 expected to occur?
Steps to run the example:
podman run --rm --name db1 -e POSTGRES_PASSWORD=password -p 5432:5432 docker.io/library/postgres:latest -c max_prepared_transactions=10
podman run --rm --name db2 -e POSTGRES_PASSWORD=password -p 5433:5432 docker.io/library/postgres:latest -c max_prepared_transactions=10
cd narayana-spring-boot-samples/narayana-spring-boot-sample-2pc
mvn spring-boot:run -Ddisable.checks > out.log
Trace logs are enabled so I suggest output to a file.
Here are some relevant parts from the log: