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


##########
paimon-mosaic/src/main/java/org/apache/paimon/format/mosaic/MosaicInputFileAdapter.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.format.mosaic;
+
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.fs.SeekableInputStream;
+import org.apache.paimon.mosaic.InputFile;
+
+import java.io.Closeable;
+import java.io.EOFException;
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.Deque;
+import java.util.concurrent.Semaphore;
+
+/**
+ * Adapts Paimon's {@link FileIO} to Mosaic's {@link InputFile} interface.
+ *
+ * <p>Maintains a pool of up to 8 {@link SeekableInputStream} instances. When 
all 8 are in use,
+ * callers block until one is returned. Thread-safe: Mosaic may invoke {@link 
#readFully}
+ * concurrently from multiple threads.
+ */
+public class MosaicInputFileAdapter implements InputFile, Closeable {
+
+    private static final int MAX_POOL_SIZE = 8;
+
+    private final FileIO fileIO;
+    private final Path path;
+    private final Semaphore semaphore;
+    private final Deque<SeekableInputStream> pool;
+    private boolean closed;
+
+    public MosaicInputFileAdapter(FileIO fileIO, Path path) {
+        this.fileIO = fileIO;
+        this.path = path;
+        this.semaphore = new Semaphore(MAX_POOL_SIZE);
+        this.pool = new ArrayDeque<>(MAX_POOL_SIZE);
+    }
+
+    @Override
+    public void readFully(long position, byte[] buffer, int offset, int 
length) throws IOException {
+        SeekableInputStream in = acquire();

Review Comment:
   We should use pread.



-- 
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