How to resolve ReadWithUncertainityInterval in cockroach database with springboot

Viewed 159

While performing write/read operations in cockroach database with springboot, we are getting below error intermittently. Any solutions here is appreciated. Thanks

Caused by:

org.postgresql.util.PSQLException: ERROR: restart transaction: TransactionRetryWithProtoRefreshError: ReadWithinUncertaintyIntervalError: read at time 1640760553.619962171,0 encountered previous write with future timestamp

1 Answers

The documentation states that this error is a sign of contention. It also suggests four ways of solving it:

  • Be prepared to retry on uncertainty (and other) errors, as described in client-side retry handling.
  • Use historical reads with SELECT ... AS OF SYSTEM TIME.
  • Design your schema and queries to reduce contention. For more information about how contention occurs and how to avoid it, see Understanding and avoiding transaction contention. In particular, if you are able to send all of the statements in your transaction in a single batch, CockroachDB can usually automatically retry the entire transaction for you.
  • If you trust your clocks, you can try lowering the --max-offset option to cockroach start, which provides an upper limit on how long a transaction can continue to restart due to uncertainty.

Did you already try these?

Related