Jackie-Jiang commented on a change in pull request #5728:
URL: https://github.com/apache/incubator-pinot/pull/5728#discussion_r463208420



##########
File path: 
pinot-broker/src/main/java/org/apache/pinot/broker/routing/segmentselector/SegmentLineageBasedSegmentPreSelector.java
##########
@@ -0,0 +1,65 @@
+/**
+ * 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.pinot.broker.routing.segmentselector;
+
+import java.util.HashSet;
+import java.util.Set;
+import org.apache.helix.ZNRecord;
+import org.apache.helix.store.zk.ZkHelixPropertyStore;
+import org.apache.pinot.common.lineage.LineageEntry;
+import org.apache.pinot.common.lineage.LineageEntryState;
+import org.apache.pinot.common.lineage.SegmentLineage;
+import org.apache.pinot.common.lineage.SegmentLineageAccessHelper;
+
+
+/**
+ * Segment lineage based segment pre-selector
+ *
+ * This pre-selector reads the segment lineage metadata and filters out either 
merged segments or original segments
+ * to make sure that the final segments contain no duplicate data.
+ */
+public class SegmentLineageBasedSegmentPreSelector implements 
SegmentPreSelector {
+  private final String _tableNameWithType;
+  private final ZkHelixPropertyStore<ZNRecord> _propertyStore;
+
+  public SegmentLineageBasedSegmentPreSelector(String tableNameWithType, 
ZkHelixPropertyStore<ZNRecord> propertyStore) {
+    _tableNameWithType = tableNameWithType;
+    _propertyStore = propertyStore;
+  }
+
+  @Override
+  public Set<String> preSelect(Set<String> onlineSegments) {
+    Set<String> segmentsToProcess = new HashSet<>(onlineSegments);
+    SegmentLineage segmentLineage = 
SegmentLineageAccessHelper.getSegmentLineage(_propertyStore, 
_tableNameWithType);
+    Set<String> segmentsToRemove = new HashSet<>();
+    if (segmentLineage != null) {
+      for (String lineageEntryId : segmentLineage.getLineageEntryIds()) {
+        LineageEntry lineageEntry = 
segmentLineage.getLineageEntry(lineageEntryId);
+        if (lineageEntry.getState() == LineageEntryState.COMPLETED && 
onlineSegments
+            .containsAll(lineageEntry.getSegmentsTo())) {

Review comment:
       This won't work because the `onlineSegments` are from the `idealState` 
instead of the `externalView`. Also, it  won't be able to handle some corner 
cases.
   E.g. the lineage is as following, and one segment in segmentsB is unavailable
   segmentsA -> segmentsB -> segmentsC
   This algorithm will select both segmentsA and segmentsC, which will cause 
wrong result.
   
   I still think we should handle this when updating the lineage. Before 
updating the lineage to `COMPLETED`, we check whether all `segmentsTo` are 
available in externalView. Also, the updater needs to notify the broker to 
rebuild the routing because there might be no externalView change to trigger 
the lineage update.

##########
File path: 
pinot-broker/src/main/java/org/apache/pinot/broker/routing/segmentselector/SegmentLineageBasedSegmentPreSelector.java
##########
@@ -0,0 +1,65 @@
+/**
+ * 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.pinot.broker.routing.segmentselector;
+
+import java.util.HashSet;
+import java.util.Set;
+import org.apache.helix.ZNRecord;
+import org.apache.helix.store.zk.ZkHelixPropertyStore;
+import org.apache.pinot.common.lineage.LineageEntry;
+import org.apache.pinot.common.lineage.LineageEntryState;
+import org.apache.pinot.common.lineage.SegmentLineage;
+import org.apache.pinot.common.lineage.SegmentLineageAccessHelper;
+
+
+/**
+ * Segment lineage based segment pre-selector
+ *
+ * This pre-selector reads the segment lineage metadata and filters out either 
merged segments or original segments
+ * to make sure that the final segments contain no duplicate data.
+ */
+public class SegmentLineageBasedSegmentPreSelector implements 
SegmentPreSelector {
+  private final String _tableNameWithType;
+  private final ZkHelixPropertyStore<ZNRecord> _propertyStore;
+
+  public SegmentLineageBasedSegmentPreSelector(String tableNameWithType, 
ZkHelixPropertyStore<ZNRecord> propertyStore) {
+    _tableNameWithType = tableNameWithType;
+    _propertyStore = propertyStore;
+  }
+
+  @Override
+  public Set<String> preSelect(Set<String> onlineSegments) {
+    Set<String> segmentsToProcess = new HashSet<>(onlineSegments);
+    SegmentLineage segmentLineage = 
SegmentLineageAccessHelper.getSegmentLineage(_propertyStore, 
_tableNameWithType);
+    Set<String> segmentsToRemove = new HashSet<>();
+    if (segmentLineage != null) {

Review comment:
       Check lineage before creating `segmentsToProcess` and 
`segmentsToRemove`. If lineage does not exist, directly return `onlineSegments` 
to prevent unnecessary overhead.
   (Optional) Consider modifying `onlineSegments` in-place?

##########
File path: 
pinot-broker/src/main/java/org/apache/pinot/broker/routing/RoutingManager.java
##########
@@ -312,6 +314,8 @@ public synchronized void buildRouting(String 
tableNameWithType) {
 
     Set<String> enabledInstances = _enabledServerInstanceMap.keySet();
 
+    SegmentPreSelector segmentPreSelector =
+        SegmentPreSelectorFactory.getSegmentPreSelector(tableConfig, 
_propertyStore);

Review comment:
       Pre-select `onlineSegments` before calling `init` on other components




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to