Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bobhan1 committed Jan 23, 2025
1 parent be81f7e commit 8e47f36
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cloud/src/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,10 @@ CONF_Bool(enable_check_instance_id, "true");

// Check if ip eq 127.0.0.1, ms/recycler exit
CONF_Bool(enable_loopback_address_for_ms, "false");

// injection random failure in txn->commit()
// this config is for test usage, be careful when changing it.
CONF_mDouble(txn_commit_fault_probability, "0.0");
CONF_Validator(txn_commit_fault_probability, [](double p) -> bool { return p >= 0.0 && p <= 1.0; });

} // namespace doris::cloud::config
12 changes: 12 additions & 0 deletions cloud/src/meta-service/txn_kv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <cstring>
#include <memory>
#include <optional>
#include <random>
#include <string>
#include <string_view>
#include <thread>
Expand Down Expand Up @@ -527,6 +528,17 @@ void Transaction::remove(std::string_view begin, std::string_view end) {
}

TxnErrorCode Transaction::commit() {
if (config::txn_commit_fault_probability > 0.0) [[unlikely]] {
std::mt19937 gen {std::random_device {}()};
std::bernoulli_distribution inject_fault {config::txn_commit_fault_probability};
if (inject_fault(gen)) {
std::bernoulli_distribution err_type {0.5};
TxnErrorCode err =
(err_type(gen) ? TxnErrorCode::TXN_CONFLICT : TxnErrorCode::TXN_TOO_OLD);
LOG_WARNING("injection {} err when commit()", err);
return err;
}
}
fdb_error_t err = 0;
TEST_SYNC_POINT_CALLBACK("transaction:commit:get_err", &err);
if (err == 0) [[likely]] {
Expand Down

0 comments on commit 8e47f36

Please sign in to comment.