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

liaoxin01 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 1346aef64f9 [fix](cloud) Keep recycle records when a tablet scan stops 
early (#70867)
1346aef64f9 is described below

commit 1346aef64f95d9cf8fc7889b42dd030b30022641
Author: Yixuan Wang <[email protected]>
AuthorDate: Tue Nov 24 16:28:06 2026 +0800

    [fix](cloud) Keep recycle records when a tablet scan stops early (#70867)
    
    ### Background
    **Stopping the recycler causes `scan_and_recycle` to return 0
    immediately, regardless of whether the recycling process has completed**
    ```
    int InstanceRecycler::scan_and_recycle(
            std::string begin, std::string_view end,
            std::function<int(std::string_view k, std::string_view v)> 
recycle_func) {
        int ret = 0;
        while (it == nullptr /* may be not init */ || (it->more() && 
!stopped())) { ... }
        return ret;
    }
    ```
    
    ```
    int ret = scan_and_recycle(tablet_key_begin, tablet_key_end, 
std::move(recycle_func),
                                   std::move(loop_done));
    if (ret != 0) {
        LOG(WARNING) << "failed to scan_and_recycle, instance_id=" << 
instance_id_;
        return ret;
    }
    
    // directly remove tablet stats and tablet jobs of these dropped index or 
partition
    txn->remove(stats_key_begin, stats_key_end);
    txn->remove(job_key_begin, job_key_end);
    std::string schema_key_begin, schema_key_end;
    std::string schema_dict_key;
    std::string versioned_schema_key_begin, versioned_schema_key_end;
    if (partition_id <= 0) {
        // Delete schema kv of this index
        meta_schema_key({instance_id_, index_id, 0}, &schema_key_begin);
        meta_schema_key({instance_id_, index_id + 1, 0}, &schema_key_end);
        txn->remove(schema_key_begin, schema_key_end);
        meta_schema_pb_dictionary_key({instance_id_, index_id}, 
&schema_dict_key);
        txn->remove(schema_dict_key);
        versioned::meta_schema_key({instance_id_, index_id, 0}, 
&versioned_schema_key_begin);
        versioned::meta_schema_key({instance_id_, index_id + 1, 0}, 
&versioned_schema_key_end);
        txn->remove(versioned_schema_key_begin, versioned_schema_key_end);
    }
    ```
    
    
    The cloud recycler uses one record to track a dropped index or
    partition. It reads the tablets one page at a time and deletes the
    record after it finishes the last page.
    
    ### What problem does this PR solve?
    
    Issue Number: None
    PR Type: Bugfix
    
    Problem Summary:
    
    If the recycler lost its lease after page one of two, the scan returned
    success. The recycler deleted the parent record, leaving the next
    recycler with no record to find the tablets on page two.
---
 cloud/src/recycler/recycler.cpp |  7 +++-
 cloud/test/recycler_test.cpp    | 75 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 81 insertions(+), 1 deletion(-)

diff --git a/cloud/src/recycler/recycler.cpp b/cloud/src/recycler/recycler.cpp
index afd15ec9cab..01d71ac51e0 100644
--- a/cloud/src/recycler/recycler.cpp
+++ b/cloud/src/recycler/recycler.cpp
@@ -6841,7 +6841,12 @@ int InstanceRecycler::scan_and_recycle(
     };
 
     std::unique_ptr<RangeGetIterator> it;
-    while (it == nullptr /* may be not init */ || (it->more() && !stopped())) {
+    while (it == nullptr || it->more()) {
+        if (stopped()) {
+            err = "recycler stopped before scan completed";
+            ret = -1;
+            return ret;
+        }
         if (get_range_retried > 1000) {
             err = "txn_get exceeds max retry(1000), may not scan all keys";
             ret = -3;
diff --git a/cloud/test/recycler_test.cpp b/cloud/test/recycler_test.cpp
index d6b33df8f78..906e7b802a0 100644
--- a/cloud/test/recycler_test.cpp
+++ b/cloud/test/recycler_test.cpp
@@ -3351,6 +3351,81 @@ TEST(RecyclerTest, delete_bitmap_collect_shard_keys) {
     EXPECT_EQ(storage_type, InstanceRecycler::DeleteBitmapStorageType::IN_FDB);
 }
 
+static void check_interrupted_tablet_scan(bool recycle_index) {
+    auto retention_seconds = config::retention_seconds;
+    DORIS_CLOUD_DEFER {
+        config::retention_seconds = retention_seconds;
+    };
+    config::retention_seconds = 0;
+    auto txn_kv = std::make_shared<MemTxnKv>();
+    ASSERT_EQ(txn_kv->init(), 0);
+    constexpr int64_t table_id = 10000, index_id = 10001, partition_id = 10002;
+    constexpr int64_t first_tablet = 10100, second_tablet = 10101;
+    ASSERT_EQ(create_tablet(txn_kv.get(), table_id, index_id, partition_id, 
first_tablet), 0);
+    ASSERT_EQ(create_tablet(txn_kv.get(), table_id, index_id, partition_id, 
second_tablet), 0);
+    std::string parent_key;
+    if (recycle_index) {
+        ASSERT_EQ(create_recycle_index(txn_kv.get(), table_id, index_id), 0);
+        parent_key = recycle_index_key({instance_id, index_id});
+    } else {
+        ASSERT_EQ(create_recycle_partiton(txn_kv.get(), table_id, 
partition_id, {index_id}), 0);
+        parent_key = recycle_partition_key({instance_id, partition_id});
+    }
+    auto recycle = [recycle_index](InstanceRecycler& recycler) {
+        return recycle_index ? recycler.recycle_indexes() : 
recycler.recycle_partitions();
+    };
+    InstanceInfoPB instance;
+    instance.set_instance_id(instance_id);
+    auto committer = std::make_shared<TxnLazyCommitter>(txn_kv);
+    {
+        InstanceRecycler recycler(txn_kv, instance, thread_group, committer);
+        ASSERT_EQ(recycler.init(), 0);
+        auto* sp = SyncPoint::get_instance();
+        SyncPoint::CallbackGuard page_size, stop;
+        DORIS_CLOUD_DEFER {
+            sp->disable_processing();
+        };
+        sp->set_call_back(
+                "memkv::Transaction::get", [](auto&& args) { 
*try_any_cast<int*>(args[0]) = 1; },
+                &page_size);
+        sp->set_call_back(
+                "InstanceRecycler::recycle_tablets.before_commit", [&](auto&&) 
{ recycler.stop(); },
+                &stop);
+        sp->enable_processing();
+        EXPECT_EQ(recycle(recycler), -1);
+    }
+
+    auto first_meta =
+            meta_tablet_key({instance_id, table_id, index_id, partition_id, 
first_tablet});
+    auto second_meta =
+            meta_tablet_key({instance_id, table_id, index_id, partition_id, 
second_tablet});
+    auto stats = stats_tablet_key({instance_id, table_id, index_id, 
partition_id, second_tablet});
+    auto job = job_tablet_key({instance_id, table_id, index_id, partition_id, 
second_tablet});
+    std::unique_ptr<Transaction> txn;
+    std::string val;
+    ASSERT_EQ(txn_kv->create_txn(&txn), TxnErrorCode::TXN_OK);
+    EXPECT_EQ(txn->get(first_meta, &val), TxnErrorCode::TXN_KEY_NOT_FOUND);
+    for (const auto& key : {second_meta, stats, job, parent_key}) {
+        EXPECT_EQ(txn->get(key, &val), TxnErrorCode::TXN_OK) << hex(key);
+    }
+
+    InstanceRecycler successor(txn_kv, instance, thread_group, committer);
+    ASSERT_EQ(successor.init(), 0);
+    ASSERT_EQ(recycle(successor), 0);
+    ASSERT_EQ(txn_kv->create_txn(&txn), TxnErrorCode::TXN_OK);
+    for (const auto& key : {second_meta, stats, job, parent_key}) {
+        EXPECT_EQ(txn->get(key, &val), TxnErrorCode::TXN_KEY_NOT_FOUND) << 
hex(key);
+    }
+}
+
+TEST(RecyclerTest, interrupted_index_tablet_scan) {
+    check_interrupted_tablet_scan(true);
+}
+
+TEST(RecyclerTest, interrupted_partition_tablet_scan) {
+    check_interrupted_tablet_scan(false);
+}
+
 TEST(RecyclerTest, recycle_indexes) {
     config::retention_seconds = 0;
     auto txn_kv = std::make_shared<MemTxnKv>();


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

Reply via email to