Skip to content

Commit 071d1ad

Browse files
committed
[feat](snapshot) recycle versioned rowsets should remove delete bitmap keys
1 parent bb302d0 commit 071d1ad

File tree

2 files changed

+98
-8
lines changed

2 files changed

+98
-8
lines changed

cloud/src/recycler/recycler.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3668,6 +3668,25 @@ int InstanceRecycler::recycle_rowset_meta_and_data(std::string_view recycle_rows
36683668
LOG_INFO("delete rowset data ref count key")
36693669
.tag("txn_id", rowset_meta.txn_id())
36703670
.tag("ref_count_key", hex(rowset_ref_count_key));
3671+
3672+
std::string dbm_start_key =
3673+
meta_delete_bitmap_key({reference_instance_id, tablet_id, rowset_id, 0, 0});
3674+
std::string dbm_end_key = meta_delete_bitmap_key(
3675+
{reference_instance_id, tablet_id, rowset_id,
3676+
std::numeric_limits<int64_t>::max(), std::numeric_limits<int64_t>::max()});
3677+
txn->remove(dbm_start_key, dbm_end_key);
3678+
LOG_INFO("remove delete bitmap kv")
3679+
.tag("begin", hex(dbm_start_key))
3680+
.tag("end", hex(dbm_end_key));
3681+
3682+
std::string versioned_dbm_start_key = versioned::meta_delete_bitmap_key(
3683+
{reference_instance_id, tablet_id, rowset_id});
3684+
std::string versioned_dbm_end_key = versioned_dbm_start_key;
3685+
encode_int64(INT64_MAX, &versioned_dbm_end_key);
3686+
txn->remove(versioned_dbm_start_key, versioned_dbm_end_key);
3687+
LOG_INFO("remove versioned delete bitmap kv")
3688+
.tag("begin", hex(versioned_dbm_start_key))
3689+
.tag("end", hex(versioned_dbm_end_key));
36713690
} else {
36723691
// Decrease the rowset ref count.
36733692
//

cloud/test/recycler_test.cpp

Lines changed: 79 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,20 @@ static doris::RowsetMetaCloudPB create_rowset(const std::string& resource_id, in
192192
return rowset;
193193
}
194194

195+
static int create_delete_bitmaps_v1(TxnKv* txn_kv, int64_t tablet_id, std::string rowset_id) {
196+
std::unique_ptr<Transaction> txn;
197+
if (txn_kv->create_txn(&txn) != TxnErrorCode::TXN_OK) {
198+
return -1;
199+
}
200+
201+
auto key = meta_delete_bitmap_key({instance_id, tablet_id, rowset_id, 0, 0});
202+
txn->put(key, "delete_bitmap_data");
203+
if (txn->commit() != TxnErrorCode::TXN_OK) {
204+
return -1;
205+
}
206+
return 0;
207+
}
208+
195209
static int create_delete_bitmaps_v2(TxnKv* txn_kv, StorageVaultAccessor* accessor,
196210
int64_t tablet_id, std::string rowset_id) {
197211
std::unique_ptr<Transaction> txn;
@@ -214,8 +228,8 @@ static int create_delete_bitmaps_v2(TxnKv* txn_kv, StorageVaultAccessor* accesso
214228

215229
static int create_recycle_rowset(TxnKv* txn_kv, StorageVaultAccessor* accessor,
216230
const doris::RowsetMetaCloudPB& rowset, RecycleRowsetPB::Type type,
217-
bool write_schema_kv,
218-
bool enable_create_delete_bitmaps_v2 = false) {
231+
bool write_schema_kv, bool enable_create_delete_bitmaps_v2 = false,
232+
bool enable_create_delete_bitmaps_v1 = false) {
219233
std::string key;
220234
std::string val;
221235

@@ -265,8 +279,17 @@ static int create_recycle_rowset(TxnKv* txn_kv, StorageVaultAccessor* accessor,
265279
}
266280
}
267281
if (enable_create_delete_bitmaps_v2) {
268-
return create_delete_bitmaps_v2(txn_kv, accessor, rowset.tablet_id(),
269-
rowset.rowset_id_v2());
282+
auto ret = create_delete_bitmaps_v2(txn_kv, accessor, rowset.tablet_id(),
283+
rowset.rowset_id_v2());
284+
if (ret != 0) {
285+
return ret;
286+
}
287+
}
288+
if (enable_create_delete_bitmaps_v1) {
289+
auto ret = create_delete_bitmaps_v1(txn_kv, rowset.tablet_id(), rowset.rowset_id_v2());
290+
if (ret != 0) {
291+
return ret;
292+
}
270293
}
271294
return 0;
272295
}
@@ -1186,8 +1209,32 @@ static void check_delete_bitmap_keys_size(TxnKv* txn_kv, int64_t tablet_id, int
11861209
dbm_start_key = meta_delete_bitmap_key({instance_id, tablet_id, "", 0, 0});
11871210
dbm_end_key = meta_delete_bitmap_key({instance_id, tablet_id + 1, "", 0, 0});
11881211
}
1189-
ASSERT_EQ(txn->get(dbm_start_key, dbm_end_key, &it), TxnErrorCode::TXN_OK);
1190-
EXPECT_EQ(it->size(), expected_size);
1212+
int size = 0;
1213+
do {
1214+
ASSERT_EQ(txn->get(dbm_start_key, dbm_end_key, &it), TxnErrorCode::TXN_OK);
1215+
while (it->has_next()) {
1216+
it->next();
1217+
size++;
1218+
}
1219+
dbm_start_key = it->next_begin_key();
1220+
} while (it->more());
1221+
EXPECT_EQ(size, expected_size);
1222+
}
1223+
1224+
static void check_delete_bitmap_file_size(std::shared_ptr<StorageVaultAccessor> accessor,
1225+
int64_t tablet_id, int expected_size) {
1226+
int size = 0;
1227+
std::unique_ptr<ListIterator> list_iter;
1228+
ASSERT_EQ(0, accessor->list_directory(tablet_path_prefix(tablet_id), &list_iter));
1229+
while (list_iter->has_next()) {
1230+
auto file_info = list_iter->next();
1231+
ASSERT_TRUE(file_info.has_value());
1232+
std::string filename = file_info.value().path;
1233+
if (filename.ends_with("_delete_bitmap.db")) {
1234+
size++;
1235+
}
1236+
}
1237+
EXPECT_EQ(size, expected_size);
11911238
}
11921239

11931240
TEST(RecyclerTest, recycle_empty) {
@@ -1271,6 +1318,7 @@ TEST(RecyclerTest, recycle_rowsets) {
12711318
i < 500);
12721319
}
12731320
check_delete_bitmap_keys_size(txn_kv.get(), tablet_id, 1000);
1321+
check_delete_bitmap_file_size(accessor, tablet_id, 1000);
12741322

12751323
ASSERT_EQ(recycler.recycle_rowsets(), 0);
12761324

@@ -1291,6 +1339,7 @@ TEST(RecyclerTest, recycle_rowsets) {
12911339
EXPECT_EQ(insert_no_inverted_index, 1);
12921340
// check all versioned delete bitmap kv have been deleted
12931341
check_delete_bitmap_keys_size(txn_kv.get(), tablet_id, 0);
1342+
check_delete_bitmap_file_size(accessor, tablet_id, 0);
12941343
}
12951344

12961345
TEST(RecyclerTest, recycle_rowsets_with_data_ref_count) {
@@ -1343,8 +1392,12 @@ TEST(RecyclerTest, recycle_rowsets_with_data_ref_count) {
13431392

13441393
// Only DROP or COMPACT will delete the rowset data
13451394
create_recycle_rowset(txn_kv.get(), accessor.get(), rowset,
1346-
i % 2 == 0 ? RecycleRowsetPB::COMPACT : RecycleRowsetPB::DROP, i & 1);
1395+
i % 2 == 0 ? RecycleRowsetPB::COMPACT : RecycleRowsetPB::DROP, i & 1,
1396+
true, true);
13471397
}
1398+
check_delete_bitmap_keys_size(txn_kv.get(), tablet_id, 5, 1);
1399+
check_delete_bitmap_keys_size(txn_kv.get(), tablet_id, 5);
1400+
check_delete_bitmap_file_size(accessor, tablet_id, 5);
13481401

13491402
ASSERT_EQ(recycler.recycle_rowsets(), 0);
13501403

@@ -1373,6 +1426,10 @@ TEST(RecyclerTest, recycle_rowsets_with_data_ref_count) {
13731426
++total_ref_count_keys;
13741427
}
13751428
ASSERT_EQ(total_ref_count_keys, 3);
1429+
1430+
check_delete_bitmap_keys_size(txn_kv.get(), tablet_id, 3, 1);
1431+
check_delete_bitmap_keys_size(txn_kv.get(), tablet_id, 3);
1432+
check_delete_bitmap_file_size(accessor, tablet_id, 3);
13761433
}
13771434

