gavinchou commented on code in PR #47336:
URL: https://github.com/apache/doris/pull/47336#discussion_r1952069013


##########
cloud/src/meta-service/txn_kv.cpp:
##########
@@ -527,6 +528,26 @@ void Transaction::remove(std::string_view begin, 
std::string_view end) {
 }
 
 TxnErrorCode Transaction::commit() {
+    bool enable_inject_random_fault {false};
+    TEST_INJECTION_POINT_CALLBACK("Transaction::commit.inject_random_fault",
+                                  &enable_inject_random_fault);
+    if (enable_inject_random_fault) [[unlikely]] {
+        std::mt19937 gen {std::random_device {}()};
+        double p {-1.0};
+        
TEST_INJECTION_POINT_CALLBACK("Transaction::commit.inject_random_fault.set_p", 
&p);
+        if (p < 0 || p > 1.0) {
+            p = 0.01; // default injection possibility is 1%
+        }
+        std::bernoulli_distribution inject_fault {p};
+        if (inject_fault(gen)) {
+            std::bernoulli_distribution err_type {0.5};
+            TxnErrorCode inject_err =
+                    (err_type(gen) ? TxnErrorCode::TXN_CONFLICT : 
TxnErrorCode::TXN_TOO_OLD);
+            LOG_WARNING("inject {} err when txn->commit()", inject_err);
+            return inject_err;
+        }
+    }
+

Review Comment:
   ```suggestion
       TEST_INJECTION_POINT_RETURN_WITH_VALUE()
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to