I'm currently testing failure scenarios using 3 cockroachDB nodes.
Using this scenario:
- Inserting records in a loop
- Shutdown 2 nodes out of 3 (to simulate Quorum lost)
- Wait long enough so the Postgres JDBC driver throws a IO Exception
- Restart one node to bring back Quorum
- Retry previous failed statement
I then hit the following exception
Cause: org.postgresql.util.PSQLException: ERROR: duplicate key value (messageid)=('71100358-aeae-41ac-a397-b79788097f74') violates unique constraint "primary"
This means that the insert succeeded on first attempt (from which I got the IO Exception) when the Quorum became available again. Problem is that I'm not aware of it.
I cannot make the assumption that a "duplicate key value" exception will be cause by application logic issues. Is there any parameters I can tuned so the underlying statement rollbacks before the IO Exception ? Or maybe a better approach ?
Tests were conducted using
- CockroachDB v1.1.5 ( 3 nodes )
- MyBatis 3.4.0
- PostgreSQL driver 42.2.1
- Java 8