@@ -38,6 +38,11 @@ DECLARE_uint32(mds_txn_max_retry_times);
3838
3939const uint32_t kTxnKeepAliveMs = 10 * 1000 ;
4040
41+ static bvar::PerSecondEx<bvar::Adder<uint32_t >, 60 > g_txn_write_conflict_per_second (" txn_write_conflict_sum" );
42+ static bvar::PerSecondEx<bvar::Adder<uint32_t >, 60 > g_txn_lock_conflict_per_second (" txn_lock_conflict_sum" );
43+ static bvar::PerSecondEx<bvar::Adder<uint32_t >, 60 > g_txn_memlock_conflict_per_second (" txn_memlock_conflict_sum" );
44+ static bvar::PerSecondEx<bvar::Adder<uint32_t >, 60 > g_txn_total_conflict_per_second (" txn_total_conflict_sum" );
45+
4146static void KvPairsToKeyValues (const std::vector<dingodb::sdk::KVPair>& kv_pairs, std::vector<KeyValue>& kvs) {
4247 kvs.reserve (kv_pairs.size ());
4348 for (const auto & kv_pair : kv_pairs) {
@@ -231,11 +236,20 @@ static inline Status TransformStatus(const dingodb::sdk::Status& status) {
231236 if (status.IsNotFound ()) {
232237 return Status (pb::error::ENOT_FOUND, status.ToString ());
233238
239+ } else if (status.IsTxnWriteConflict ()) {
240+ g_txn_total_conflict_per_second << 1 ;
241+ g_txn_write_conflict_per_second << 1 ;
242+ return Status (pb::error::ESTORE_MAYBE_RETRY, status.ToString ());
243+
234244 } else if (status.IsTxnLockConflict ()) {
235- return Status (pb::error::ESTORE_TXN_LOCK_CONFLICT, status.ToString ());
245+ g_txn_total_conflict_per_second << 1 ;
246+ g_txn_lock_conflict_per_second << 1 ;
247+ return Status (pb::error::ESTORE_MAYBE_RETRY, status.ToString ());
236248
237249 } else if (status.IsTxnMemLockConflict ()) {
238- return Status (pb::error::ESTORE_TXN_MEM_LOCK_CONFLICT, status.ToString ());
250+ g_txn_total_conflict_per_second << 1 ;
251+ g_txn_memlock_conflict_per_second << 1 ;
252+ return Status (pb::error::ESTORE_MAYBE_RETRY, status.ToString ());
239253
240254 } else {
241255 return Status (pb::error::EBACKEND_STORE, status.ToString ());
@@ -465,10 +479,37 @@ Status DingodbTxn::Scan(const Range& range, ScanHandlerType handler) {
465479 return status;
466480}
467481
482+ Status DingodbTxn::TransformStatus (const dingodb::sdk::Status& status) {
483+ if (status.IsNotFound ()) {
484+ return Status (pb::error::ENOT_FOUND, status.ToString ());
485+
486+ } else if (status.IsTxnWriteConflict ()) {
487+ g_txn_total_conflict_per_second << 1 ;
488+ g_txn_write_conflict_per_second << 1 ;
489+ txn_trace_.is_conflict = true ;
490+ return Status (pb::error::ESTORE_MAYBE_RETRY, status.ToString ());
491+
492+ } else if (status.IsTxnLockConflict ()) {
493+ g_txn_total_conflict_per_second << 1 ;
494+ g_txn_lock_conflict_per_second << 1 ;
495+ txn_trace_.is_conflict = true ;
496+ return Status (pb::error::ESTORE_MAYBE_RETRY, status.ToString ());
497+
498+ } else if (status.IsTxnMemLockConflict ()) {
499+ g_txn_total_conflict_per_second << 1 ;
500+ g_txn_memlock_conflict_per_second << 1 ;
501+ txn_trace_.is_conflict = true ;
502+ return Status (pb::error::ESTORE_MAYBE_RETRY, status.ToString ());
503+
504+ } else {
505+ return Status (pb::error::EBACKEND_STORE, status.ToString ());
506+ }
507+ }
508+
468509void DingodbTxn::Rollback () {
469510 auto status = txn_->Rollback ();
470511 if (!status.ok ()) {
471- DINGO_LOG (ERROR) << fmt::format (" rollback fail, error: {} " , status.ToString ());
512+ DINGO_LOG (ERROR) << fmt::format (" [storage] rollback fail, status({}). " , status.ToString ());
472513 }
473514}
474515
@@ -482,20 +523,12 @@ Status DingodbTxn::Commit() {
482523 auto status = txn_->PreCommit ();
483524 if (!status.ok ()) {
484525 Rollback ();
485- if (status.IsTxnWriteConflict ()) {
486- txn_trace_.is_conflict = true ;
487- return Status (pb::error::ESTORE_MAYBE_RETRY, status.ToString ());
488- }
489526 return TransformStatus (status);
490527 }
491528
492529 status = txn_->Commit ();
493530 if (!status.ok ()) {
494531 Rollback ();
495- if (status.IsTxnWriteConflict ()) {
496- txn_trace_.is_conflict = true ;
497- return Status (pb::error::ESTORE_MAYBE_RETRY, status.ToString ());
498- }
499532 return TransformStatus (status);
500533 }
501534
0 commit comments