Open sticnarf opened 3 years ago
cc @nrc @youjiali1995 @MyonKeminta @cfzjywxk
We could do some benchmarks for the read-write conflict scenarios with different data distributions to show the impact. Currently I agree it's not urgent and we need to make the basic async-commit stable before introducing new improvements.
Did you mean that the transaction's lock can be skipped if we did CheckSecondaryLocks on one if its keys that's not yet locked? Sounds correct, but I'm afraid that if you do the CheckTxnStatus - CheckSecondaryLocks procedure even when the lock's TTL is not expired, it may cause too many these requests when there are many transaction conflicts and maybe results in lower performance.
Did you mean that the transaction's lock can be skipped if we did CheckSecondaryLocks on one if its keys that's not yet locked? Sounds correct, but I'm afraid that if you do the CheckTxnStatus - CheckSecondaryLocks procedure even when the lock's TTL is not expired, it may cause too many these requests when there are many transaction conflicts and maybe results in lower performance.
Yes. And it's why I suggest this only happens after several times of backoffs.
Now the
min_commit_ts
of async commit transactions cannot be advanced like the legacy transactions. So if our read timestamp is larger than themin_commit_ts
of an async-commit lock, we can only wait until the lock expires and resolve the lock.Actually, we can use the
CheckSecondaryLocks
API to achieve something like advancingmin_commit_ts
.We can add
caller_start_ts
(like the one in theCheckTxnStatus
API) to the request. TiKV uses this timestamp to update itsmax_ts
.After the change, we don't need to wait until the TTL expires before checking secondary locks. If TTL is not expired, we set
caller_start_ts
. Otherwise, we keepcaller_start_ts
zero.If
caller_start_ts
is zero,CheckSecondaryLocks
writes rollbacks if the lock does not exist, which is the current behavior. Ifcaller_start_ts
exists,CheckSecondaryLocks
needn't write anything if the lock does not exist.After calling
CheckSecondaryLocks
withcaller_start_ts
, we can skip the locks of this transaction, just like we've advanced themin_commit_ts
of the transaction: If a following prewrite hits the same TiKV, itsmin_commit_ts
must be greater than thecaller_start_ts
due to the updatedmax_ts
; if it sends to a different TiKV, the leader must have changed, so themax_ts
should have been updated to a more recent timestamp from PD and thus thecommit_ts
should be also greater than thecaller_start_ts
.However, we still need to weigh the benefit and the cost. It is heavy to check all secondaries, so maybe we should not do this so eagerly (maybe after several backoffs?). And the benefit is not so big. Async commit transactions are typically small. It is unusual that prewriting them takes a long time. So personally I don't think it's a task of high priority.