This is an automated email from the ASF dual-hosted git repository. w41ter pushed a commit to branch branch-4.0-cherry-pr60738 in repository https://gitbox.apache.org/repos/asf/doris.git
commit 4392263e2e23009d77823e1babd009097c851b43 Author: w41ter <[email protected]> AuthorDate: Thu Feb 26 09:49:19 2026 +0000 fix truncate with txn --- .../apache/doris/journal/bdbje/BDBEnvironment.java | 26 +++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/journal/bdbje/BDBEnvironment.java b/fe/fe-core/src/main/java/org/apache/doris/journal/bdbje/BDBEnvironment.java index c49efa09151..d2caabdec27 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/journal/bdbje/BDBEnvironment.java +++ b/fe/fe-core/src/main/java/org/apache/doris/journal/bdbje/BDBEnvironment.java @@ -386,9 +386,11 @@ public class BDBEnvironment { long deletedCount = 0; TupleBinding<Long> idBinding = TupleBinding.getPrimitiveBinding(Long.class); + com.sleepycat.je.Transaction txn = null; Cursor cursor = null; try { - cursor = db.openCursor(null, null); + txn = replicatedEnvironment.beginTransaction(null, null); + cursor = db.openCursor(txn, null); DatabaseEntry key = new DatabaseEntry(); DatabaseEntry value = new DatabaseEntry(); while (cursor.getNext(key, value, LockMode.DEFAULT) == OperationStatus.SUCCESS) { @@ -398,10 +400,28 @@ public class BDBEnvironment { deletedCount++; } } - } finally { + // Close cursor before committing transaction + cursor.close(); + cursor = null; + txn.commit(); + txn = null; + } catch (Exception e) { if (cursor != null) { - cursor.close(); + try { + cursor.close(); + } catch (Exception cursorCloseEx) { + LOG.warn("failed to close cursor", cursorCloseEx); + } + } + if (txn != null) { + try { + txn.abort(); + } catch (Exception abortEx) { + LOG.warn("failed to abort transaction", abortEx); + } } + LOG.warn("failed to truncate database {} to journal id {}", dbName, truncateToJournalId, e); + throw new IllegalStateException("failed to truncate database " + dbName, e); } return deletedCount; --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
