How to Capture TiKV Error Txn(Error(Mvcc(Error(TxnLockNotFound

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 如何捕获TiKV报错 Txn(Error(Mvcc(Error(TxnLockNotFound

| username: Timber

To improve efficiency, please provide the following information. A clear problem description can help resolve the issue faster:

[Overview] Our application (implemented in Golang) encounters TxnLockNotFound when using the TiKV component to store key-value pairs due to business logic reasons. After investigating the cause of the issue, which might be due to slow writes, we decided to retry if this error occurs. However, we currently cannot find the corresponding error description under github.com/tikv/client-go/v2/error.

[Application Framework and Business Logic Adaptation]
Concurrent writes to a specific row in TiKV, retry if an error occurs, resulting in TxnLockNotFound error.
[Background]

[Phenomenon]

[Problem] Unable to obtain the error type of TxnLockNotFound from the application side.

[Business Impact] Unable to retry for this specific error.

[TiDB Version] TiKV v6.1.0

[Attachment] Error(Txn(Error(Mvcc(Error(TxnLockNotFound { start_ts: TimeStamp(440892935474774075), commit_ts: TimeStamp(440892936274313253), key: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0, 1, 135, 151, 111, 70, 149, 238, 214, 132, 2, 168, 28, 0, 0] })))))', ‘details’: )
Verified through the pd-ctl tool that the transaction’s commit time exceeded the lock’s TTL of 3 seconds.

| username: Billmay表妹 | Original post link

In TiKV, the TxnLockNotFound error indicates that during the execution of a transaction, it was found that the lock on a certain key had expired, but the lock on that key had already been deleted by another transaction, causing the transaction to be unable to continue. This situation is usually due to slow writes, which can be avoided by increasing TiKV’s write capacity.

When using TiKV’s Golang client client-go, you can use the IsErrNotFound function to determine if it is a TxnLockNotFound error. For example:

if client-go.IsErrNotFound(err) {
    // Handle TxnLockNotFound error
    // Perform retry operations, etc.
}

It should be noted that the TxnLockNotFound error may cause the transaction to fail, so when handling this error, retry operations and other measures should be taken to ensure the correctness of the transaction.

| username: Timber | Original post link

Thank you for the reply. I have another question: Does IsErrNotFound uniformly represent this type of NotFound-related error? Because if the key is not found, this error is also used.

| username: xfworld | Original post link

Golang’s error descriptions are not precise enough, right? If an exception is not caught, most of them are panic :rofl:

You have to analyze the code yourself…