@@ -3075,51 +3075,38 @@ butil::Status TxnEngineHelper::Commit(RawEnginePtr raw_engine, std::shared_ptr<E
30753075 // return butil::Status::OK();
30763076 // }
30773077
3078- // if lock is exists, check if lock_ts is equal to start_ts
3079- // if not equal, means this key is locked by other txn, return LockInfo
3080- if (lock_info.lock_ts () != 0 ) {
3081- // if lock is exists but start_ts is not equal to lock_ts, return locked
3082- if (lock_info.lock_ts () != start_ts) {
3083- DINGO_LOG (WARNING) << fmt::format (" [txn][region({})] Commit, start_Ts: {}, commit_ts: {}" , region->Id (),
3084- start_ts, commit_ts)
3085- << " , txn_not_found with lock_info.lock_ts not equal to start_ts, key: "
3086- << Helper::StringToHex (key) << " , lock_info: " << lock_info.ShortDebugString ();
3087-
3078+ if (lock_info.lock_ts () == start_ts) {
3079+ // lock_ts match start_ts, check if lock_type is Put/Delete/PutIfAbsent
3080+ // If this is a pessimistic lock in Lock phase, return LockInfo
3081+ // If this is not a Put/Delete/PutIfAbsent, return LockInfo
3082+ if (lock_info.lock_type () == pb::store::Op::Lock) {
3083+ DINGO_LOG (ERROR) << fmt::format (" [txn][region({})] Commit, start_Ts: {}, commit_ts: {}" , region->Id (), start_ts,
3084+ commit_ts)
3085+ << " , meet a pessimistic lock, there must BUG in executor, key: " << Helper::StringToHex (key)
3086+ << " , lock_info: " << lock_info.ShortDebugString ();
30883087 *txn_result->mutable_locked () = lock_info;
30893088 return butil::Status::OK ();
3090- } else {
3091- // lock_ts match start_ts, check if lock_type is Put/Delete/PutIfAbsent
3092- // If this is a pessimistic lock in Lock phase, return LockInfo
3093- // If this is not a Put/Delete/PutIfAbsent, return LockInfo
3094- if (lock_info.lock_type () == pb::store::Op::Lock) {
3095- DINGO_LOG (ERROR) << fmt::format (" [txn][region({})] Commit, start_Ts: {}, commit_ts: {}" , region->Id (),
3096- start_ts, commit_ts)
3097- << " , meet a pessimistic lock, there must BUG in executor, key: " << Helper::StringToHex (key)
3098- << " , lock_info: " << lock_info.ShortDebugString ();
3099- *txn_result->mutable_locked () = lock_info;
3100- return butil::Status::OK ();
3101- } else if (lock_info.lock_type () != pb::store::Op::Put && lock_info.lock_type () != pb::store::Op::Delete &&
3102- lock_info.lock_type () != pb::store::Op::PutIfAbsent) {
3103- DINGO_LOG (ERROR) << fmt::format (" [txn][region({})] Commit, start_Ts: {}, commit_ts: {}" , region->Id (),
3104- start_ts, commit_ts)
3105- << " , meet a invalid lock_type, there must BUG in executor, key: "
3106- << Helper::StringToHex (key) << " , lock_info: " << lock_info.ShortDebugString ();
3107- *txn_result->mutable_locked () = lock_info;
3108- return butil::Status::OK ();
3109- }
3089+ } else if (lock_info.lock_type () != pb::store::Op::Put && lock_info.lock_type () != pb::store::Op::Delete &&
3090+ lock_info.lock_type () != pb::store::Op::PutIfAbsent) {
3091+ DINGO_LOG (ERROR) << fmt::format (" [txn][region({})] Commit, start_Ts: {}, commit_ts: {}" , region->Id (), start_ts,
3092+ commit_ts)
3093+ << " , meet a invalid lock_type, there must BUG in executor, key: " << Helper::StringToHex (key)
3094+ << " , lock_info: " << lock_info.ShortDebugString ();
3095+ *txn_result->mutable_locked () = lock_info;
3096+ return butil::Status::OK ();
3097+ }
31103098
3111- // check if the commit_ts is bigger than min_commit_ts, if not, return CommitTsExpired, the executor should
3112- // get a new tso from coordinator, then commit again.
3113- if (lock_info.min_commit_ts () > 0 && commit_ts < lock_info.min_commit_ts ()) {
3114- // the min_commit_ts is already setup and commit_ts is less than min_commit_ts, return CommitTsExpired
3115- auto *commit_ts_expired = txn_result->mutable_commit_ts_expired ();
3116- commit_ts_expired->set_start_ts (start_ts);
3117- commit_ts_expired->set_attempted_commit_ts (commit_ts);
3118- commit_ts_expired->set_key (key);
3119- commit_ts_expired->set_min_commit_ts (lock_info.min_commit_ts ());
3099+ // check if the commit_ts is bigger than min_commit_ts, if not, return CommitTsExpired, the executor should
3100+ // get a new tso from coordinator, then commit again.
3101+ if (lock_info.min_commit_ts () > 0 && commit_ts < lock_info.min_commit_ts ()) {
3102+ // the min_commit_ts is already setup and commit_ts is less than min_commit_ts, return CommitTsExpired
3103+ auto *commit_ts_expired = txn_result->mutable_commit_ts_expired ();
3104+ commit_ts_expired->set_start_ts (start_ts);
3105+ commit_ts_expired->set_attempted_commit_ts (commit_ts);
3106+ commit_ts_expired->set_key (key);
3107+ commit_ts_expired->set_min_commit_ts (lock_info.min_commit_ts ());
31203108
3121- return butil::Status::OK ();
3122- }
3109+ return butil::Status::OK ();
31233110 }
31243111 } else {
31253112 // check if the key is already committed, if it is committed can skip it
@@ -3178,6 +3165,17 @@ butil::Status TxnEngineHelper::Commit(RawEnginePtr raw_engine, std::shared_ptr<E
31783165 return butil::Status::OK ();
31793166 }
31803167
3168+ // if lock is exists but start_ts is not equal to lock_ts, return locked
3169+ if (lock_info.lock_ts () > 0 ) {
3170+ DINGO_LOG (WARNING) << fmt::format (" [txn][region({})] Commit, start_Ts: {}, commit_ts: {}" , region->Id (),
3171+ start_ts, commit_ts)
3172+ << " , txn_not_found with lock_info.lock_ts not equal to start_ts, key: "
3173+ << Helper::StringToHex (key) << " , lock_info: " << lock_info.ShortDebugString ();
3174+
3175+ *txn_result->mutable_locked () = lock_info;
3176+ return butil::Status::OK ();
3177+ }
3178+
31813179 // no committed and no rollbacked, there may be BUG
31823180 auto *txn_not_found = txn_result->mutable_txn_not_found ();
31833181 txn_not_found->set_start_ts (start_ts);
@@ -3190,7 +3188,6 @@ butil::Status TxnEngineHelper::Commit(RawEnginePtr raw_engine, std::shared_ptr<E
31903188
31913189 return butil::Status::OK ();
31923190 }
3193-
31943191 // now txn is match, prepare to commit
31953192 lock_infos.push_back (lock_info);
31963193 }
0 commit comments