gavinchou commented on code in PR #51129: URL: https://github.com/apache/doris/pull/51129#discussion_r2106435175
########## cloud/src/meta-service/meta_service.cpp: ########## @@ -990,6 +990,66 @@ static void fill_schema_from_dict(MetaServiceCode& code, std::string& msg, existed_rowset_meta->CopyFrom(metas.Get(0)); } +/** +* Check if the transaction status is as expected. +* If the transaction is not in the expected state, return false and set the error code and message. +* +* @param expect_status The expected transaction status. +* @param txn Pointer to the transaction object. +* @param instance_id The instance ID associated with the transaction. +* @param txn_id The transaction ID to check. +* @param code Reference to the error code to be set in case of failure. +* @param msg Reference to the error message to be set in case of failure. +* @return true if the transaction status matches the expected status, false otherwise. + */ +static bool check_transaction_status(TxnStatusPB expect_status, Transaction* txn, + const std::string& instance_id, int64_t txn_id, + MetaServiceCode& code, std::string& msg) { + // Get db id with txn id + std::string index_val; + const std::string index_key = txn_index_key({instance_id, txn_id}); + TxnErrorCode err = txn->get(index_key, &index_val); + if (err != TxnErrorCode::TXN_OK) { + code = cast_as<ErrCategory::READ>(err); + msg = fmt::format("failed to get db id, txn_id={} err={}", txn_id, err); + return false; + } + + TxnIndexPB index_pb; + if (!index_pb.ParseFromString(index_val)) { + code = MetaServiceCode::PROTOBUF_PARSE_ERR; + msg = fmt::format("failed to parse txn_index_pb, txn_id={}", txn_id); + return false; + } + + DCHECK(index_pb.has_tablet_index() == true); Review Comment: also return false and log for these checks -- 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: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org