This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new bc68a8da070 branch-2.1: remove visible rowset from memory during
deletion transaction (#50329)
bc68a8da070 is described below
commit bc68a8da0707b46c1b9e7a30894a2742593b619f
Author: hui lai <[email protected]>
AuthorDate: Thu Apr 24 09:41:37 2025 +0800
branch-2.1: remove visible rowset from memory during deletion transaction
(#50329)
---
be/src/olap/txn_manager.cpp | 5 +++--
be/test/olap/txn_manager_test.cpp | 40 +++++++++++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/be/src/olap/txn_manager.cpp b/be/src/olap/txn_manager.cpp
index 90ed82242f1..c6dc711d0d8 100644
--- a/be/src/olap/txn_manager.cpp
+++ b/be/src/olap/txn_manager.cpp
@@ -696,6 +696,7 @@ Status TxnManager::delete_txn(OlapMeta* meta, TPartitionId
partition_id,
if (it == txn_tablet_map.end()) {
return Status::Error<TRANSACTION_NOT_EXIST>("key not founded from
txn_tablet_map");
}
+ Status st = Status::OK();
auto load_itr = it->second.find(tablet_info);
if (load_itr != it->second.end()) {
// found load for txn,tablet
@@ -704,7 +705,7 @@ Status TxnManager::delete_txn(OlapMeta* meta, TPartitionId
partition_id,
auto& rowset = load_info->rowset;
if (rowset != nullptr && meta != nullptr) {
if (!rowset->is_pending()) {
- return Status::Error<TRANSACTION_ALREADY_COMMITTED>(
+ st = Status::Error<TRANSACTION_ALREADY_COMMITTED>(
"could not delete transaction from engine, just remove
it from memory not "
"delete from disk, because related rowset already
published. partition_id: "
"{}, transaction_id: {}, tablet: {}, rowset id: {},
version: {}, state: {}",
@@ -729,7 +730,7 @@ Status TxnManager::delete_txn(OlapMeta* meta, TPartitionId
partition_id,
g_tablet_txn_info_txn_partitions_count << -1;
_clear_txn_partition_map_unlocked(transaction_id, partition_id);
}
- return Status::OK();
+ return st;
}
void TxnManager::get_tablet_related_txns(TTabletId tablet_id, TabletUid
tablet_uid,
diff --git a/be/test/olap/txn_manager_test.cpp
b/be/test/olap/txn_manager_test.cpp
index 77f1a16eb5b..4741d7d7f95 100644
--- a/be/test/olap/txn_manager_test.cpp
+++ b/be/test/olap/txn_manager_test.cpp
@@ -400,4 +400,44 @@ TEST_F(TxnManagerTest,
DeleteCommittedTxnForIngestingBinlog) {
EXPECT_FALSE(k_engine->pending_local_rowsets().contains(_rowset_ingested->rowset_id()));
}
+TEST_F(TxnManagerTest, DeleteCommittedTxnCleanupOnError) {
+ // first commit a transaction
+ auto guard = k_engine->pending_local_rowsets().add(_rowset->rowset_id());
+ auto st = _txn_mgr->commit_txn(_meta, partition_id, transaction_id,
tablet_id, _tablet_uid,
+ load_id, _rowset, std::move(guard), false);
+ ASSERT_TRUE(st.ok()) << st;
+
+ // verify transaction exists before deletion
+ std::vector<TPartitionId> partition_ids;
+ _txn_mgr->get_partition_ids(transaction_id, &partition_ids);
+ ASSERT_EQ(1, partition_ids.size());
+ ASSERT_EQ(partition_id, partition_ids[0]);
+
+ // also verify using get_tablet_related_txns
+ int64_t found_partition_id;
+ std::set<int64_t> found_txn_ids;
+ _txn_mgr->get_tablet_related_txns(tablet_id, _tablet_uid,
&found_partition_id, &found_txn_ids);
+ ASSERT_EQ(1, found_txn_ids.size());
+ ASSERT_EQ(transaction_id, *found_txn_ids.begin());
+
+ // make rowset visible
+ Version version(0, 1);
+ _rowset->make_visible(version);
+
+ // now try to delete the transaction
+ // this should return TRANSACTION_ALREADY_COMMITTED but still clean up the
transaction state
+ st = _txn_mgr->delete_txn(_meta, partition_id, transaction_id, tablet_id,
_tablet_uid);
+ ASSERT_TRUE(st.is<ErrorCode::TRANSACTION_ALREADY_COMMITTED>()) << st;
+
+ // verify transaction is removed from txn map
+ partition_ids.clear();
+ _txn_mgr->get_partition_ids(transaction_id, &partition_ids);
+ ASSERT_TRUE(partition_ids.empty()) << "Transaction should be removed from
txn map";
+
+ // verify by checking if we can get tablet related txns
+ found_txn_ids.clear();
+ _txn_mgr->get_tablet_related_txns(tablet_id, _tablet_uid,
&found_partition_id, &found_txn_ids);
+ ASSERT_TRUE(found_txn_ids.empty()) << "Transaction should not be found in
tablet related txns";
+}
+
} // namespace doris
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]