gavinchou commented on code in PR #52523:
URL: https://github.com/apache/doris/pull/52523#discussion_r2176357496
##########
cloud/src/recycler/recycler.cpp:
##########
@@ -811,6 +812,177 @@ int InstanceRecycler::recycle_deleted_instance() {
return ret;
}
+bool is_txn_finished(std::shared_ptr<TxnKv> txn_kv, const std::string&
instance_id,
+ int64_t txn_id) {
+ std::unique_ptr<Transaction> txn;
+ TxnErrorCode err = txn_kv->create_txn(&txn);
+ if (err != TxnErrorCode::TXN_OK) {
+ LOG(WARNING) << "failed to create txn, txn_id=" << txn_id << "
instance_id=" << instance_id;
+ return false;
+ }
+
+ std::string index_val;
+ const std::string index_key = txn_index_key({instance_id, txn_id});
+ err = txn->get(index_key, &index_val);
+ if (err != TxnErrorCode::TXN_OK) {
+ if (TxnErrorCode::TXN_KEY_NOT_FOUND == err) {
+ TEST_SYNC_POINT_CALLBACK("is_txn_finished::txn_has_been_recycled");
+ // txn has been recycled;
+ LOG(INFO) << "txn index key has been recycled, txn_id=" << txn_id
+ << " instance_id=" << instance_id;
+ return true;
+ }
+ LOG(WARNING) << "failed to get txn index key, txn_id=" << txn_id
+ << " instance_id=" << instance_id << " key=" <<
hex(index_key)
+ << " err=" << err;
+ return false;
+ }
+
+ TxnIndexPB index_pb;
+ if (!index_pb.ParseFromString(index_val)) {
+ LOG(WARNING) << "failed to parse txn_index_pb, txn_id=" << txn_id
+ << " instance_id=" << instance_id;
+ return false;
+ }
+
+ DCHECK(index_pb.has_tablet_index() == true);
+ if (!index_pb.tablet_index().has_db_id()) {
+ // In the previous version, the db_id was not set in the index_pb.
+ // If updating to the version which enable txn lazy commit, the db_id
will be set.
+ LOG(INFO) << "txn index has no db_id, txn_id=" << txn_id << "
instance_id=" << instance_id
+ << " index=" << index_pb.ShortDebugString();
+ return true;
+ }
+
+ int64_t db_id = index_pb.tablet_index().db_id();
+ DCHECK_GT(db_id, 0) << "db_id=" << db_id << " txn_id=" << txn_id
+ << " instance_id=" << instance_id;
+
+ std::string info_val;
+ const std::string info_key = txn_info_key({instance_id, db_id, txn_id});
+ err = txn->get(info_key, &info_val);
+ if (err != TxnErrorCode::TXN_OK) {
+ if (TxnErrorCode::TXN_KEY_NOT_FOUND == err) {
+ // txn info has been recycled;
+ LOG(INFO) << "txn info key has been recycled, db_id=" << db_id <<
" txn_id=" << txn_id
+ << " instance_id=" << instance_id;
+ return true;
+ }
+
+ DCHECK(err != TxnErrorCode::TXN_KEY_NOT_FOUND);
+ LOG(WARNING) << "failed to get txn info key, txn_id=" << txn_id
+ << " instance_id=" << instance_id << " key=" <<
hex(info_key)
+ << " err=" << err;
+ return false;
+ }
+
+ TxnInfoPB txn_info;
+ if (!txn_info.ParseFromString(info_val)) {
+ LOG(WARNING) << "failed to parse txn_info, txn_id=" << txn_id
+ << " instance_id=" << instance_id;
+ return false;
+ }
+
+ DCHECK(txn_info.txn_id() == txn_id) << "txn_id=" << txn_id << "
instance_id=" << instance_id
+ << " txn_info=" <<
txn_info.ShortDebugString();
+
+ if (TxnStatusPB::TXN_STATUS_ABORTED == txn_info.status() ||
+ TxnStatusPB::TXN_STATUS_VISIBLE == txn_info.status()) {
+ TEST_SYNC_POINT_CALLBACK("is_txn_finished::txn_has_been_aborted",
&txn_info);
+ return true;
+ }
+
+ TEST_SYNC_POINT_CALLBACK("is_txn_finished::txn_not_finished", &txn_info);
+ return false;
+}
+
+int64_t calculate_rowset_expired_time(const std::string& instance_id_, const
RecycleRowsetPB& rs,
+ int64_t* earlest_ts) {
Review Comment:
what is earlest_ts?
add comment (behavior, params) for functions extracted from lambda,
because the context has been lost
--
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]