snleee commented on code in PR #10350: URL: https://github.com/apache/pinot/pull/10350#discussion_r1143481613
########## pinot-broker/src/main/java/org/apache/pinot/broker/routing/instanceselector/SegmentInstanceCandidate.java: ########## @@ -0,0 +1,43 @@ +/** + * 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.instanceselector; + +// Represents an instance candidate for segment. Review Comment: We normally use the following convention for the comment for the class ``` /** * comment */ ``` ########## pinot-broker/src/main/java/org/apache/pinot/broker/routing/instanceselector/SegmentState.java: ########## @@ -0,0 +1,95 @@ +/** + * 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.instanceselector; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + + +// Class used to represent the instance state for new segment. Review Comment: Same here ########## pinot-broker/src/main/java/org/apache/pinot/broker/routing/instanceselector/SegmentStateSnapshot.java: ########## @@ -0,0 +1,123 @@ +/** + * 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.instanceselector; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import javax.annotation.Nullable; +import javax.annotation.concurrent.Immutable; +import org.apache.pinot.common.metrics.BrokerMeter; +import org.apache.pinot.common.metrics.BrokerMetrics; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * This class represents a snapshot state of segments used for routing purpose. + * Note that this class is immutable after creation. + * + * For old segments, we return a list of online instances with online flags set to true. + * For old segments without any online instances, we report them as unavailable segments. + * + * For new segments, we return a list of candidate instance with online flags to indicate whether the instance is + * online or not. + * We don't report new segment as unavailable segments because it is valid for new segments to be not online at all. + */ +@Immutable +public class SegmentStateSnapshot { + private static final Logger LOGGER = LoggerFactory.getLogger(SegmentStateSnapshot.class); + + private Map<String, List<SegmentInstanceCandidate>> _segmentCandidates; + private Set<String> _unavailableSegments; + + // Create a segment state snapshot based on some in-memory states to be used for routing. Review Comment: (nit) We also use `/** ... **/` for the comments on the functions. ########## pinot-broker/src/main/java/org/apache/pinot/broker/routing/instanceselector/BaseInstanceSelector.java: ########## @@ -18,69 +18,162 @@ */ package org.apache.pinot.broker.routing.instanceselector; +import java.time.Clock; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.SortedMap; import javax.annotation.Nullable; +import org.apache.helix.AccessOption; import org.apache.helix.model.ExternalView; import org.apache.helix.model.IdealState; +import org.apache.helix.store.zk.ZkHelixPropertyStore; +import org.apache.helix.zookeeper.datamodel.ZNRecord; import org.apache.pinot.broker.routing.adaptiveserverselector.AdaptiveServerSelector; import org.apache.pinot.broker.routing.segmentpreselector.SegmentPreSelector; -import org.apache.pinot.common.metrics.BrokerMeter; +import org.apache.pinot.common.metadata.ZKMetadataProvider; +import org.apache.pinot.common.metadata.segment.SegmentZKMetadata; import org.apache.pinot.common.metrics.BrokerMetrics; import org.apache.pinot.common.request.BrokerRequest; -import org.apache.pinot.common.utils.HashUtil; import org.apache.pinot.spi.utils.CommonConstants.Helix.StateModel.SegmentStateModel; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** - * Base implementation of instance selector which maintains a map from segment to enabled ONLINE/CONSUMING server + * Base implementation of instance selector. Selector maintains a map from segment to enabled ONLINE/CONSUMING server * instances that serves the segment and a set of unavailable segments (no enabled instance or all enabled instances are * in ERROR state). + * <p> + * Special handling of new segment: It is common for new segment to be partially available or not available at all in + * all instances. + * 1) We don't report new segment as unavailable segments. + * 2) To increase query availability, unavailable + * instance for new segment won't be excluded for instance selection. When it is selected, we don't serve the new + * segment. + * <p> + * Definition of new segment: + * 1) Segment created more than 5 minutes ago. + * - If we first see a segment via initialization, we look up segment creation time from zookeeper. + * - If we first see a segment via onAssignmentChange initialization, we use the calling time of onAssignmentChange + * as approximation. + * 2) We retire new segment as old when: + * - The creation time is more than 5 minutes ago + * - Any instance for new segment is in error state + * - External view for segment converges with ideal state. + * + * Note that this implementation means: + * 1) Inconsistent selection of new segments across queries. (some queries will serve new segments and others won't) + * 2) When there is no state update from helix, new segments won't be retired because of the time passing. Review Comment: Let's add the comment about `TODO` to enhance this? Otherwise, ppl will think that this is the expected behavior. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
