diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/utils/MultiTsFileDeviceIterator.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/utils/MultiTsFileDeviceIterator.java index 26f20697e2da..32a1593c4a65 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/utils/MultiTsFileDeviceIterator.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/utils/MultiTsFileDeviceIterator.java @@ -166,10 +166,13 @@ public boolean hasNextDevice() { boolean hasNext = false; for (TsFileDeviceIterator iterator : deviceIteratorMap.values()) { hasNext = - hasNext - || iterator.hasNext() + iterator.hasNext() || (iterator.current() != null && !iterator.current().left.equals(currentDevice.left)); + + if (hasNext) { + break; + } } return hasNext; }