Skip to content

Commit 8801b6d

Browse files
committed
Fix cleanup due to bug in Datafusion Reader not releasing catalog snapshot
Signed-off-by: Mohit Godwani <[email protected]>
1 parent ad3eb7c commit 8801b6d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

plugins/engine-datafusion/src/main/java/org/opensearch/datafusion/jni/handle/ReaderHandle.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,23 @@
1111
import org.opensearch.datafusion.jni.NativeBridge;
1212
import org.opensearch.vectorized.execution.jni.RefCountedNativeHandle;
1313

14+
import java.io.Closeable;
15+
1416
/**
1517
* Reference-counted handle for native reader.
1618
*/
1719
public final class ReaderHandle extends RefCountedNativeHandle {
1820

19-
public ReaderHandle(String path, String[] files) {
21+
private final Runnable onClose;
22+
23+
public ReaderHandle(String path, String[] files, Runnable onClose) {
2024
super(NativeBridge.createDatafusionReader(path, files));
25+
this.onClose = onClose;
2126
}
2227

2328
@Override
2429
protected void doClose() {
2530
NativeBridge.closeDatafusionReader(ptr);
31+
onClose.run();
2632
}
2733
}

plugins/engine-datafusion/src/main/java/org/opensearch/datafusion/search/DatafusionReader.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public DatafusionReader(String directoryPath, CompositeEngine.ReleasableRef<Cata
5555
}
5656
System.out.println("File names: " + Arrays.toString(fileNames));
5757
System.out.println("Directory path: " + directoryPath);
58-
this.readerHandle = new ReaderHandle(directoryPath, fileNames);
58+
this.readerHandle = new ReaderHandle(directoryPath, fileNames, this::releaseCatalogSnapshot);
5959
}
6060

6161
/**
@@ -91,6 +91,10 @@ public int getRefCount() {
9191
@Override
9292
public void close() {
9393
readerHandle.close();
94+
releaseCatalogSnapshot();
95+
}
96+
97+
private void releaseCatalogSnapshot() {
9498
try {
9599
if (catalogSnapshotRef != null)
96100
catalogSnapshotRef.close();

0 commit comments

Comments
 (0)