Skip to content

Commit 8c55eb0

Browse files
committed
[fix](binlog) Address committed TSO review feedback
### What problem does this PR solve? Issue Number: None Related PR: apache#67181, apache#67594 Problem Summary: The commit TSO fence check lacked request-level and Meta Service configuration gates, its error name was unclear, the fence key was unavailable through Meta Service HTTP KV tooling, and the persisted window time did not state its unit. Add both fence-check gates to every Cloud commit path, expose the fence key to HTTP encode/get/set, rename the stale TSO error, and clarify the FE tracker and durable-state names. ### Release note Cloud commit TSO fence checks can be controlled by the request and the mutable Meta Service configuration. Rejected stale commit TSOs now use TXN_COMMIT_TSO_EXPIRED. ### Check List (For Author) - Test: Unit Test - Targeted FE unit tests: 108 passed - Cloud MetaService TSO fence test: passed - Cloud HTTP encode/get/set tests: 11 passed - Full ./build.sh -j32: passed - Cloud clang-tidy on changed lines: passed - Behavior changed: Yes. Commit TSO fencing requires both request and Meta Service gates, and the stale TSO error was renamed. - Does this need documentation: No
1 parent 864546d commit 8c55eb0

17 files changed

Lines changed: 123 additions & 79 deletions

File tree

‎cloud/src/common/config.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ CONF_Bool(delete_bitmap_enable_retry_txn_conflict, "true");
354354
CONF_mInt64(max_txn_commit_byte, "7340032");
355355

356356
CONF_Bool(enable_cloud_txn_lazy_commit, "true");
357+
CONF_mBool(enable_check_commit_tso_fence, "true");
357358
CONF_Int32(txn_lazy_commit_rowsets_thresold, "1000");
358359
CONF_Int32(txn_lazy_commit_num_threads, "8");
359360
CONF_mBool(enable_cloud_parallel_txn_lazy_commit, "true");

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ static std::unordered_map<std::string_view,
250250
{"TxnInfoKey", {{"instance_id", "db_id", "txn_id"}, [](param_type& p) { return txn_info_key(KeyInfoSetter<TxnInfoKeyInfo>{p}.get()); }, parse<TxnInfoPB> , parse_json<TxnInfoPB>}},
251251
{"TxnIndexKey", {{"instance_id", "txn_id"}, [](param_type& p) { return txn_index_key(KeyInfoSetter<TxnIndexKeyInfo>{p}.get()); }, parse<TxnIndexPB> , parse_json<TxnIndexPB>}},
252252
{"TxnRunningKey", {{"instance_id", "db_id", "txn_id"}, [](param_type& p) { return txn_running_key(KeyInfoSetter<TxnRunningKeyInfo>{p}.get()); }, parse<TxnRunningPB> , parse_json<TxnRunningPB>}},
253+
{"TxnTsoFenceKey", {{"instance_id"}, [](param_type& p) { return txn_tso_fence_key(KeyInfoSetter<TxnTsoFenceKeyInfo>{p}.get()); }, parse<TxnTsoFencePB> , parse_json<TxnTsoFencePB>}},
253254
{"PartitionVersionKey", {{"instance_id", "db_id", "tbl_id", "partition_id"}, [](param_type& p) { return partition_version_key(KeyInfoSetter<PartitionVersionKeyInfo>{p}.get()); }, parse<VersionPB> , parse_json<VersionPB>}},
254255
{"TableVersionKey", {{"instance_id", "db_id", "tbl_id"}, [](param_type& p) { return table_version_key(KeyInfoSetter<TableVersionKeyInfo>{p}.get()); }, parse<VersionPB> , parse_json<VersionPB>}},
255256
{"MetaRowsetKey", {{"instance_id", "tablet_id", "version"}, [](param_type& p) { return meta_rowset_key(KeyInfoSetter<MetaRowsetKeyInfo>{p}.get()); }, parse<doris::RowsetMetaCloudPB> , parse_json<doris::RowsetMetaCloudPB>}},

‎cloud/src/meta-service/meta_service_helper.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ inline std::pair<MetaServiceCode, std::string> resolve_response_code_and_msg(Met
6161
"[TXN_ALREADY_COMMITED will be converted to code=UNDEFINED_ERR for old version "
6262
"clients]";
6363
return {MetaServiceCode::UNDEFINED_ERR, std::move(msg)};
64-
case MetaServiceCode::TXN_COMMIT_TSO_FENCED:
64+
case MetaServiceCode::TXN_COMMIT_TSO_EXPIRED:
6565
msg += std::string((msg.empty() ? "" : ", ")) +
66-
"[TXN_COMMIT_TSO_FENCED will be converted to code=UNDEFINED_ERR for old "
66+
"[TXN_COMMIT_TSO_EXPIRED will be converted to code=UNDEFINED_ERR for old "
6767
"version clients]";
6868
return {MetaServiceCode::UNDEFINED_ERR, std::move(msg)};
6969
default:

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ static void append_table_stream_commit_size_error(TxnErrorCode err, std::string&
127127
}
128128
}
129129

