如果是start_ts < commit_ts,错误码不应该是write conflict吗?
另外在看tikv源码时,看到了一部分关于committed错误的源码:
pub fn check_txn_status_missing_lock(
txn: &mut MvccTxn,
reader: &mut SnapshotReader<impl Snapshot>,
primary_key: Key,
mismatch_lock: Option<Lock>,
action: MissingLockAction,
resolving_pessimistic_lock: bool,
) -> Result<TxnStatus> {
MVCC_CHECK_TXN_STATUS_COUNTER_VEC.get_commit_info.inc();
match reader.get_txn_commit_record(&primary_key)? {
TxnCommitRecord::SingleRecord { commit_ts, write } => {
if write.write_type == WriteType::Rollback {
Ok(TxnStatus::RolledBack)
} else {
Ok(TxnStatus::committed(commit_ts))
}
}
...
fn get_txn_commit_record(&mut self, key: &Key, start_ts: TimeStamp) -> Result<TxnCommitRecord> {
// It's possible a txn with a small `start_ts` has a greater `commit_ts` than a
// txn with a greater `start_ts` in pessimistic transaction.
// I.e., txn_1.commit_ts > txn_2.commit_ts > txn_2.start_ts > txn_1.start_ts.
//
// Scan all the versions from `TimeStamp::max()` to `start_ts`.
let mut seek_ts = TimeStamp::max();
let mut gc_fence = TimeStamp::from(0);
while let Some((commit_ts, write)) = self.seek_write(key, seek_ts)? {
if write.start_ts == start_ts {
return Ok(TxnCommitRecord::SingleRecord { commit_ts, write });
}
可以看到在这里面,当write表的start_ts = 当前事务的start_ts,且不是rollback的才会反这个错误,不过其他地方可能也会反这个错误。