gavinchou commented on code in PR #58459:
URL: https://github.com/apache/doris/pull/58459#discussion_r2633702430
##########
cloud/src/meta-service/meta_service.cpp:
##########
@@ -2527,6 +2527,74 @@ void
MetaServiceImpl::prepare_rowset(::google::protobuf::RpcController* controll
}
}
+// Check recycle_rowset_key to ensure idempotency for commit_rowset operation.
+// The precondition for commit_rowset is that prepare_rowset has been
successfully executed,
+// which creates the recycle_rowset_key. Therefore, we only need to check if
the
+// recycle_rowset_key exists to determine if this is a duplicate request:
+// - If key not found: commit_rowset has already been executed and remove the
key,
+// this is a duplicate request and should be rejected.
+// - If key exists but marked as recycled: the rowset data has been recycled
by recycler,
+// this request should be rejected to prevent data inconsistency.
+// - If key exists and not marked: this is a valid commit_rowset request,
proceed normally.
+// Note: We don't need to check txn/job status separately because
prepare_rowset has already
+// validated them, and the existence of recycle_rowset_key is sufficient to
guarantee idempotency.
+int check_idempotent_for_txn_or_job(Transaction* txn, const std::string&
recycle_rs_key,
+ doris::RowsetMetaCloudPB& rowset_meta,
+ const std::string& instance_id, int64_t
tablet_id,
+ const std::string& rowset_id, const
std::string& tablet_job_id,
+ bool is_versioned_read, ResourceManager*
resource_mgr,
+ MetaServiceCode& code, std::string& msg) {
+ if (!rowset_meta.has_delete_predicate() &&
config::enable_recycle_delete_rowset_key_check) {
+ std::string recycle_rs_val;
+ TxnErrorCode err = txn->get(recycle_rs_key, &recycle_rs_val);
+ if (err == TxnErrorCode::TXN_OK) {
+ RecycleRowsetPB recycle_rowset;
+ if (!recycle_rowset.ParseFromString(recycle_rs_val)) {
+ code = MetaServiceCode::PROTOBUF_PARSE_ERR;
+ msg = fmt::format("malformed recycle rowset value. key={}",
hex(recycle_rs_key));
+ return 1;
+ }
+ auto rs_meta = recycle_rowset.rowset_meta();
+ if (rs_meta.has_is_recycled() && rs_meta.is_recycled()) {
+ code = MetaServiceCode::INVALID_ARGUMENT;
+ msg = fmt::format("rowset has already been marked as recycled,
key={}, rs_meta={}",
+ hex(recycle_rs_key),
rs_meta.ShortDebugString());
+ return 1;
+ }
+ } else if (err == TxnErrorCode::TXN_KEY_NOT_FOUND) {
+ code = MetaServiceCode::INVALID_ARGUMENT;
+ msg = fmt::format("recycle rowset key not found, key={}",
hex(recycle_rs_key));
+ return 1;
+ } else {
+ code = cast_as<ErrCategory::READ>(err);
+ msg = fmt::format("failed to get recycle rowset, err={}", err);
Review Comment:
future todo: LOG recycle key
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]