gavinchou commented on code in PR #54623:
URL: https://github.com/apache/doris/pull/54623#discussion_r2288871010
##########
cloud/src/recycler/checker.cpp:
##########
@@ -1758,4 +1766,141 @@ int InstanceChecker::do_mow_job_key_check() {
return 0;
}
+int InstanceChecker::check_meta_rowset_key(std::string& start_key, const
std::string& end_key) {
+ return scan_and_handle_kv(
+ start_key, end_key, [&](std::string_view key, std::string_view
value) -> int {
+ RowsetMetaCloudPB meta_rowset_pb;
+ if (!meta_rowset_pb.ParseFromArray(value.data(),
value.size())) {
+ LOG(WARNING) << "failed to parse RowsetMetaCloudPB";
+ return -1;
+ }
+ std::string tablet_index_key =
+ meta_tablet_idx_key({instance_id_,
meta_rowset_pb.tablet_id()});
+ if (key_exist(txn_kv_.get(), tablet_index_key) == 1) {
+ LOG(WARNING) << "rowset's tablet id not found in fdb"
+ << "tablet_index_key: " << tablet_index_key
+ << "rowset meta: " <<
meta_rowset_pb.ShortDebugString();
+ return 1;
+ }
+ return 0;
+ });
+ return 0;
+}
+
+int InstanceChecker::check_meta_tmp_rowset_key(std::string& start_key, const
std::string& end_key) {
+ return scan_and_handle_kv(
+ start_key, end_key, [&](std::string_view key, std::string_view
value) -> int {
+ TxnInfoPB txn_info_pb;
+ std::string_view k1 = key;
+ k1.remove_prefix(1);
+ std::vector<std::tuple<std::variant<int64_t, std::string>,
int, int>> out;
+ decode_key(&k1, &out);
+ // 0x01 "txn" ${instance_id} "txn_info" ${db_id} ${txn_id}
+ if (!txn_info_pb.ParseFromArray(value.data(), value.size())) {
+ LOG(WARNING) << "failed to parse TxnInfoPB";
+ return -1;
+ }
+ /// get tablet id
+ auto txn_id = std::get<int64_t>(std::get<0>(out[4]));
+ std::string txn_index = txn_index_key({instance_id_, txn_id});
+ std::string txn_index_val;
+ TxnIndexPB txn_index_pb;
+ std::unique_ptr<Transaction> txn;
+ TxnErrorCode err = txn_kv_->create_txn(&txn);
+ if (err != TxnErrorCode::TXN_OK) {
+ LOG(WARNING) << "failed to init txn";
+ return -1;
+ }
+ if (txn->get(txn_index, &txn_index_val) !=
TxnErrorCode::TXN_OK) {
+ LOG(WARNING) << "failed to get txn index key, key=" <<
txn_index;
+ return -1;
+ }
+ txn_index_pb.ParseFromString(txn_index_val);
+ auto tablet_id = txn_index_pb.tablet_index().tablet_id();
+ std::string meta_tmp_rowset_key =
+ meta_rowset_tmp_key({instance_id_, txn_id, tablet_id});
+ int is_key_exist = key_exist(txn_kv_.get(),
meta_tmp_rowset_key);
+ if (is_key_exist == 1) {
+ if (txn_info_pb.status() !=
TxnStatusPB::TXN_STATUS_VISIBLE) {
+ // clang-format off
+ LOG(INFO) << "meta tmp rowset key not exist but txn
status != TXN_STATUS_VISIBLE"
+ << "meta tmp rowset key=" <<
meta_tmp_rowset_key
+ << "txn_info=" <<
txn_info_pb.ShortDebugString();
+ // clang-format on
+ return 1;
+ }
+ } else if (is_key_exist == 0) {
+ if (txn_info_pb.status() !=
TxnStatusPB::TXN_STATUS_PREPARED) {
+ // clang-format off
+ LOG(INFO) << "meta tmp rowset key exist but txn status
!= TXN_STATUS_PREPARED"
+ << "meta tmp rowset key=" <<
meta_tmp_rowset_key
+ << "txn_info=" <<
txn_info_pb.ShortDebugString();
+ // clang-format on
+ return 1;
+ }
+ } else {
+ LOG(WARNING) << "failed to get key, key=" <<
meta_tmp_rowset_key;
+ return -1;
+ }
+ return 0;
+ });
+}
+
+int InstanceChecker::do_meta_rowset_key_check() {
+ int ret = 0;
+
+ std::string begin = meta_rowset_key({instance_id_, 0, 0});
+ std::string end = meta_rowset_key({instance_id_, INT64_MAX, 0});
+
+ ret = check_meta_rowset_key(begin, end);
+ if (ret == -1) {
+ LOG(WARNING) << "failed to check meta rowset key";
+ return -1;
+ }
+
+ begin = txn_info_key({instance_id_, 0, 0});
+ end = txn_info_key({instance_id_, INT64_MAX, 0});
+
+ ret = check_meta_tmp_rowset_key(begin, end);
+ if (ret == -1) {
+ LOG(WARNING) << "failed to check meta rowset key";
+ return -1;
+ }
+
+ return ret;
+}
+
+int InstanceChecker::scan_and_handle_kv(
+ std::string& start_key, const std::string& end_key,
+ std::function<int(std::string_view, std::string_view)> handle_kv) {
+ std::unique_ptr<Transaction> txn;
+ int ret = -1;
+ TxnErrorCode err = txn_kv_->create_txn(&txn);
+ if (err != TxnErrorCode::TXN_OK) {
+ LOG(WARNING) << "failed to init txn";
+ return -1;
+ }
+ std::unique_ptr<RangeGetIterator> it;
+ do {
Review Comment:
this loop may run more than 5 seconds, which is the max lifespan of a fdb
txn (object `txn` here)
we may need to recreate the `txn` in this loop as necessary or it may fail.
also add a syncpoint here to simulate a long-last loop more than 5 seconds
(add UT)
--
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]