This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch branch-4.2
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-4.2 by this push:
     new 6836533d94e branch-4.2: [fix](cloud) Fix infinite loop and OOM in FDB 
conflict logging #70417 (#70686)
6836533d94e is described below

commit 6836533d94e8863a4e730fc454508646fa47d784
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Sat Nov 21 04:53:22 2026 +0800

    branch-4.2: [fix](cloud) Fix infinite loop and OOM in FDB conflict logging 
#70417 (#70686)
    
    Cherry-picked from #70417
    
    Co-authored-by: Yixuan Wang <[email protected]>
---
 cloud/src/meta-store/txn_kv.cpp | 142 +++++++---------------------------------
 cloud/test/txn_kv_test.cpp      |  60 ++++++++++++++++-
 2 files changed, 80 insertions(+), 122 deletions(-)

diff --git a/cloud/src/meta-store/txn_kv.cpp b/cloud/src/meta-store/txn_kv.cpp
index 2f2b0458580..130e6dd0db6 100644
--- a/cloud/src/meta-store/txn_kv.cpp
+++ b/cloud/src/meta-store/txn_kv.cpp
@@ -1040,136 +1040,38 @@ TxnErrorCode 
Transaction::get_versionstamp(Versionstamp* versionstamp) {
     return TxnErrorCode::TXN_OK;
 }
 
