From 646d53777f9fff6da7fb6ed85d12d1557f5d2bf0 Mon Sep 17 00:00:00 2001 From: edwinhzhang Date: Thu, 28 Nov 2024 17:03:40 +0800 Subject: [PATCH 1/3] [BugFix] With a high streamload frequency and too many tablets involved, TabletCommitInfos will take up too much memory. Signed-off-by: edwinhzhang --- .../com/starrocks/transaction/DatabaseTransactionMgr.java | 2 ++ .../java/com/starrocks/transaction/TransactionState.java | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/fe/fe-core/src/main/java/com/starrocks/transaction/DatabaseTransactionMgr.java b/fe/fe-core/src/main/java/com/starrocks/transaction/DatabaseTransactionMgr.java index 8ce2f13a60c8e..469ada5c824c8 100644 --- a/fe/fe-core/src/main/java/com/starrocks/transaction/DatabaseTransactionMgr.java +++ b/fe/fe-core/src/main/java/com/starrocks/transaction/DatabaseTransactionMgr.java @@ -1177,6 +1177,7 @@ public void finishTransaction(long transactionId, Set errorReplicaIds) thr transactionState.clearErrorMsg(); transactionState.setTransactionStatus(TransactionStatus.VISIBLE); unprotectUpsertTransactionState(transactionState, false); + transactionState.resetTabletCommitInfos(); txnOperated = true; // TODO(cmy): We found a very strange problem. When delete-related transactions are processed here, // subsequent `updateCatalogAfterVisible()` is called, but it does not seem to be executed here @@ -1885,6 +1886,7 @@ public void finishTransactionNew(TransactionState transactionState, Set pu transactionState.setNewFinish(); transactionState.setTransactionStatus(TransactionStatus.VISIBLE); unprotectUpsertTransactionState(transactionState, false); + transactionState.resetTabletCommitInfos(); transactionState.notifyVisible(); txnOperated = true; } finally { diff --git a/fe/fe-core/src/main/java/com/starrocks/transaction/TransactionState.java b/fe/fe-core/src/main/java/com/starrocks/transaction/TransactionState.java index 6f1490815755a..75e4d816d86b2 100644 --- a/fe/fe-core/src/main/java/com/starrocks/transaction/TransactionState.java +++ b/fe/fe-core/src/main/java/com/starrocks/transaction/TransactionState.java @@ -427,6 +427,12 @@ public void setTabletCommitInfos(List infos) { this.tabletCommitInfos.addAll(infos); } + public void resetTabletCommitInfos() { + // With a high streamload frequency and too many tablets involved, + // TabletCommitInfos will take up too much memory. + tabletCommitInfos = null; + } + public boolean tabletCommitInfosContainsReplica(long tabletId, long backendId, ReplicaState state) { TabletCommitInfo info = new TabletCommitInfo(tabletId, backendId); if (this.tabletCommitInfos == null) { From fac22302c287a6e5c592dedc2e802f5461ec1c41 Mon Sep 17 00:00:00 2001 From: edwinhzhang Date: Thu, 28 Nov 2024 21:50:04 +0800 Subject: [PATCH 2/3] fix bug Signed-off-by: edwinhzhang --- .../transaction/DatabaseTransactionMgr.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/fe/fe-core/src/main/java/com/starrocks/transaction/DatabaseTransactionMgr.java b/fe/fe-core/src/main/java/com/starrocks/transaction/DatabaseTransactionMgr.java index 469ada5c824c8..31b187d3fd597 100644 --- a/fe/fe-core/src/main/java/com/starrocks/transaction/DatabaseTransactionMgr.java +++ b/fe/fe-core/src/main/java/com/starrocks/transaction/DatabaseTransactionMgr.java @@ -1177,7 +1177,6 @@ public void finishTransaction(long transactionId, Set errorReplicaIds) thr transactionState.clearErrorMsg(); transactionState.setTransactionStatus(TransactionStatus.VISIBLE); unprotectUpsertTransactionState(transactionState, false); - transactionState.resetTabletCommitInfos(); txnOperated = true; // TODO(cmy): We found a very strange problem. When delete-related transactions are processed here, // subsequent `updateCatalogAfterVisible()` is called, but it does not seem to be executed here @@ -1208,6 +1207,13 @@ public void finishTransaction(long transactionId, Set errorReplicaIds) thr finishSpan.end(); } + writeLock(); + try { + transactionState.resetTabletCommitInfos(); + } finally { + writeUnlock(); + } + transactionState.notifyVisible(); // do after transaction finish GlobalStateMgr.getCurrentState().getOperationListenerBus().onStreamJobTransactionFinish(transactionState); @@ -1886,7 +1892,6 @@ public void finishTransactionNew(TransactionState transactionState, Set pu transactionState.setNewFinish(); transactionState.setTransactionStatus(TransactionStatus.VISIBLE); unprotectUpsertTransactionState(transactionState, false); - transactionState.resetTabletCommitInfos(); transactionState.notifyVisible(); txnOperated = true; } finally { @@ -1909,6 +1914,13 @@ public void finishTransactionNew(TransactionState transactionState, Set pu finishSpan.end(); } + writeLock(); + try { + transactionState.resetTabletCommitInfos(); + } finally { + writeUnlock(); + } + // do after transaction finish GlobalStateMgr.getCurrentState().getOperationListenerBus().onStreamJobTransactionFinish(transactionState); GlobalStateMgr.getCurrentState().getLocalMetastore().handleMVRepair(transactionState); From dcf2f0c42ed7d2f9ee06b217582a61af685c056b Mon Sep 17 00:00:00 2001 From: edwinhzhang Date: Thu, 28 Nov 2024 22:10:40 +0800 Subject: [PATCH 3/3] Optimization Logic Signed-off-by: edwinhzhang --- .../transaction/DatabaseTransactionMgr.java | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/fe/fe-core/src/main/java/com/starrocks/transaction/DatabaseTransactionMgr.java b/fe/fe-core/src/main/java/com/starrocks/transaction/DatabaseTransactionMgr.java index 31b187d3fd597..da88943d3f5d2 100644 --- a/fe/fe-core/src/main/java/com/starrocks/transaction/DatabaseTransactionMgr.java +++ b/fe/fe-core/src/main/java/com/starrocks/transaction/DatabaseTransactionMgr.java @@ -1207,13 +1207,7 @@ public void finishTransaction(long transactionId, Set errorReplicaIds) thr finishSpan.end(); } - writeLock(); - try { - transactionState.resetTabletCommitInfos(); - } finally { - writeUnlock(); - } - + resetTransactionStateTabletCommitInfos(transactionState); transactionState.notifyVisible(); // do after transaction finish GlobalStateMgr.getCurrentState().getOperationListenerBus().onStreamJobTransactionFinish(transactionState); @@ -1914,13 +1908,7 @@ public void finishTransactionNew(TransactionState transactionState, Set pu finishSpan.end(); } - writeLock(); - try { - transactionState.resetTabletCommitInfos(); - } finally { - writeUnlock(); - } - + resetTransactionStateTabletCommitInfos(transactionState); // do after transaction finish GlobalStateMgr.getCurrentState().getOperationListenerBus().onStreamJobTransactionFinish(transactionState); GlobalStateMgr.getCurrentState().getLocalMetastore().handleMVRepair(transactionState); @@ -2082,4 +2070,13 @@ public List getSamplesForMemoryTracker() { readUnlock(); } } + + public void resetTransactionStateTabletCommitInfos(TransactionState transactionState) { + writeLock(); + try { + transactionState.resetTabletCommitInfos(); + } finally { + writeUnlock(); + } + } }