This is an automated email from the ASF dual-hosted git repository.

JingsongLi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new 903aa197a1 [core] Remove dangerous partition reusing in 
BinaryManifestEntry
903aa197a1 is described below

commit 903aa197a1e1d14593ecbb72fe532b08fcc07061
Author: JingsongLi <[email protected]>
AuthorDate: Wed Jul 29 09:23:37 2026 +0800

    [core] Remove dangerous partition reusing in BinaryManifestEntry
---
 .../paimon/manifest/BinaryManifestEntry.java       | 56 ++++------------------
 .../paimon/manifest/BinaryManifestEntryTest.java   | 12 ++---
 2 files changed, 14 insertions(+), 54 deletions(-)

diff --git 
a/paimon-core/src/main/java/org/apache/paimon/manifest/BinaryManifestEntry.java 
b/paimon-core/src/main/java/org/apache/paimon/manifest/BinaryManifestEntry.java
index 73e361a904..217d7846a2 100644
--- 
a/paimon-core/src/main/java/org/apache/paimon/manifest/BinaryManifestEntry.java
+++ 
b/paimon-core/src/main/java/org/apache/paimon/manifest/BinaryManifestEntry.java
@@ -23,7 +23,6 @@ import org.apache.paimon.data.BinaryString;
 import org.apache.paimon.data.InternalRow;
 import org.apache.paimon.io.BinaryDataFileMeta;
 import org.apache.paimon.io.DataFileMeta;
-import org.apache.paimon.memory.MemorySegment;
 import org.apache.paimon.memory.MemorySegmentUtils;
 import org.apache.paimon.types.DataField;
 import org.apache.paimon.types.RowType;
@@ -35,6 +34,7 @@ import java.util.List;
 
 import static org.apache.paimon.utils.Preconditions.checkArgument;
 import static org.apache.paimon.utils.Preconditions.checkState;
+import static org.apache.paimon.utils.SerializationUtils.deserializeBinaryRow;
 
 /**
  * Reusable binary view of a projected manifest entry.
@@ -52,7 +52,6 @@ public final class BinaryManifestEntry implements 
ManifestEntry {
 
     private final Projection projection;
     private final @Nullable BinaryDataFileMeta file;
-    private final ReusablePartition partitionView = new ReusablePartition();
     private @Nullable InternalRow row;
 
     private BinaryManifestEntry(Projection projection) {
@@ -79,7 +78,6 @@ public final class BinaryManifestEntry implements 
ManifestEntry {
             file.replace(fileRow);
         }
         this.row = row;
-        this.partitionView.reset();
         return this;
     }
 
@@ -120,7 +118,6 @@ public final class BinaryManifestEntry implements 
ManifestEntry {
     /** Drops references to the current row before its reader batch is 
released. */
     public void clear() {
         row = null;
-        partitionView.reset();
         if (file != null) {
             file.clear();
         }
@@ -143,54 +140,17 @@ public final class BinaryManifestEntry implements 
ManifestEntry {
     }
 
     public byte[] partitionBytes() {
-        return partitionView.getBytes(
-                row, requiredOuterPosition(projection.partitionPosition, 
ManifestEntry.PARTITION));
+        byte[] partition =
+                row.getBinary(
+                        requiredOuterPosition(
+                                projection.partitionPosition, 
ManifestEntry.PARTITION));
+        checkState(partition != null, "Serialized manifest partition cannot be 
null.");
+        return partition;
     }
 
     @Override
     public BinaryRow partition() {
-        return partitionView.getRow(
-                row, requiredOuterPosition(projection.partitionPosition, 
ManifestEntry.PARTITION));
-    }
-
-    private static final class ReusablePartition {
-
-        private final MemorySegment[] segments = new MemorySegment[1];
-        private @Nullable byte[] bytes;
-        private @Nullable BinaryRow row;
-
-        private byte[] getBytes(InternalRow entryRow, int position) {
-            if (bytes == null) {
-                bytes = entryRow.getBinary(position);
-                checkState(bytes != null, "Serialized manifest partition 
cannot be null.");
-            }
-            return bytes;
-        }
-
-        private BinaryRow getRow(InternalRow entryRow, int position) {
-            if (segments[0] == null) {
-                byte[] bytes = getBytes(entryRow, position);
-                checkState(
-                        bytes.length >= Integer.BYTES,
-                        "Serialized manifest partition is too short.");
-                int arity =
-                        ((bytes[0] & 0xff) << 24)
-                                | ((bytes[1] & 0xff) << 16)
-                                | ((bytes[2] & 0xff) << 8)
-                                | (bytes[3] & 0xff);
-                if (row == null || row.getFieldCount() != arity) {
-                    row = new BinaryRow(arity);
-                }
-                segments[0] = MemorySegment.wrap(bytes);
-                row.pointTo(segments, Integer.BYTES, bytes.length - 
Integer.BYTES);
-            }
-            return row;
-        }
-
-        private void reset() {
-            bytes = null;
-            segments[0] = null;
-        }
+        return deserializeBinaryRow(partitionBytes());
     }
 
     @Override
diff --git 
a/paimon-core/src/test/java/org/apache/paimon/manifest/BinaryManifestEntryTest.java
 
b/paimon-core/src/test/java/org/apache/paimon/manifest/BinaryManifestEntryTest.java
index 07f06be10b..aceb117264 100644
--- 
a/paimon-core/src/test/java/org/apache/paimon/manifest/BinaryManifestEntryTest.java
+++ 
b/paimon-core/src/test/java/org/apache/paimon/manifest/BinaryManifestEntryTest.java
@@ -205,7 +205,7 @@ public class BinaryManifestEntryTest {
     }
 
     @Test
-    void testReusesPartitionAndPartitionedIdentifierViews() {
+    void testDoesNotReusePartitionAndUpdatesPartitionedIdentifier() {
         BinaryManifestEntry entry =
                 projection(
                                 true,
@@ -219,15 +219,15 @@ public class BinaryManifestEntryTest {
                 new BinaryManifestEntry.ReusableIdentifier();
 
         entry.replace(identityRow(partition(1)));
-        BinaryRow partitionView = entry.partition();
-        assertThat(partitionView.getInt(0)).isEqualTo(1);
-        assertThat(entry.partition()).isSameAs(partitionView);
+        BinaryRow firstPartition = entry.partition();
+        assertThat(firstPartition.getInt(0)).isEqualTo(1);
+        assertThat(entry.partition()).isNotSameAs(firstPartition);
         identifier.replaceWithPartition(entry);
         byte[] firstIdentifier = Arrays.copyOf(identifier.bytes(), 
identifier.length());
 
         entry.replace(identityRow(partition(2)));
-        assertThat(entry.partition()).isSameAs(partitionView);
-        assertThat(partitionView.getInt(0)).isEqualTo(2);
+        assertThat(firstPartition.getInt(0)).isEqualTo(1);
+        assertThat(entry.partition().getInt(0)).isEqualTo(2);
         identifier.replaceWithPartition(entry);
         assertThat(Arrays.copyOf(identifier.bytes(), identifier.length()))
                 .isNotEqualTo(firstIdentifier);

Reply via email to