Skip to content

Commit 6b9fd4f

Browse files
rock-gitchuandew
authored andcommitted
[feat][mdsv2] Add txn conflict bvar PerSecondEx.
1 parent 08a030b commit 6b9fd4f

File tree

5 files changed

+55
-18
lines changed

5 files changed

+55
-18
lines changed

src/client/vfs_wrapper/global_log.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
#include "fmt/format.h"
18+
#include "glog/logging.h"
1819
#include "options/common/dynamic_vlog.h"
1920
#include "utils/configuration.h"
2021
#include "utils/gflags_helper.h"
@@ -39,7 +40,10 @@ static int InitLog(const char* argv0, const std::string& conf_path) {
3940
dummy.Load(&conf, "v", "client.loglevel", &FLAGS_v);
4041
dingofs::common::FLAGS_vlog_level = FLAGS_v;
4142

42-
FLAGS_logbufsecs = 4;
43+
FLAGS_logbufsecs = 10;
44+
FLAGS_minloglevel = google::GLOG_ERROR;
45+
FLAGS_logbuflevel = google::GLOG_INFO;
46+
4347
// initialize logging module
4448
google::InitGoogleLogging(argv0);
4549

src/mdsv2/common/logging.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ namespace dingofs {
2323
namespace mdsv2 {
2424

2525
void DingoLogger::InitLogger(const std::string& log_dir, const std::string& role, const LogLevel& level) {
26-
FLAGS_logbufsecs = 0;
27-
FLAGS_max_log_size = 80;
26+
FLAGS_logbufsecs = 10;
27+
FLAGS_max_log_size = 256;
2828
FLAGS_stop_logging_if_full_disk = true;
2929
FLAGS_minloglevel = google::GLOG_INFO;
3030
FLAGS_logbuflevel = google::GLOG_INFO;

src/mdsv2/filesystem/store_operation.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,8 +2454,7 @@ Status OperationProcessor::RunAlone(Operation* operation) {
24542454

24552455
status = operation->Run(txn);
24562456
if (!status.ok()) {
2457-
if (status.error_code() == pb::error::ESTORE_TXN_LOCK_CONFLICT ||
2458-
status.error_code() == pb::error::ESTORE_TXN_MEM_LOCK_CONFLICT) {
2457+
if (status.error_code() == pb::error::ESTORE_MAYBE_RETRY) {
24592458
DINGO_LOG(WARNING) << fmt::format(
24602459
"[operation.{}.{}][{}][{}us] alone run {} lock conflict, retry({}) status({}).", fs_id, ino, txn_id,
24612460
once_duration.ElapsedUs(), operation->OpName(), retry, status.error_str());
@@ -2657,8 +2656,7 @@ void OperationProcessor::ExecuteBatchOperation(BatchOperation& batch_operation)
26572656
std::vector<KeyValue> prefetch_kvs;
26582657
status = txn->BatchGet(keys, prefetch_kvs);
26592658
if (!status.ok()) {
2660-
if (status.error_code() == pb::error::ESTORE_TXN_LOCK_CONFLICT ||
2661-
status.error_code() == pb::error::ESTORE_TXN_MEM_LOCK_CONFLICT) {
2659+
if (status.error_code() == pb::error::ESTORE_MAYBE_RETRY) {
26622660
DINGO_LOG(WARNING) << fmt::format(
26632661
"[operation.{}.{}][{}][{}us] batch run {} lock conflict, retry({}) status({}).", fs_id, ino, txn_id,
26642662
once_duration.ElapsedUs(), op_names, retry, status.error_str());

src/mdsv2/storage/dingodb_storage.cc

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ DECLARE_uint32(mds_txn_max_retry_times);
3838

3939
const 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+
4146
static 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+
468509
void 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

src/mdsv2/storage/dingodb_storage.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ class DingodbTxn : public Txn {
8888
private:
8989
using TxnUPtr = std::unique_ptr<dingodb::sdk::Transaction>;
9090

91+
Status TransformStatus(const dingodb::sdk::Status& status);
92+
9193
void Rollback();
9294

9395
SdkTxnUPtr txn_;

0 commit comments

Comments
 (0)