Copilot commented on code in PR #10008:
URL: https://github.com/apache/paimon/pull/10008#discussion_r4070893840
##########
paimon-core/src/main/java/org/apache/paimon/append/dataevolution/RowRangeMappingIndex.java:
##########
@@ -166,6 +170,28 @@ boolean overlaps(Range oldRange) {
return index < oldStarts.length && oldStarts[index] <= oldRange.to;
}
+ void serialize(DataOutputView out) throws IOException {
+ out.writeInt(oldStarts.length);
+ for (int i = 0; i < oldStarts.length; i++) {
+ out.writeLong(oldStarts[i]);
+ out.writeLong(oldEnds[i]);
+ out.writeLong(Math.addExact(newStarts[i], newStartOffset));
+ }
+ }
+
+ static RowRangeMappingIndex deserialize(DataInputView in) throws
IOException {
+ int size = readCount(in, "row-id mappings");
+ long[] oldStarts = new long[size];
+ long[] oldEnds = new long[size];
+ long[] newStarts = new long[size];
Review Comment:
A valid CRC only shows that the bytes are self-consistent; it does not make
the count safe. A plan with a small payload and `Integer.MAX_VALUE` here can
allocate three enormous arrays before the subsequent reads fail, allowing a
malformed plan to exhaust the process. Bound the count by the remaining payload
bytes before allocating the arrays.
##########
paimon-core/src/main/java/org/apache/paimon/append/dataevolution/SerializationAssignment.java:
##########
@@ -0,0 +1,205 @@
+/*
+ * 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.append.dataevolution;
+
+import org.apache.paimon.Snapshot;
+import org.apache.paimon.data.BinaryRow;
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.io.DataInputDeserializer;
+import org.apache.paimon.io.DataOutputViewStreamWrapper;
+import org.apache.paimon.table.FileStoreTable;
+import org.apache.paimon.utils.FileStorePathFactory;
+
+import javax.annotation.Nullable;
+
+import java.io.BufferedOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.UncheckedIOException;
+import java.nio.ByteBuffer;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.UUID;
+import java.util.zip.CRC32;
+import java.util.zip.CheckedOutputStream;
+
+import static org.apache.paimon.utils.IOUtils.readFully;
+import static org.apache.paimon.utils.Preconditions.checkArgument;
+import static org.apache.paimon.utils.SerializationUtils.deserializeBinaryRow;
+import static org.apache.paimon.utils.SerializationUtils.readCount;
+import static org.apache.paimon.utils.SerializationUtils.serializeBinaryRow;
+
+/** Persisted row-id mappings and allocation bounds copied from a reassignment
attempt. */
+public final class SerializationAssignment {
+
+ /** A snapshot-local marker and reference to the plan in the manifest
directory. */
+ public static final String PLAN_FILE_PROPERTY = "row-id-reassign.plan";
+
+ public static final String REASSIGN_SNAPSHOT_ID = "reassign-snapshot-id";
+
+ private static final int VERSION = 1;
+ private static final String FILE_PREFIX = "snapshot-";
+
+ private final long snapshotId;
+ private final Map<BinaryRow, RowRangeMappingIndex> rowIdMappings;
+ private final long firstAssignedRowId;
+ private final long nextRowId;
+
+ private SerializationAssignment(
+ long snapshotId,
+ Map<BinaryRow, RowRangeMappingIndex> rowIdMappings,
+ long firstAssignedRowId,
+ long nextRowId) {
+ checkArgument(
+ snapshotId >= Snapshot.FIRST_SNAPSHOT_ID,
+ "Invalid reassignment snapshot ID: %s.",
+ snapshotId);
+ checkArgument(!rowIdMappings.isEmpty(), "Reassignment mappings must
not be empty.");
+ checkArgument(
+ firstAssignedRowId >= 0 && nextRowId > firstAssignedRowId,
+ "Invalid assigned row-id range [%s, %s).",
+ firstAssignedRowId,
+ nextRowId);
+ this.snapshotId = snapshotId;
+ this.rowIdMappings = Collections.unmodifiableMap(new
LinkedHashMap<>(rowIdMappings));
+ this.firstAssignedRowId = firstAssignedRowId;
+ this.nextRowId = nextRowId;
+ }
+
+ /** The reassignment snapshot that references this plan file. */
+ public long snapshotId() {
+ return snapshotId;
+ }
+
+ public long firstAssignedRowId() {
+ return firstAssignedRowId;
+ }
+
+ public long nextRowId() {
+ return nextRowId;
+ }
+
+ /** Returns a plan only for the snapshot that committed it, ignoring
inherited properties. */
+ @Nullable
+ public static String planFile(Snapshot snapshot) {
+ Map<String, String> properties = snapshot.properties();
+ if (properties == null
+ ||
!Long.toString(snapshot.id()).equals(properties.get(REASSIGN_SNAPSHOT_ID))) {
+ return null;
+ }
+ return properties.get(PLAN_FILE_PROPERTY);
Review Comment:
Snapshot properties can be supplied by committers, but this returns any
`row-id-reassign.plan` value once the marker matches. Snapshot/tag expiration
then passes that value to manifest deletion, whose path factory resolves
relative components; a committer can set both properties and make cleanup
delete outside the manifest directory. Validate the filename against the
generated `snapshot-<id>-<UUID>.reassign-plan` form before returning it.
--
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]