+static TxnErrorCode get_conflict_range(Transaction* txn, std::string_view 
prefix,
+                                       std::vector<std::pair<std::string, 
std::string>>* values) {
+    std::string end(prefix);
+    end.push_back('\xff');
+    FullRangeGetOptions opts;
+    opts.batch_limit = 0;
+    TEST_SYNC_POINT_CALLBACK("transaction:get_conflict_range:batch_limit", 
&opts.batch_limit);
+
+    // The iterator uses the full last key to read the next page in the same 
transaction.
+    auto iter = txn->full_range_get(prefix, end, opts);
+    for (auto kv = iter->next(); kv.has_value(); kv = iter->next()) {
+        auto [key, value] = *kv;
+        // Drop the prefix only from the key copied to the result.
+        key.remove_prefix(prefix.size());
+        values->emplace_back(key, value);
+    }
+    return iter->error_code();
+}
+
 TxnErrorCode Transaction::get_conflicting_range(
         std::vector<std::pair<std::string, std::string>>* values) {
-    constexpr std::string_view start = 
"\xff\xff/transaction/conflicting_keys/";
-    constexpr std::string_view end = 
"\xff\xff/transaction/conflicting_keys/\xff";
-
-    int limit = 0;
-    int target_bytes = 0;
-    FDBStreamingMode mode = FDB_STREAMING_MODE_WANT_ALL;
-    int iteration = 0;
-    fdb_bool_t snapshot = 0;
-    fdb_bool_t reverse = 0;
-    FDBFuture* future = fdb_transaction_get_range(
-            txn_, FDB_KEYSEL_FIRST_GREATER_OR_EQUAL((uint8_t*)start.data(), 
start.size()),
-            FDB_KEYSEL_FIRST_GREATER_OR_EQUAL((uint8_t*)end.data(), 
end.size()), limit,
-            target_bytes, mode, iteration, snapshot, reverse);
-
-    DORIS_CLOUD_DEFER {
-        fdb_future_destroy(future);
-    };
-
-    RETURN_IF_ERROR(await_future(future));
-
-    FDBKeyValue const* out_kvs;
-    int out_kvs_count;
-    fdb_bool_t out_more = false;
-    do {
-        fdb_error_t err =
-                fdb_future_get_keyvalue_array(future, &out_kvs, 
&out_kvs_count, &out_more);
-        if (err) {
-            LOG(WARNING) << "get_conflicting_range get keyvalue array error: "
-                         << fdb_get_error(err);
-            return cast_as_txn_code(err);
-        }
-        for (int i = 0; i < out_kvs_count; i++) {
-            std::string_view key((char*)out_kvs[i].key, out_kvs[i].key_length);
-            std::string_view value((char*)out_kvs[i].value, 
out_kvs[i].value_length);
-            key.remove_prefix(start.size());
-            values->emplace_back(key, value);
-        }
-    } while (out_more);
-
-    return TxnErrorCode::TXN_OK;
+    return get_conflict_range(this, "\xff\xff/transaction/conflicting_keys/", 
values);
 }
 
 TxnErrorCode Transaction::get_read_conflict_range(
         std::vector<std::pair<std::string, std::string>>* values) {
-    constexpr std::string_view start = 
"\xff\xff/transaction/read_conflict_range/";
-    constexpr std::string_view end = 
"\xff\xff/transaction/read_conflict_range/\xff";
-
-    int limit = 0;
-    int target_bytes = 0;
-    FDBStreamingMode mode = FDB_STREAMING_MODE_WANT_ALL;
-    int iteration = 0;
-    fdb_bool_t snapshot = 0;
-    fdb_bool_t reverse = 0;
-    FDBFuture* future = fdb_transaction_get_range(
-            txn_, FDB_KEYSEL_FIRST_GREATER_OR_EQUAL((uint8_t*)start.data(), 
start.size()),
-            FDB_KEYSEL_FIRST_GREATER_OR_EQUAL((uint8_t*)end.data(), 
end.size()), limit,
-            target_bytes, mode, iteration, snapshot, reverse);
-
-    DORIS_CLOUD_DEFER {
-        fdb_future_destroy(future);
-    };
-
-    RETURN_IF_ERROR(await_future(future));
-
-    FDBKeyValue const* out_kvs;
-    int out_kvs_count;
-    fdb_bool_t out_more;
-    do {
-        fdb_error_t err =
-                fdb_future_get_keyvalue_array(future, &out_kvs, 
&out_kvs_count, &out_more);
-        if (err) {
-            LOG(WARNING) << "get_conflicting_range get keyvalue array error: "
-                         << fdb_get_error(err);
-            return cast_as_txn_code(err);
-        }
-        for (int i = 0; i < out_kvs_count; i++) {
-            std::string_view key((char*)out_kvs[i].key, out_kvs[i].key_length);
-            std::string_view value((char*)out_kvs[i].value, 
out_kvs[i].value_length);
-            key.remove_prefix(start.size());
-            values->emplace_back(key, value);
-        }
-    } while (out_more);
-
-    return TxnErrorCode::TXN_OK;
+    return get_conflict_range(this, 
"\xff\xff/transaction/read_conflict_range/", values);
 }
 
 TxnErrorCode Transaction::get_write_conflict_range(
         std::vector<std::pair<std::string, std::string>>* values) {
-    constexpr std::string_view start = 
"\xff\xff/transaction/write_conflict_range/";
-    constexpr std::string_view end = 
"\xff\xff/transaction/write_conflict_range/\xff";
-
-    int limit = 0;
-    int target_bytes = 0;
-    FDBStreamingMode mode = FDB_STREAMING_MODE_WANT_ALL;
-    int iteration = 0;
-    fdb_bool_t snapshot = 0;
-    fdb_bool_t reverse = 0;
-    FDBFuture* future = fdb_transaction_get_range(
-            txn_, FDB_KEYSEL_FIRST_GREATER_OR_EQUAL((uint8_t*)start.data(), 
start.size()),
-            FDB_KEYSEL_FIRST_GREATER_OR_EQUAL((uint8_t*)end.data(), 
end.size()), limit,
-            target_bytes, mode, iteration, snapshot, reverse);
-
-    DORIS_CLOUD_DEFER {
-        fdb_future_destroy(future);
-    };
-
-    RETURN_IF_ERROR(await_future(future));
-
-    FDBKeyValue const* out_kvs;
-    int out_kvs_count;
-    fdb_bool_t out_more;
-    do {
-        fdb_error_t err =
-                fdb_future_get_keyvalue_array(future, &out_kvs, 
&out_kvs_count, &out_more);
-        if (err) {
-            LOG(WARNING) << "get_conflicting_range get keyvalue array error: "
-                         << fdb_get_error(err);
-            return cast_as_txn_code(err);
-        }
-        for (int i = 0; i < out_kvs_count; i++) {
-            std::string_view key((char*)out_kvs[i].key, out_kvs[i].key_length);
-            std::string_view value((char*)out_kvs[i].value, 
out_kvs[i].value_length);
-            key.remove_prefix(start.size());
-            values->emplace_back(key, value);
-        }
-    } while (out_more);
-
-    return TxnErrorCode::TXN_OK;
+    return get_conflict_range(this, 
"\xff\xff/transaction/write_conflict_range/", values);
 }
 
 TxnErrorCode Transaction::report_conflicting_range() {
diff --git a/cloud/test/txn_kv_test.cpp b/cloud/test/txn_kv_test.cpp
index f2771a502cf..6f82d5b86ff 100644
--- a/cloud/test/txn_kv_test.cpp
+++ b/cloud/test/txn_kv_test.cpp
@@ -1547,10 +1547,16 @@ TEST(TxnKvTest, BatchScan) {
 }
 
 TEST(TxnKvTest, ReportConflictingRange) {
+    const bool old_enable_logging_conflict_keys = 
config::enable_logging_conflict_keys;
+    DORIS_CLOUD_DEFER {
+        config::enable_logging_conflict_keys = 
old_enable_logging_conflict_keys;
+    };
     config::enable_logging_conflict_keys = true;
 
     constexpr std::string_view key_prefix = 
"txn_kv_test__report_conflicting_range";
     std::string key = std::string(key_prefix) + std::to_string(time(nullptr));
+    key.push_back('\0');
+    key.append("suffix");
 
     {
         // 1. write a common key
@@ -1576,13 +1582,63 @@ TEST(TxnKvTest, ReportConflictingRange) {
     ASSERT_EQ(txn2->commit(), TxnErrorCode::TXN_CONFLICT);
 
     // 3. get the conflicting ranges.
+    auto* fdb_txn = static_cast<fdb::Transaction*>(txn2.get());
     std::vector<std::pair<std::string, std::string>> values;
-    
ASSERT_EQ(reinterpret_cast<fdb::Transaction*>(txn2.get())->get_conflicting_range(&values),
-              TxnErrorCode::TXN_OK);
+    ASSERT_EQ(fdb_txn->get_conflicting_range(&values), TxnErrorCode::TXN_OK);
     ASSERT_EQ(values.size(), 2);
     ASSERT_EQ(values[0].first, key);
     ASSERT_EQ(values[1].second, "0");
     ASSERT_TRUE(values[1].first.starts_with(key));
+
+    auto* sp = doris::SyncPoint::get_instance();
+    sp->enable_processing();
+    DORIS_CLOUD_DEFER {
+        sp->clear_all_call_backs();
+        sp->disable_processing();
+    };
+
+    int batch_limit = 0;
+    doris::SyncPoint::CallbackGuard limit_guard;
+    sp->set_call_back(
+            "transaction:get_conflict_range:batch_limit",
+            [&](auto&& args) { *doris::try_any_cast<int*>(args[0]) = 
batch_limit; }, &limit_guard);
+    int page_count = 0;
+    int fail_on_page = 0;
+    constexpr fdb_error_t txn_timed_out = 1031;
+    doris::SyncPoint::CallbackGuard page_guard;
+    sp->set_call_back(
+            "range_get_iterator:init:get_keyvalue_array_err",
+            [&](auto&& args) {
+                if (++page_count == fail_on_page) {
+                    *doris::try_any_cast<fdb_error_t*>(args[0]) = 
txn_timed_out;
+                }
+            },
+            &page_guard);
+
+    for (auto reader :
+         {&fdb::Transaction::get_conflicting_range, 
&fdb::Transaction::get_read_conflict_range,
+          &fdb::Transaction::get_write_conflict_range}) {
+        batch_limit = 0;
+        fail_on_page = 0;
+        values.clear();
+        ASSERT_EQ((fdb_txn->*reader)(&values), TxnErrorCode::TXN_OK);
+        ASSERT_EQ(values.size(), 2);
+        const auto expected = values;
+
+        // Put the two range ends on separate pages.
+        batch_limit = 1;
+        page_count = 0;
+        values.clear();
+        ASSERT_EQ((fdb_txn->*reader)(&values), TxnErrorCode::TXN_OK);
+        EXPECT_EQ(values, expected);
+        EXPECT_GT(page_count, 1);
+
+        page_count = 0;
+        fail_on_page = 2;
+        values.clear();
+        EXPECT_EQ((fdb_txn->*reader)(&values), TxnErrorCode::TXN_TIMEOUT);
+        EXPECT_EQ(values.size(), 1);
+    }
 }
 
 TEST(TxnKvTest, WatchKey) {


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

Reply via email to