Skip to content

Commit 9957987

Browse files
authored
[fix](cloud) Return existing rowset for concurrent commits (apache#67637)
Problem Summary: Different BEs may generate different rowsets for the same transaction and tablet. After rowset A is committed, the temporary rowset key points to A while the recycle rowset key for B still exists. The recycle key check ran before comparing rowset IDs, so commit_rowset incorrectly treated tmp(A) and recycle(B) as an invalid conflict. Compare rowset IDs first and only check the tmp and recycle key conflict when they belong to the same rowset. For different rowsets, return ALREADY_EXISTED with rowset A.
1 parent 396ad79 commit 9957987

2 files changed

Lines changed: 65 additions & 20 deletions

File tree

‎cloud/src/meta-service/meta_service.cpp‎

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2758,33 +2758,33 @@ void MetaServiceImpl::commit_rowset(::google::protobuf::RpcController* controlle
27582758
std::string existed_commit_val;
27592759
err = txn->get(tmp_rs_key, &existed_commit_val);
27602760
if (err == TxnErrorCode::TXN_OK) {
2761-
if (config::enable_recycle_delete_rowset_key_check) {
2762-
bool recycle_rs_key_exists = false;
2763-
if (!check_recycle_rowset_key(txn.get(), recycle_rs_key, rowset_meta,
2764-
&recycle_rs_key_exists, code, msg)) {
2765-
return;
2766-
}
2767-
if (recycle_rs_key_exists) {
2768-
code = MetaServiceCode::INVALID_ARGUMENT;
2769-
msg = fmt::format(
2770-
"tmp rowset key and recycle rowset key are mutually exclusive, "
2771-
"tmp_rs_key={}, recycle_rs_key={}",
2772-
hex(tmp_rs_key), hex(recycle_rs_key));
2773-
LOG(INFO) << "skip commit rowset because tmp rowset key and recycle rowset key are "
2774-
"mutually exclusive, txn_id="
2775-
<< rowset_meta.txn_id() << ", tablet_id=" << tablet_id
2776-
<< ", rowset_id=" << rowset_id << ", tmp_rs_key=" << hex(tmp_rs_key)
2777-
<< ", recycle_rs_key=" << hex(recycle_rs_key) << ", msg=" << msg;
2778-
return;
2779-
}
2780-
}
27812761
auto existed_rowset_meta = response->mutable_existed_rowset_meta();
27822762
if (!existed_rowset_meta->ParseFromString(existed_commit_val)) {
27832763
code = MetaServiceCode::PROTOBUF_PARSE_ERR;
27842764
msg = fmt::format("malformed rowset meta value. key={}", hex(tmp_rs_key));
27852765
return;
27862766
}
27872767
if (existed_rowset_meta->rowset_id_v2() == rowset_meta.rowset_id_v2()) {
2768+
if (config::enable_recycle_delete_rowset_key_check) {
2769+
bool recycle_rs_key_exists = false;
2770+
if (!check_recycle_rowset_key(txn.get(), recycle_rs_key, rowset_meta,
2771+
&recycle_rs_key_exists, code, msg)) {
2772+
return;
2773+
}
2774+
if (recycle_rs_key_exists) {
2775+
code = MetaServiceCode::INVALID_ARGUMENT;
2776+
msg = fmt::format(
2777+
"tmp rowset key and recycle rowset key are mutually exclusive, "
2778+
"tmp_rs_key={}, recycle_rs_key={}",
2779+
hex(tmp_rs_key), hex(recycle_rs_key));
2780+
LOG(INFO) << "skip commit rowset because tmp rowset key and recycle rowset key "
2781+
"are mutually exclusive, txn_id="
2782+
<< rowset_meta.txn_id() << ", tablet_id=" << tablet_id
2783+
<< ", rowset_id=" << rowset_id << ", tmp_rs_key=" << hex(tmp_rs_key)
2784+
<< ", recycle_rs_key=" << hex(recycle_rs_key) << ", msg=" << msg;
2785+
return;
2786+
}
2787+
}
27882788
// Same request, return OK
27892789
response->set_allocated_existed_rowset_meta(nullptr);
27902790
return;

‎cloud/test/meta_service_test.cpp‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11268,6 +11268,13 @@ TEST(MetaServiceTest, CommitRowsetCheckTmpAndRecycleKeyExclusion) {
1126811268
ASSERT_EQ(txn->commit(), TxnErrorCode::TXN_OK);
1126911269
};
1127011270

11271+
auto remove_recycle_rowset = [&](const doris::RowsetMetaCloudPB& rowset) {
11272+
std::unique_ptr<Transaction> txn;
11273+
ASSERT_EQ(meta_service->txn_kv()->create_txn(&txn), TxnErrorCode::TXN_OK);
11274+
txn->remove(recycle_rowset_key({instance_id, rowset.tablet_id(), rowset.rowset_id_v2()}));
11275+
ASSERT_EQ(txn->commit(), TxnErrorCode::TXN_OK);
11276+
};
11277+
1127111278
{
1127211279
int64_t table_id = 1;
1127311280
int64_t partition_id = 1;
@@ -11316,6 +11323,44 @@ TEST(MetaServiceTest, CommitRowsetCheckTmpAndRecycleKeyExclusion) {
1131611323
ASSERT_TRUE(res.status().msg().find("recycle rowset key not found") != std::string::npos)
1131711324
<< res.status().msg();
1131811325
}
11326+
11327+
auto check_different_rowset_commit = [&](int64_t table_id, int64_t tablet_id, int64_t db_id,
11328+
bool remove_recycle_key) {
11329+
std::string label = "test_commit_rowset_different_rowset";
11330+
create_tablet(meta_service.get(), table_id, 1, table_id, tablet_id);
11331+
11332+
int64_t txn_id = 0;
11333+
ASSERT_NO_FATAL_FAILURE(begin_txn(meta_service.get(), db_id, label, table_id, txn_id));
11334+
CreateRowsetResponse res;
11335+
auto rowset_a = create_rowset(txn_id, tablet_id, table_id);
11336+
rowset_a.mutable_load_id()->set_hi(123);
11337+
rowset_a.mutable_load_id()->set_lo(456);
11338+
ASSERT_NO_FATAL_FAILURE(prepare_rowset(meta_service.get(), rowset_a, res));
11339+
ASSERT_EQ(res.status().code(), MetaServiceCode::OK) << label;
11340+
res.Clear();
11341+
11342+
auto rowset_b = create_rowset(txn_id, tablet_id, table_id);
11343+
rowset_b.mutable_load_id()->set_hi(789);
11344+
rowset_b.mutable_load_id()->set_lo(101112);
11345+
ASSERT_NO_FATAL_FAILURE(prepare_rowset(meta_service.get(), rowset_b, res));
11346+
ASSERT_EQ(res.status().code(), MetaServiceCode::OK) << label;
11347+
res.Clear();
11348+
11349+
ASSERT_NO_FATAL_FAILURE(commit_rowset(meta_service.get(), rowset_a, res));
11350+
ASSERT_EQ(res.status().code(), MetaServiceCode::OK) << label;
11351+
res.Clear();
11352+
11353+
if (remove_recycle_key) {
11354+
ASSERT_NO_FATAL_FAILURE(remove_recycle_rowset(rowset_b));
11355+
}
11356+
ASSERT_NO_FATAL_FAILURE(commit_rowset(meta_service.get(), rowset_b, res));
11357+
ASSERT_EQ(res.status().code(), MetaServiceCode::ALREADY_EXISTED) << res.status().msg();
11358+
ASSERT_TRUE(res.has_existed_rowset_meta());
11359+
ASSERT_EQ(res.existed_rowset_meta().rowset_id_v2(), rowset_a.rowset_id_v2());
11360+
};
11361+
11362+
check_different_rowset_commit(3, 3, 100203, false);
11363+
check_different_rowset_commit(4, 4, 100204, true);
1131911364
}
1132011365

1132111366
TEST(MetaServiceTest, AlterObjInfoTest) {

0 commit comments

Comments
 (0)