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


##########
paimon-common/src/main/java/org/apache/paimon/fileindex/FileIndexFormatUtils.java:
##########
@@ -0,0 +1,156 @@
+/*
+ * 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.fileindex;
+
+import org.apache.paimon.fs.PositionOutputStream;
+import org.apache.paimon.fs.SeekableInputStream;
+import org.apache.paimon.utils.Pair;
+
+import java.io.DataInput;
+import java.io.DataInputStream;
+import java.io.DataOutput;
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+/** Utilities shared by file index container versions. */
+final class FileIndexFormatUtils {
+
+    static final long MAGIC = 1493475289347502L;
+    static final int EMPTY_INDEX_FLAG = -1;
+    static final int VERSION_1 = 1;
+    static final int VERSION_2 = 2;
+
+    private FileIndexFormatUtils() {}
+
+    static void writeMagicAndVersion(DataOutput output, int version) throws 
IOException {
+        // writeMagic
+        output.writeLong(MAGIC);
+        // writeVersion
+        output.writeInt(version);
+    }
+
+    static boolean isV2(SeekableInputStream input) throws IOException {
+        long position = input.getPos();
+        try {
+            DataInputStream dataInput = new DataInputStream(input);
+            return dataInput.readLong() == MAGIC && dataInput.readInt() == 
VERSION_2;
+        } catch (EOFException e) {
+            return false;
+        } finally {
+            input.seek(position);

Review Comment:
   [P2] Avoid rewinding the V1 index stream after the version probe.
   
   `FileIndexPredicate.createReader` calls `isV2` for every external index. For 
the default V1 format, this consumes the 12-byte prefix, seeks back to the 
start, and then the V1 reader reads the prefix again. 
`HadoopFileIO.HadoopSeekableInputStream` forwards backward seeks to the 
underlying filesystem stream; on S3A, that can reopen the object stream and 
issue another GET per index file during filtered scans. This regresses the 
existing V1 read path even when V2 writing is disabled. Could we reuse the 
prefix already read (or replay it from a small buffer) so the V1 reader can 
continue without a backward seek, while still obtaining the file length only 
for V2?



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