13781435
TEST(RecyclerTest, bench_recycle_rowsets) {
@@ -1435,7 +1492,8 @@ TEST(RecyclerTest, bench_recycle_rowsets) {
14351492
i % 10 < 2 ? RecycleRowsetPB::PREPARE : RecycleRowsetPB::COMPACT,
14361493
i & 1, i < 1000);
14371494
}
1438-
check_delete_bitmap_keys_size(txn_kv.get(), tablet_id, 100);
1495+
check_delete_bitmap_keys_size(txn_kv.get(), tablet_id, 1000);
1496+
check_delete_bitmap_file_size(accessor, tablet_id, 1000);
14391497

14401498
ASSERT_EQ(recycler.recycle_rowsets(), 0);
14411499
ASSERT_EQ(recycler.check_recycle_tasks(), false);
@@ -1453,6 +1511,7 @@ TEST(RecyclerTest, bench_recycle_rowsets) {
14531511
ASSERT_EQ(txn->get(begin_key, end_key, &it), TxnErrorCode::TXN_OK);
14541512
ASSERT_EQ(it->size(), 0);
14551513
check_delete_bitmap_keys_size(txn_kv.get(), tablet_id, 0);
1514+
check_delete_bitmap_file_size(accessor, tablet_id, 0);
14561515
}
14571516