130+
// Reads the fence through the commit transaction so a concurrent fence update causes a conflict.
131+
// Allows commits without a TSO or a persisted fence, and rejects a commit at or below the fence.
130132
static bool check_txn_commit_tso_fence(Transaction* txn, const std::string& instance_id,
131133
int64_t commit_tso, CommitTxnResponse* response,
132134
MetaServiceCode& code, std::string& msg) {
@@ -153,7 +155,7 @@ static bool check_txn_commit_tso_fence(Transaction* txn, const std::string& inst
153155
}
154156
if (commit_tso <= fence.fence_tso()) {
155157
response->set_tso_fence(fence.fence_tso());
156-
code = MetaServiceCode::TXN_COMMIT_TSO_FENCED;
158+
code = MetaServiceCode::TXN_COMMIT_TSO_EXPIRED;
157159
msg = fmt::format("commit TSO {} is fenced by {}", commit_tso, fence.fence_tso());
158160
return false;
159161
}
@@ -1944,7 +1946,8 @@ void MetaServiceImpl::commit_txn_immediately(
19441946
return;
19451947
}
19461948

1947-
if (txn_info.status() != TxnStatusPB::TXN_STATUS_COMMITTED &&
1949+
if (request->enable_check_commit_tso_fence() && config::enable_check_commit_tso_fence &&
1950+
txn_info.status() != TxnStatusPB::TXN_STATUS_COMMITTED &&
19481951
!check_txn_commit_tso_fence(txn.get(), instance_id, commit_tso, response, code, msg)) {
19491952
return;
19501953
}
@@ -2781,7 +2784,8 @@ void MetaServiceImpl::commit_txn_eventually(
27812784
return;
27822785
}
27832786

2784-
if (txn_info.status() != TxnStatusPB::TXN_STATUS_COMMITTED &&
2787+
if (request->enable_check_commit_tso_fence() && config::enable_check_commit_tso_fence &&
2788+
txn_info.status() != TxnStatusPB::TXN_STATUS_COMMITTED &&
27852789
!check_txn_commit_tso_fence(txn.get(), instance_id, commit_tso, response, code, msg)) {
27862790
return;
27872791
}
@@ -3186,7 +3190,8 @@ void MetaServiceImpl::commit_txn_with_sub_txn(const CommitTxnRequest* request,
31863190
return;
31873191
}
31883192

3189-
if (txn_info.status() != TxnStatusPB::TXN_STATUS_COMMITTED &&
3193+
if (request->enable_check_commit_tso_fence() && config::enable_check_commit_tso_fence &&
3194+
txn_info.status() != TxnStatusPB::TXN_STATUS_COMMITTED &&
31903195
!check_txn_commit_tso_fence(txn.get(), instance_id, commit_tso, response, code, msg)) {
31913196
return;
31923197
}

‎cloud/test/http_encode_key_test.cpp‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,17 @@ txn_id=126419752960)",
190190
},
191191
R"({"table_ids":["10001"]})",
192192
},
193+
Input {
194+
"TxnTsoFenceKey",
195+
"instance_id=gavin-instance",
196+
{hex(txn_tso_fence_key({"gavin-instance"}))},
197+
[]() -> std::vector<std::string> {
198+
TxnTsoFencePB pb;
199+
pb.set_fence_tso(100);
200+
return {pb.SerializeAsString()};
201+
},
202+
R"({"fence_tso":"100"})",
203+
},
193204
Input {
194205
"PartitionVersionKey",
195206
"instance_id=gavin-instance&db_id=10086&tbl_id=10010&partition_id=10000",

‎cloud/test/meta_service_helper_test.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ TEST(MetaServiceHelperTest, ResponseStatusCoversEveryMetaServiceCode) {
413413

414414
expect_legacy_fallback_response_status(covered_codes, MetaServiceCode::TXN_ALREADY_COMMITED,
415415
LegacyFallbackCode::UNDEFINED_ERR);
416-
expect_legacy_fallback_response_status(covered_codes, MetaServiceCode::TXN_COMMIT_TSO_FENCED,
416+
expect_legacy_fallback_response_status(covered_codes, MetaServiceCode::TXN_COMMIT_TSO_EXPIRED,
417417
LegacyFallbackCode::UNDEFINED_ERR);
418418
EXPECT_EQ(covered_codes.size(),
419419
static_cast<size_t>(MetaServiceCode_descriptor()->value_count()))

‎cloud/test/meta_service_test.cpp‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2783,6 +2783,11 @@ TEST(MetaServiceTest, GetCurrentMaxTxnIdTest) {
27832783
}
27842784

27852785
TEST(MetaServiceTest, TsoFenceIsMonotonicAndRejectsStaleCommit) {
2786+
bool old_enable_check_commit_tso_fence = config::enable_check_commit_tso_fence;
2787+
DORIS_CLOUD_DEFER {
2788+
config::enable_check_commit_tso_fence = old_enable_check_commit_tso_fence;
2789+
};
2790+
config::enable_check_commit_tso_fence = true;
27862791
auto meta_service = get_meta_service();
27872792
brpc::Controller cntl;
27882793
AdvanceTsoFenceRequest fence_request;
@@ -2805,9 +2810,10 @@ TEST(MetaServiceTest, TsoFenceIsMonotonicAndRejectsStaleCommit) {
28052810
commit_request.set_db_id(666);
28062811
commit_request.set_txn_id(txn_id);
28072812
commit_request.set_commit_tso(100);
2813+
commit_request.set_enable_check_commit_tso_fence(true);
28082814
CommitTxnResponse commit_response;
28092815
meta_service->commit_txn(&cntl, &commit_request, &commit_response, nullptr);
2810-
ASSERT_EQ(commit_response.status().actual_code(), MetaServiceCode::TXN_COMMIT_TSO_FENCED);
2816+
ASSERT_EQ(commit_response.status().actual_code(), MetaServiceCode::TXN_COMMIT_TSO_EXPIRED);
28112817
ASSERT_EQ(commit_response.tso_fence(), 100);
28122818

28132819
commit_request.set_commit_tso(101);
@@ -2821,6 +2827,34 @@ TEST(MetaServiceTest, TsoFenceIsMonotonicAndRejectsStaleCommit) {
28212827
meta_service->commit_txn(&cntl, &commit_request, &commit_response, nullptr);
28222828
ASSERT_EQ(commit_response.status().code(), MetaServiceCode::OK);
28232829

2830+
// FE can disable the check for one request.
2831+
int64_t request_check_disabled_txn_id = -1;
2832+
begin_txn(meta_service.get(), 666, "tso_fence_request_check_disabled", 1234,
2833+
request_check_disabled_txn_id);
2834+
CommitTxnRequest request_check_disabled;
2835+
request_check_disabled.set_db_id(666);
2836+
request_check_disabled.set_txn_id(request_check_disabled_txn_id);
2837+
request_check_disabled.set_commit_tso(100);
2838+
CommitTxnResponse request_check_disabled_response;
2839+
meta_service->commit_txn(&cntl, &request_check_disabled, &request_check_disabled_response,
2840+
nullptr);
2841+
ASSERT_EQ(request_check_disabled_response.status().code(), MetaServiceCode::OK);
2842+
2843+
// MS can disable the check globally.
2844+
config::enable_check_commit_tso_fence = false;
2845+
int64_t server_check_disabled_txn_id = -1;
2846+
begin_txn(meta_service.get(), 666, "tso_fence_server_check_disabled", 1234,
2847+
server_check_disabled_txn_id);
2848+
CommitTxnRequest server_check_disabled;
2849+
server_check_disabled.set_db_id(666);
2850+
server_check_disabled.set_txn_id(server_check_disabled_txn_id);
2851+
server_check_disabled.set_commit_tso(100);
2852+
server_check_disabled.set_enable_check_commit_tso_fence(true);
2853+
CommitTxnResponse server_check_disabled_response;
2854+
meta_service->commit_txn(&cntl, &server_check_disabled, &server_check_disabled_response,
2855+
nullptr);
2856+
ASSERT_EQ(server_check_disabled_response.status().code(), MetaServiceCode::OK);
2857+
28242858
// Transactions without a commit TSO do not participate in binlog fencing.
28252859
int64_t non_tso_txn_id = -1;
28262860
begin_txn(meta_service.get(), 666, "tso_fence_non_tso_commit", 1234, non_tso_txn_id);

‎fe/fe-core/src/main/java/org/apache/doris/cloud/transaction/CloudGlobalTransactionMgr.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ private TransactionState commitTxn(CommitTxnRequest.Builder builder, List<Table>
862862
Set<Long> commitTsoTableIds = tableList.stream().map(Table::getId).collect(Collectors.toSet());
863863
long commitTso = TransactionUtil.getCommitTSO(transactionId, database, commitTsoTableIds);
864864
if (commitTso > 0) {
865-
builder.setCommitTso(commitTso);
865+
builder.setCommitTso(commitTso).setEnableCheckCommitTsoFence(true);
866866
}
867867
CommitTxnRequest commitTxnRequest = builder.build();
868868
try {
@@ -891,7 +891,7 @@ private TransactionState commitTxn(CommitTxnRequest.Builder builder, List<Table>
891891
if (LOG.isDebugEnabled()) {
892892
LOG.debug("retryTime:{}, commitTxnResponse:{}", retryTime, commitTxnResponse);
893893
}
894-
if (commitTxnResponse.getStatus().getCode() == MetaServiceCode.TXN_COMMIT_TSO_FENCED) {
894+
if (commitTxnResponse.getStatus().getCode() == MetaServiceCode.TXN_COMMIT_TSO_EXPIRED) {
895895
if (!commitTxnResponse.hasTsoFence() || commitTxnRequest.getCommitTso() <= 0) {
896896
throw new UserException("MetaService returned an invalid TSO fence response");
897897
}
@@ -937,7 +937,7 @@ private TransactionState commitTxn(CommitTxnRequest.Builder builder, List<Table>
937937
commitTxnRequest.getDbId(), transactionId, commitTxnRequest.getCommitTso());
938938
} else if (code == MetaServiceCode.OK || code == MetaServiceCode.TXN_ALREADY_VISIBLE
939939
|| code == MetaServiceCode.TXN_ALREADY_ABORTED) {
940-
Env.getCurrentEnv().getTSOService().transactionFinished(commitTxnRequest.getDbId(), transactionId);
940+
Env.getCurrentEnv().getTSOService().markTxnFinished(commitTxnRequest.getDbId(), transactionId);
941941
} else {
942942
Env.getCurrentEnv().getTSOService().abandonCommitTso(
943943
commitTxnRequest.getDbId(), transactionId, commitTxnRequest.getCommitTso());
@@ -2110,7 +2110,7 @@ private void afterAbortTxnResp(AbortTxnResponse abortTxnResponse, String txnIdOr
21102110
if (abortTxnResponse.hasTxnInfo()
21112111
&& (abortTxnResponse.getTxnInfo().getStatus() == TxnStatusPB.TXN_STATUS_ABORTED
21122112
|| abortTxnResponse.getTxnInfo().getStatus() == TxnStatusPB.TXN_STATUS_VISIBLE)) {
2113-
Env.getCurrentEnv().getTSOService().transactionFinished(
2113+
Env.getCurrentEnv().getTSOService().markTxnFinished(
21142114
abortTxnResponse.getTxnInfo().getDbId(), abortTxnResponse.getTxnInfo().getTxnId());
21152115
}
21162116
if (abortTxnResponse.getStatus().getCode() != MetaServiceCode.OK) {

‎fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/TSOAction.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public Object getTSO(HttpServletRequest request, HttpServletResponse response) {
8787

8888
// Prepare response data with detailed TSO information
8989
Map<String, Object> result = Maps.newHashMap();
90-
result.put("window_end_physical_time", statusSnapshot.getWindowEndPhysicalTime());
90+
result.put("window_end_physical_time", statusSnapshot.getWindowEndPhysicalTimeMs());
9191
result.put("current_tso", currentTso);
9292
result.put("current_tso_physical_time", TSOTimestamp.extractPhysicalTime(currentTso));
9393
result.put("current_tso_logical_counter", TSOTimestamp.extractLogicalCounter(currentTso));

‎fe/fe-core/src/main/java/org/apache/doris/tablefunction/MetadataGenerator.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2351,7 +2351,7 @@ private static TFetchSchemaTableDataResult tsoStatusMetadataResult(boolean inclu
23512351

23522352
long currentTso = statusSnapshot.getCurrentTso();
23532353
TRow row = new TRow();
2354-
row.addToColumnValue(new TCell().setLongVal(statusSnapshot.getWindowEndPhysicalTime()));
2354+
row.addToColumnValue(new TCell().setLongVal(statusSnapshot.getWindowEndPhysicalTimeMs()));
23552355
row.addToColumnValue(new TCell().setLongVal(currentTso));
23562356
row.addToColumnValue(new TCell().setLongVal(TSOTimestamp.extractPhysicalTime(currentTso)));
23572357
row.addToColumnValue(new TCell().setLongVal(TSOTimestamp.extractLogicalCounter(currentTso)));

0 commit comments

Comments
 (0)