You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2020/07/22 12:09:45 UTC
[GitHub] [incubator-pinot] snleee opened a new pull request #5728: Add segment lineage based segment selector
snleee opened a new pull request #5728:
URL: https://github.com/apache/incubator-pinot/pull/5728
Segment lineage based segment selector looks at the
segment lineage metadata and correctly prunes the segments
to make sure that we do not process the duplicate data.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [incubator-pinot] snleee commented on a change in pull request #5728: Add segment lineage based segment selector
Posted by GitBox <gi...@apache.org>.
snleee commented on a change in pull request #5728:
URL: https://github.com/apache/incubator-pinot/pull/5728#discussion_r463323754
##########
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:
Sorry for the confusion. I somehow assumed that `onlineSegments` are from external view but it's actually from the idealstate. As you also said, I also think that it's better to check the external view in `startReplaceSegments and endReplaceSegments`, which updates the segment lineage and keep the segment pre-selector as simple as possible. I will revert this change and file the separate PR for this.
##########
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:
Sorry for the confusion. I somehow assumed that `onlineSegments` are from external view but it's actually from the idealstate. As you also said, I also think that it's better to check the external view in `endReplaceSegments`, which updates the segment lineage and keep the segment pre-selector as simple as possible. I will revert this change and file the separate PR for this.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [incubator-pinot] kishoreg commented on a change in pull request #5728: Add segment lineage based segment selector
Posted by GitBox <gi...@apache.org>.
kishoreg commented on a change in pull request #5728:
URL: https://github.com/apache/incubator-pinot/pull/5728#discussion_r461661440
##########
File path: pinot-broker/src/main/java/org/apache/pinot/broker/routing/segmentselector/OfflineSegmentSelector.java
##########
@@ -42,7 +49,14 @@ public void onExternalViewChange(ExternalView externalView, Set<String> onlineSe
// TODO: for new added segments, before all replicas are up, consider not selecting them to avoid causing
// hotspot servers
- _segments = Collections.unmodifiableList(new ArrayList<>(onlineSegments));
+
+ // Update segment lineage based segment selector
+ _segmentLineageBasedSegmentSelector.onExternalViewChange();
+
+ // Compute the intersection of segments to process from both offline and segment lineage based segment selectors.
+ List<String> segmentsToProcess =
+ new ArrayList<>(_segmentLineageBasedSegmentSelector.computeSegmentsToProcess(onlineSegments));
Review comment:
thinking out loud here, should we model them it as pruner?
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [incubator-pinot] Jackie-Jiang commented on a change in pull request #5728: Add segment lineage based segment selector
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [incubator-pinot] snleee commented on a change in pull request #5728: Add segment lineage based segment selector
Posted by GitBox <gi...@apache.org>.
snleee commented on a change in pull request #5728:
URL: https://github.com/apache/incubator-pinot/pull/5728#discussion_r463326927
##########
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:
good catch :)
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [incubator-pinot] snleee merged pull request #5728: Add segment lineage based segment selector
Posted by GitBox <gi...@apache.org>.
snleee merged pull request #5728:
URL: https://github.com/apache/incubator-pinot/pull/5728
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [incubator-pinot] snleee commented on a change in pull request #5728: Add segment lineage based segment selector
Posted by GitBox <gi...@apache.org>.
snleee commented on a change in pull request #5728:
URL: https://github.com/apache/incubator-pinot/pull/5728#discussion_r463329083
##########
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:
changed to modify `onlineSegments` in-place and also changed the code to create `segmentsToRemove` only if the lineage entry is not null.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [incubator-pinot] snleee commented on a change in pull request #5728: Add segment lineage based segment selector
Posted by GitBox <gi...@apache.org>.
snleee commented on a change in pull request #5728:
URL: https://github.com/apache/incubator-pinot/pull/5728#discussion_r463328679
##########
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:
As for the edge case that you mentioned, the edge case is correctly covered if we check external view when updating the lineage and segment pre-selector only checks `COMPLETED`.
This means that once the validation passes and lineage entry gets updated to `COMPLETED`, we will never fall back to the original segments (which makes sense because original segments will get deleted by the retention manager soon).
##########
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:
As for the edge case that you mentioned, the edge case is correctly covered if we check external view when updating the lineage and segment pre-selector only checks `COMPLETED`.
This means that once the validation passes and the lineage entry gets updated to `COMPLETED`, we will never fall back to the original segments (which makes sense because original segments will get deleted by the retention manager soon).
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [incubator-pinot] snleee commented on a change in pull request #5728: Add segment lineage based segment selector
Posted by GitBox <gi...@apache.org>.
snleee commented on a change in pull request #5728:
URL: https://github.com/apache/incubator-pinot/pull/5728#discussion_r463323754
##########
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:
Sorry for the confusion. I somehow assumed that `onlineSegments` are from external view but it's actually from the idealstate. As you also said, I also think that it's better to check the external view in `startReplaceSegments`, which updates the segment lineage and keep the segment pre-selector as simple as possible. I will revert this change and file the separate PR for this.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [incubator-pinot] mayankshriv commented on a change in pull request #5728: Add segment lineage based segment selector
Posted by GitBox <gi...@apache.org>.
mayankshriv commented on a change in pull request #5728:
URL: https://github.com/apache/incubator-pinot/pull/5728#discussion_r460408329
##########
File path: pinot-broker/src/main/java/org/apache/pinot/broker/routing/segmentselector/OfflineSegmentSelector.java
##########
@@ -30,10 +30,17 @@
* Segment selector for offline table.
*/
public class OfflineSegmentSelector implements SegmentSelector {
+ private final SegmentLineageBasedSegmentSelector _segmentLineageBasedSegmentSelector;
Review comment:
This seems a bit confusing:
1. One segment selector class contains another segment segment selector.
2. Even though both are named SegmentSelector, only one of them implements the SegmentSelector interface.
I think SegmentLineageBasedSegmentSelector needs to be renamed, since it is not really implementing the interface.
##########
File path: pinot-broker/src/main/java/org/apache/pinot/broker/routing/segmentselector/OfflineSegmentSelector.java
##########
@@ -42,7 +49,14 @@ public void onExternalViewChange(ExternalView externalView, Set<String> onlineSe
// TODO: for new added segments, before all replicas are up, consider not selecting them to avoid causing
// hotspot servers
- _segments = Collections.unmodifiableList(new ArrayList<>(onlineSegments));
+
+ // Update segment lineage based segment selector
+ _segmentLineageBasedSegmentSelector.onExternalViewChange();
+
+ // Compute the intersection of segments to process from both offline and segment lineage based segment selectors.
+ List<String> segmentsToProcess =
+ new ArrayList<>(_segmentLineageBasedSegmentSelector.computeSegmentsToProcess(onlineSegments));
Review comment:
I am unclear on the extensibility of the code in future. Will we add more selectors and cascade them in future, for example versionBasedSelector/Pruner?
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [incubator-pinot] snleee commented on a change in pull request #5728: Add segment lineage based segment selector
Posted by GitBox <gi...@apache.org>.
snleee commented on a change in pull request #5728:
URL: https://github.com/apache/incubator-pinot/pull/5728#discussion_r462991298
##########
File path: pinot-broker/src/main/java/org/apache/pinot/broker/routing/segmentselector/SegmentLineageBasedSegmentSelector.java
##########
@@ -0,0 +1,69 @@
+/**
+ * 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.Collections;
+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;
+
+
+public class SegmentLineageBasedSegmentSelector {
+ private final String _tableNameWithType;
+ private final ZkHelixPropertyStore<ZNRecord> _propertyStore;
+
+ private volatile Set<String> _segmentsToRemove;
+
+ public SegmentLineageBasedSegmentSelector(String tableNameWithType, ZkHelixPropertyStore<ZNRecord> propertyStore) {
+ _tableNameWithType = tableNameWithType;
+ _propertyStore = propertyStore;
+ }
+
+ public void init() {
Review comment:
I adopted the `SegmentPreSelector` model.
##########
File path: pinot-broker/src/main/java/org/apache/pinot/broker/routing/segmentselector/OfflineSegmentSelector.java
##########
@@ -30,10 +30,17 @@
* Segment selector for offline table.
*/
public class OfflineSegmentSelector implements SegmentSelector {
+ private final SegmentLineageBasedSegmentSelector _segmentLineageBasedSegmentSelector;
Review comment:
I adopted the `SegmentPreSelector` model.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [incubator-pinot] Jackie-Jiang commented on a change in pull request #5728: Add segment lineage based segment selector
Posted by GitBox <gi...@apache.org>.
Jackie-Jiang commented on a change in pull request #5728:
URL: https://github.com/apache/incubator-pinot/pull/5728#discussion_r463333041
##########
File path: pinot-broker/src/main/java/org/apache/pinot/broker/routing/segmentselector/SegmentLineageBasedSegmentPreSelector.java
##########
@@ -0,0 +1,63 @@
+/**
+ * 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) {
+ SegmentLineage segmentLineage = SegmentLineageAccessHelper.getSegmentLineage(_propertyStore, _tableNameWithType);
+ if (segmentLineage != null) {
+ Set<String> segmentsToRemove = new HashSet<>();
+ for (String lineageEntryId : segmentLineage.getLineageEntryIds()) {
+ LineageEntry lineageEntry = segmentLineage.getLineageEntry(lineageEntryId);
+ if (lineageEntry.getState() == LineageEntryState.COMPLETED) {
+ segmentsToRemove.addAll(lineageEntry.getSegmentsFrom());
Review comment:
(nit) You can directly remove them from `onlineSegments`
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [incubator-pinot] Jackie-Jiang commented on a change in pull request #5728: Add segment lineage based segment selector
Posted by GitBox <gi...@apache.org>.
Jackie-Jiang commented on a change in pull request #5728:
URL: https://github.com/apache/incubator-pinot/pull/5728#discussion_r461791755
##########
File path: pinot-broker/src/main/java/org/apache/pinot/broker/routing/segmentselector/OfflineSegmentSelector.java
##########
@@ -42,7 +49,14 @@ public void onExternalViewChange(ExternalView externalView, Set<String> onlineSe
// TODO: for new added segments, before all replicas are up, consider not selecting them to avoid causing
// hotspot servers
- _segments = Collections.unmodifiableList(new ArrayList<>(onlineSegments));
+
+ // Update segment lineage based segment selector
+ _segmentLineageBasedSegmentSelector.onExternalViewChange();
+
+ // Compute the intersection of segments to process from both offline and segment lineage based segment selectors.
+ List<String> segmentsToProcess =
+ new ArrayList<>(_segmentLineageBasedSegmentSelector.computeSegmentsToProcess(onlineSegments));
Review comment:
@kishoreg Based on the interface definition, I feel it is better to model it as SegmentSelector (`The segments selected should cover the whole dataset (table) without overlap`). Another benefit of putting it in `Selector`/`Preselector` is to avoid the per-query calculation within the `Pruner`
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [incubator-pinot] Jackie-Jiang commented on a change in pull request #5728: Add segment lineage based segment selector
Posted by GitBox <gi...@apache.org>.
Jackie-Jiang commented on a change in pull request #5728:
URL: https://github.com/apache/incubator-pinot/pull/5728#discussion_r459044062
##########
File path: pinot-broker/src/main/java/org/apache/pinot/broker/routing/segmentselector/SegmentLineageBasedSegmentSelector.java
##########
@@ -0,0 +1,80 @@
+/**
+ * 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.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import org.apache.helix.ZNRecord;
+import org.apache.helix.model.ExternalView;
+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;
+import org.apache.pinot.common.request.BrokerRequest;
+
+
+public class SegmentLineageBasedSegmentSelector implements SegmentSelector {
Review comment:
Don't implement `SegmentSelector` because it is not actually a segment selector, but a component inside the segment selector.
You may re-design the methods for this class to make it easier to use, e.g. `public Set<String> refreshLinage(Set<String> onlineSegments);` which returns the candidate segments based on the linage
##########
File path: pinot-broker/src/main/java/org/apache/pinot/broker/routing/segmentselector/OfflineSegmentSelector.java
##########
@@ -30,10 +31,17 @@
* Segment selector for offline table.
*/
public class OfflineSegmentSelector implements SegmentSelector {
+ private SegmentLineageBasedSegmentSelector _segmentLineageBasedSegmentSelector;
Review comment:
```suggestion
private final SegmentLineageBasedSegmentSelector _segmentLineageBasedSegmentSelector;
```
##########
File path: pinot-broker/src/main/java/org/apache/pinot/broker/routing/segmentselector/SegmentSelectorFactory.java
##########
@@ -17,19 +17,25 @@
* under the License.
*/
package org.apache.pinot.broker.routing.segmentselector;
+import org.apache.helix.ZNRecord;
+import org.apache.helix.store.zk.ZkHelixPropertyStore;
import org.apache.pinot.spi.config.table.TableConfig;
import org.apache.pinot.spi.config.table.TableType;
+import org.apache.pinot.spi.utils.builder.TableNameBuilder;
public class SegmentSelectorFactory {
private SegmentSelectorFactory() {
}
- public static SegmentSelector getSegmentSelector(TableConfig tableConfig) {
+ public static SegmentSelector getSegmentSelector(TableConfig tableConfig,
+ ZkHelixPropertyStore<ZNRecord> propertyStore) {
+ String tableNameWithType =
+ TableNameBuilder.forType(tableConfig.getTableType()).tableNameWithType(tableConfig.getTableName());
Review comment:
Table name in table config always have the suffix
```suggestion
String tableNameWithType = tableConfig.getTableName();
```
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [incubator-pinot] snleee commented on a change in pull request #5728: Add segment lineage based segment selector
Posted by GitBox <gi...@apache.org>.
snleee commented on a change in pull request #5728:
URL: https://github.com/apache/incubator-pinot/pull/5728#discussion_r463323754
##########
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:
Sorry for the confusion. I somehow assumed that `onlineSegments` are from external view but it's actually from the idealstate. As you also said, I also think that it's better to check the external view in `startReplaceSegments`, which updates the segment lineage and keep the segment pre-selector as simple as possible. I will file the separate PR for this.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [incubator-pinot] snleee commented on a change in pull request #5728: Add segment lineage based segment selector
Posted by GitBox <gi...@apache.org>.
snleee commented on a change in pull request #5728:
URL: https://github.com/apache/incubator-pinot/pull/5728#discussion_r459846427
##########
File path: pinot-broker/src/main/java/org/apache/pinot/broker/routing/segmentselector/SegmentSelectorFactory.java
##########
@@ -17,19 +17,25 @@
* under the License.
*/
package org.apache.pinot.broker.routing.segmentselector;
+import org.apache.helix.ZNRecord;
+import org.apache.helix.store.zk.ZkHelixPropertyStore;
import org.apache.pinot.spi.config.table.TableConfig;
import org.apache.pinot.spi.config.table.TableType;
+import org.apache.pinot.spi.utils.builder.TableNameBuilder;
public class SegmentSelectorFactory {
private SegmentSelectorFactory() {
}
- public static SegmentSelector getSegmentSelector(TableConfig tableConfig) {
+ public static SegmentSelector getSegmentSelector(TableConfig tableConfig,
+ ZkHelixPropertyStore<ZNRecord> propertyStore) {
+ String tableNameWithType =
+ TableNameBuilder.forType(tableConfig.getTableType()).tableNameWithType(tableConfig.getTableName());
Review comment:
fixed
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [incubator-pinot] snleee commented on a change in pull request #5728: Add segment lineage based segment selector
Posted by GitBox <gi...@apache.org>.
snleee commented on a change in pull request #5728:
URL: https://github.com/apache/incubator-pinot/pull/5728#discussion_r463328679
##########
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:
As for the edge case that you mentioned, the edge case is correctly covered if we check external view when updating the lineage and segment pre-selector only checks `COMPLETED`.
This means that once the validation passes and the lineage entry gets updated to `COMPLETED`, we will never fall back to the original segments (which makes sense because original segments needs to be deleted by the retention manager soon).
##########
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:
As for the edge case that you mentioned, the edge case is correctly covered if we check external view when updating the lineage and segment pre-selector only checks `COMPLETED`.
This means that once the validation passes and the lineage entry gets updated to `COMPLETED`, we will never fall back to the original segments (which makes sense because original segments need to be deleted by the retention manager soon).
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [incubator-pinot] snleee commented on a change in pull request #5728: Add segment lineage based segment selector
Posted by GitBox <gi...@apache.org>.
snleee commented on a change in pull request #5728:
URL: https://github.com/apache/incubator-pinot/pull/5728#discussion_r462991006
##########
File path: pinot-broker/src/main/java/org/apache/pinot/broker/routing/segmentselector/SegmentLineageBasedSegmentSelector.java
##########
@@ -0,0 +1,69 @@
+/**
+ * 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.Collections;
+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;
+
+
+public class SegmentLineageBasedSegmentSelector {
+ private final String _tableNameWithType;
+ private final ZkHelixPropertyStore<ZNRecord> _propertyStore;
+
+ private volatile Set<String> _segmentsToRemove;
+
+ public SegmentLineageBasedSegmentSelector(String tableNameWithType, ZkHelixPropertyStore<ZNRecord> propertyStore) {
+ _tableNameWithType = tableNameWithType;
+ _propertyStore = propertyStore;
+ }
+
+ public void init() {
+ onExternalViewChange();
+ }
+
+ public void onExternalViewChange() {
+ // Fetch segment lineage
+ 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) {
Review comment:
I fixed the if check like the following:
```
if (lineageEntry.getState() == LineageEntryState.COMPLETED && onlineSegments
.containsAll(lineageEntry.getSegmentsTo())) {
segmentsToRemove.addAll(lineageEntry.getSegmentsFrom());
}
```
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [incubator-pinot] snleee commented on pull request #5728: Add segment lineage based segment selector
Posted by GitBox <gi...@apache.org>.
snleee commented on pull request #5728:
URL: https://github.com/apache/incubator-pinot/pull/5728#issuecomment-666903009
#5728
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org
[GitHub] [incubator-pinot] snleee commented on pull request #5728: Add segment lineage based segment selector
Posted by GitBox <gi...@apache.org>.
snleee commented on pull request #5728:
URL: https://github.com/apache/incubator-pinot/pull/5728#issuecomment-662470702
Selection algorithm is explained at https://docs.google.com/document/d/1-AKCfXNXdoNjFIvJ87wjWwFM_38gS0NCwFrIYjYsqp8/edit#heading=h.jfv7jhocokm4
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org