From c59c9271490ec9d4f61965ad67d8d67e864dc8a2 Mon Sep 17 00:00:00 2001 From: "liming.1018" Date: Mon, 13 Nov 2023 21:12:22 +0800 Subject: [PATCH] [common] fix the problem that RecordReader may not be closed in asynchronous compact thread. --- .../apache/paimon/reader/RecordReaderIterator.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/paimon-common/src/main/java/org/apache/paimon/reader/RecordReaderIterator.java b/paimon-common/src/main/java/org/apache/paimon/reader/RecordReaderIterator.java index fedb1aeef4f8e..201901fd40132 100644 --- a/paimon-common/src/main/java/org/apache/paimon/reader/RecordReaderIterator.java +++ b/paimon-common/src/main/java/org/apache/paimon/reader/RecordReaderIterator.java @@ -76,6 +76,10 @@ private void advanceIfNeeded() { break; } else { currentIterator.releaseBatch(); + // reset currentIterator, because reader#readBatch will be affected by + // interrupt, which will cause currentIterator#releaseBatch to be executed + // twice. + currentIterator = null; currentIterator = reader.readBatch(); if (currentIterator == null) { break; @@ -89,9 +93,12 @@ private void advanceIfNeeded() { @Override public void close() throws Exception { - if (currentIterator != null) { - currentIterator.releaseBatch(); + try { + if (currentIterator != null) { + currentIterator.releaseBatch(); + } + } finally { + reader.close(); } - reader.close(); } }