14581517
TEST(RecyclerTest, recycle_tmp_rowsets) {
@@ -1520,6 +1579,7 @@ TEST(RecyclerTest, recycle_tmp_rowsets) {
15201579
ASSERT_EQ(txn->commit(), TxnErrorCode::TXN_OK);
15211580
for (int j = 0; j < 20; ++j) {
15221581
check_delete_bitmap_keys_size(txn_kv.get(), tablet_id_base + j, 50);
1582+
check_delete_bitmap_file_size(accessor, tablet_id_base + j, 50);
15231583
check_delete_bitmap_keys_size(txn_kv.get(), tablet_id_base + j, 100, 1);
15241584
}
15251585

@@ -1552,6 +1612,7 @@ TEST(RecyclerTest, recycle_tmp_rowsets) {
15521612
ASSERT_EQ(it->size(), 0);
15531613
for (int j = 0; j < 20; ++j) {
15541614
check_delete_bitmap_keys_size(txn_kv.get(), tablet_id_base + j, 0);
1615+
check_delete_bitmap_file_size(accessor, tablet_id_base + j, 0);
15551616
check_delete_bitmap_keys_size(txn_kv.get(), tablet_id_base + j, 0, 1);
15561617
}
15571618
}
@@ -1605,6 +1666,7 @@ TEST(RecyclerTest, recycle_tmp_rowsets_partial_update) {
16051666
}
16061667
}
16071668
check_delete_bitmap_keys_size(txn_kv.get(), tablet_id, 10);
1669+
check_delete_bitmap_file_size(accessor, tablet_id, 10);
16081670

16091671
ASSERT_EQ(recycler.recycle_tmp_rowsets(), 0);
16101672
// check rowset does not exist on obj store
@@ -1625,6 +1687,7 @@ TEST(RecyclerTest, recycle_tmp_rowsets_partial_update) {
16251687
ASSERT_EQ(txn->get(begin_key, end_key, &it), TxnErrorCode::TXN_OK);
16261688
ASSERT_EQ(it->size(), 0);
16271689
check_delete_bitmap_keys_size(txn_kv.get(), tablet_id, 0);
1690+
check_delete_bitmap_file_size(accessor, tablet_id, 0);
16281691
}
16291692

16301693
TEST(RecyclerTest, recycle_tablet) {
@@ -1671,6 +1734,7 @@ TEST(RecyclerTest, recycle_tablet) {
16711734
index_id, 1, 1, i < 200);
16721735
}
16731736
check_delete_bitmap_keys_size(txn_kv.get(), tablet_id, 400);
1737+
check_delete_bitmap_file_size(accessor, tablet_id, 400);
16741738

16751739
ASSERT_EQ(create_partition_version_kv(txn_kv.get(), table_id, partition_id), 0);
16761740

@@ -1718,6 +1782,7 @@ TEST(RecyclerTest, recycle_tablet) {
17181782
ASSERT_EQ(txn->get(idx_key, &empty_value), TxnErrorCode::TXN_KEY_NOT_FOUND);
17191783
ASSERT_EQ(txn->get(inverted_idx_key, &empty_value), TxnErrorCode::TXN_KEY_NOT_FOUND);
17201784
check_delete_bitmap_keys_size(txn_kv.get(), tablet_id, 0);
1785+
check_delete_bitmap_file_size(accessor, tablet_id, 0);
17211786
}
17221787

17231788
TEST(RecyclerTest, recycle_indexes) {
@@ -1781,6 +1846,7 @@ TEST(RecyclerTest, recycle_indexes) {
17811846
for (int i = 0; i < 100; ++i) {
17821847
int64_t tablet_id = tablet_id_base + i;
17831848
check_delete_bitmap_keys_size(txn_kv.get(), tablet_id, 10);
1849+
check_delete_bitmap_file_size(accessor, tablet_id, 10);
17841850
}
17851851
ASSERT_EQ(recycler.recycle_indexes(), 0);
17861852
ASSERT_EQ(recycler.recycle_tmp_rowsets(), 0); // Recycle tmp rowsets too, since
@@ -1856,6 +1922,7 @@ TEST(RecyclerTest, recycle_indexes) {
18561922
for (int i = 0; i < 100; ++i) {
18571923
int64_t tablet_id = tablet_id_base + i;
18581924
check_delete_bitmap_keys_size(txn_kv.get(), tablet_id, 0);
1925+
check_delete_bitmap_file_size(accessor, tablet_id, 0);
18591926
}
18601927
}
18611928

@@ -1924,6 +1991,7 @@ TEST(RecyclerTest, recycle_partitions) {
19241991
for (int i = 0; i < 20 * index_ids.size(); ++i) {
19251992
int64_t tablet_id = tablet_id_base2 + i;
19261993
check_delete_bitmap_keys_size(txn_kv.get(), tablet_id, 10);
1994+
check_delete_bitmap_file_size(accessor, tablet_id, 10);
19271995
}
19281996
ASSERT_EQ(recycler.recycle_partitions(), 0);
19291997

@@ -1986,6 +2054,7 @@ TEST(RecyclerTest, recycle_partitions) {
19862054
for (int i = 0; i < 20 * index_ids.size(); ++i) {
19872055
int64_t tablet_id = tablet_id_base2 + i;
19882056
check_delete_bitmap_keys_size(txn_kv.get(), tablet_id, 0);
2057+
check_delete_bitmap_file_size(accessor, tablet_id, 0);
19892058
}
19902059
}
19912060

@@ -3002,6 +3071,7 @@ TEST(RecyclerTest, recycle_deleted_instance) {
30023071
for (int i = 0; i < 100; ++i) {
30033072
int64_t tablet_id = tablet_id_base + i;
30043073
check_delete_bitmap_keys_size(txn_kv.get(), tablet_id, 10);
3074+
check_delete_bitmap_file_size(accessor, tablet_id, 10);
30053075
}
30063076

30073077
{
@@ -3094,6 +3164,7 @@ TEST(RecyclerTest, recycle_deleted_instance) {
30943164
for (int i = 0; i < 100; ++i) {
30953165
int64_t tablet_id = tablet_id_base + i;
30963166
check_delete_bitmap_keys_size(txn_kv.get(), tablet_id, 0);
3167+
check_delete_bitmap_file_size(accessor, tablet_id, 0);
30973168
}
30983169
}
30993170

0 commit comments

Comments
 (0)