Caideyipi commented on code in PR #17711:
URL: https://github.com/apache/iotdb/pull/17711#discussion_r3295885708


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/iotconsensusv2/payload/request/IoTConsensusV2ObjectFilePieceReq.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.iotdb.db.pipe.sink.protocol.iotconsensusv2.payload.request;
+
+import org.apache.iotdb.common.rpc.thrift.TConsensusGroupId;
+import 
org.apache.iotdb.commons.pipe.sink.payload.iotconsensusv2.request.IoTConsensusV2RequestType;
+import 
org.apache.iotdb.commons.pipe.sink.payload.iotconsensusv2.request.IoTConsensusV2RequestVersion;
+import org.apache.iotdb.commons.queryengine.plan.planner.plan.node.PlanNode;
+import org.apache.iotdb.consensus.iotconsensusv2.thrift.TCommitId;
+import 
org.apache.iotdb.consensus.iotconsensusv2.thrift.TIoTConsensusV2TransferReq;
+import org.apache.iotdb.db.queryengine.plan.planner.plan.node.write.ObjectNode;
+import org.apache.iotdb.db.storageengine.dataregion.wal.buffer.WALEntry;
+
+import java.nio.ByteBuffer;
+import java.util.Objects;
+
+public class IoTConsensusV2ObjectFilePieceReq extends 
TIoTConsensusV2TransferReq {
+
+  private transient ObjectNode objectNode;
+
+  private IoTConsensusV2ObjectFilePieceReq() {
+    // Do nothing
+  }
+
+  public ObjectNode getObjectNode() {
+    return objectNode;
+  }
+
+  /////////////////////////////// Thrift ///////////////////////////////
+
+  public static IoTConsensusV2ObjectFilePieceReq toTIoTConsensusV2TransferReq(
+      final ObjectNode objectNode,
+      final TCommitId commitId,
+      final TConsensusGroupId consensusGroupId,
+      final int thisDataNodeId) {
+    final IoTConsensusV2ObjectFilePieceReq req = new 
IoTConsensusV2ObjectFilePieceReq();
+
+    req.objectNode = objectNode;
+    req.commitId = commitId;
+    req.consensusGroupId = consensusGroupId;
+    req.dataNodeId = thisDataNodeId;
+    req.version = IoTConsensusV2RequestVersion.VERSION_1.getVersion();
+    req.type = IoTConsensusV2RequestType.TRANSFER_OBJECT_FILE_PIECE.getType();
+    req.body = objectNode.serialize();

Review Comment:
   `objectNode.serialize()` currently treats source-file read failures as a 
successful transfer: `ObjectNode.serialize()` logs only at debug, writes 
`readSuccess && isEOF`, and still sends the zero-filled `contents` buffer. It 
also uses `RandomAccessFile.read(byte[])` without validating the byte count. 
With this new IoTConsensusV2 path, a removed/truncated object file or short 
read can be accepted by the follower as corrupted content. Please fail fast 
here (and use `readFully` or validate the bytes read) so the event is retried 
instead of committed with bad object data.



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/RelationalInsertTabletNode.java:
##########
@@ -404,6 +405,11 @@ protected List<WritePlanNode> 
doSplit(Map<TRegionReplicaSet, List<Integer>> spli
         // Avoid using system arraycopy when there is no need to split
         setRange(entry.getValue());
         setDataRegionReplicaSet(entry.getKey());
+        for (int i = 0; i < columns.length; i++) {
+          if (dataTypes[i] == TSDataType.OBJECT) {
+            handleObjectValue(i, 0, times.length, entry, result);

Review Comment:
   `times.length` can be the tablet capacity, not the number of valid rows in 
this insert. If a reused tablet has stale OBJECT values after `rowCount`, this 
loop will generate ObjectNodes for rows that are not part of the current write 
and may create extra object rows on the follower. Please bound this by 
`rowCount` (or the active split range) and add coverage where the backing 
arrays are larger than the current row count.



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/RelationalInsertTabletNode.java:
##########
@@ -455,6 +471,44 @@ private List<WritePlanNode> generateOneSplitList(
     return result;
   }
 
+  private void handleObjectValue(
+      int column,
+      int startRow,
+      int endRow,
+      Map.Entry<TRegionReplicaSet, List<Integer>> entry,
+      List<WritePlanNode> result) {
+    for (int row = startRow; row < endRow; row++) {
+      if (((Binary[]) columns[column])[row] == null) {

Review Comment:
   This should honor the null bitmap before reading the `Binary` slot. For 
OBJECT columns a null row can still leave a stale value in a reused backing 
array; this code will transfer that object and only later mark the row null. 
Please mirror the descriptor collection logic and skip rows where `bitMaps != 
null && bitMaps[column] != null && bitMaps[column].isMarked(row)`.



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