如何使用spring boot解决蟑螂数据库中的ReadWithUncertainity Interval

How to resolve ReadWithUncertainityInterval in cockroach database with springboot

使用 springboot 在 cockroach 数据库中执行 write/read 操作时,我们间歇性地出现以下错误。这里的任何解决方案表示赞赏。谢谢

原因:

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

documentation 声明此错误是争用的迹象。它还提出了四种解决方法:

  • 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.

你试过这些了吗?