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


##########
integration-test/src/test/java/org/apache/iotdb/pipe/it/single/IoTDBPipeCompactionSinkParameterIT.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * 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.pipe.it.single;
+
+import org.apache.iotdb.commons.client.sync.SyncConfigNodeIServiceClient;
+import org.apache.iotdb.commons.pipe.config.constant.PipeSinkConstant;
+import org.apache.iotdb.confignode.rpc.thrift.TCreatePipeReq;
+import org.apache.iotdb.confignode.rpc.thrift.TShowPipeInfo;
+import org.apache.iotdb.confignode.rpc.thrift.TShowPipeReq;
+import org.apache.iotdb.it.framework.IoTDBTestRunner;
+import org.apache.iotdb.itbase.category.MultiClusterIT1;
+import org.apache.iotdb.rpc.TSStatusCode;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@RunWith(IoTDBTestRunner.class)
+@Category({MultiClusterIT1.class})
+public class IoTDBPipeCompactionSinkParameterIT extends AbstractPipeSingleIT {

Review Comment:
   Moved the compaction parameter assertions into the existing 
`IoTDBPipeSingleEnvDemoIT.testSingleEnv` test and removed the dedicated test 
class. This reuses the existing cluster startup/teardown. Verified with the 
`MultiClusterIT1` profile: 1 test, 0 failures/errors/skips. Included in 
eae842778e3001a0188900d0866bc0a7d467dd7f.



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/agent/task/subtask/sink/PipeRealtimePriorityBlockingQueue.java:
##########
@@ -203,22 +199,39 @@ public Event peek() {
 
   public synchronized void replace(
       String dataRegionId, Set<TsFileResource> sourceFiles, 
List<TsFileResource> targetFiles) {
+    if (!enableCompaction) {
+      return;
+    }
 
     final int regionId = Integer.parseInt(dataRegionId);
+    final Set<Path> sourceFilePaths =
+        sourceFiles.stream()
+            .map(TsFileResource::getTsFile)
+            .map(PipeRealtimePriorityBlockingQueue::normalizePath)
+            .collect(Collectors.toSet());
+
     final Map<CommitterKey, Set<PipeTsFileInsertionEvent>> 
eventsToBeRemovedGroupByCommitterKey =
         tsfileInsertEventDeque.stream()
             .filter(
                 event ->
                     event instanceof PipeTsFileInsertionEvent
                         && ((PipeTsFileInsertionEvent) event).getRegionId() == 
regionId)
             .map(event -> (PipeTsFileInsertionEvent) event)
+            .filter(event -> 
sourceFilePaths.contains(normalizePath(event.getSourceTsFile())))
             .collect(
                 Collectors.groupingBy(
                     PipeTsFileInsertionEvent::getCommitterKey, 
Collectors.toSet()))
             .entrySet()
             .stream()
-            // Replace if all source files are present in the queue
-            .filter(entry -> entry.getValue().size() == sourceFiles.size())
+            // Replace only when every source file is present exactly once for 
this pipe.
+            .filter(entry -> entry.getValue().size() == sourceFilePaths.size())
+            .filter(
+                entry ->
+                    entry.getValue().stream()
+                        .map(PipeTsFileInsertionEvent::getSourceTsFile)
+                        .map(PipeRealtimePriorityBlockingQueue::normalizePath)
+                        .collect(Collectors.toSet())
+                        .equals(sourceFilePaths))

Review Comment:
   I am keeping the complete-source requirement for this fix. A partial 
replacement also replays data from the files that have already been sent, so 
the size ratio alone does not establish safe overwrite/replay and progress 
behavior. The proposed IO optimization needs dedicated tests for those cases 
before relaxing the condition. This update fixes source matching and preserves 
the replacement's queue position.



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