JingsongLi commented on code in PR #9481:
URL: https://github.com/apache/paimon/pull/9481#discussion_r3911841336


##########
paimon-lumina/src/main/java/org/apache/paimon/lumina/index/LuminaVectorGlobalIndexWriter.java:
##########
@@ -427,16 +428,23 @@ static class FileBackedDataset implements LuminaDataset, 
Closeable {
         FileBackedDataset(File file, int dim, long totalCount, String phase, 
int bufferSize)
                 throws IOException {
             this.raf = new RandomAccessFile(file, "r");
-            this.channel = raf.getChannel();
-            this.dim = dim;
-            this.totalCount = totalCount;
-            this.recordSizeInBytes = checkedRecordSize(dim, bufferSize);
-            this.cursor = 0;
-            this.readBuf = ByteBuffer.allocateDirect(bufferSize);
-            this.readBuf.order(ByteOrder.nativeOrder());
-            this.readBuf.limit(0); // empty initially
-            this.phase = phase;
-            this.lastLoggedPercent = -1;
+            try {
+                this.channel = raf.getChannel();
+                this.dim = dim;
+                this.totalCount = totalCount;
+                this.recordSizeInBytes = checkedRecordSize(dim, bufferSize);
+                this.cursor = 0;
+                this.readBuf = ByteBuffer.allocateDirect(bufferSize);
+                this.readBuf.order(ByteOrder.nativeOrder());
+                this.readBuf.limit(0); // empty initially
+                this.phase = phase;
+                this.lastLoggedPercent = -1;
+            } catch (RuntimeException e) {

Review Comment:
   [P2] Also close the file when direct-buffer allocation throws an Error
   
   The cleanup currently only handles `RuntimeException`, but the other 
post-open failure named in the PR, `ByteBuffer.allocateDirect`, can throw 
`OutOfMemoryError`. A direct-memory OOM can be caught by a higher-level 
task/runtime and leave this JVM alive; in that path the constructor still 
strands `raf`, which is exactly the resource-safety hole this change is 
intended to close. Please catch and rethrow `RuntimeException | Error` (or use 
the usual constructor-cleanup `catch (Throwable)` pattern) so every failure 
after the successful open releases the handle. The existing regression only 
exercises `checkedRecordSize`, so it does not cover this path.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to