From 38495a1a33d54c57d30f16d0a683a149fc9ed0ad Mon Sep 17 00:00:00 2001 From: "liming.1018" Date: Mon, 13 Nov 2023 21:29:34 +0800 Subject: [PATCH] [common] fix the problem that RecordReader may not be closed in asynchronous compact thread. --- .../apache/paimon/reader/RecordReaderIterator.java | 12 +++++++++--- 1 file changed, 9 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 fedb1aeef4f8..5a807c6f115c 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,9 @@ private void advanceIfNeeded() { break; } else { currentIterator.releaseBatch(); + // 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 +92,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(); } }