Class StrictReplicaGroupInstanceSelector
- java.lang.Object
-
- org.apache.pinot.broker.routing.instanceselector.ReplicaGroupInstanceSelector
-
- org.apache.pinot.broker.routing.instanceselector.StrictReplicaGroupInstanceSelector
-
- All Implemented Interfaces:
InstanceSelector
public class StrictReplicaGroupInstanceSelector extends ReplicaGroupInstanceSelector
Instance selector for strict replica-group routing strategy.The strict replica-group routing strategy always routes the query to the instances within the same replica-group. (Note that the replica-group information is derived from the ideal state of the table, where the instances are sorted alphabetically in the instance state map, so the replica-groups in the instance selector might not match the replica-groups in the instance partitions.) The instances in a replica-group should have all the online segments (segments with ONLINE/CONSUMING instances in the ideal state and selected by the pre-selector) available (ONLINE/CONSUMING in the external view) in order to serve queries. If any segment is unavailable in the replica-group, we mark the whole replica-group down and not serve queries with this replica-group. The selection algorithm is the same as
ReplicaGroupInstanceSelector, and will always evenly distribute the traffic to all replica-groups that have all online segments available. The algorithm relies on the mirror segment assignment from replica-group segment assignment strategy. With mirror segment assignment, any server in one replica-group will always have a corresponding server in other replica-groups that have the same segments assigned. For example, if S1 is a server in replica-group 1, and it has mirror server S2 in replica-group 2 and S3 in replica-group 3. All segments assigned to S1 will also be assigned to S2 and S3. In stable scenario (external view matches ideal state), all segments assigned to S1 will have the same enabled instances of [S1, S2, S3] sorted (in alphabetical order). If we always pick the same index of enabled instances for all segments, only one of S1, S2, S3 will be picked, and all the segments are processed by the same server. In transitioning/error scenario (external view does not match ideal state), if a segment is down on S1, we mark all segments with the same assignment ([S1, S2, S3]) down on S1 to ensure that we always route the segments to the same replica-group.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.pinot.broker.routing.instanceselector.InstanceSelector
InstanceSelector.SelectionResult
-
-
Field Summary
Fields Modifier and Type Field Description protected AdaptiveServerSelector_adaptiveServerSelector
-
Constructor Summary
Constructors Constructor Description StrictReplicaGroupInstanceSelector(String tableNameWithType, org.apache.pinot.common.metrics.BrokerMetrics brokerMetrics, AdaptiveServerSelector adaptiveServerSelector)
-
Method Summary
Modifier and Type Method Description voidinit(Set<String> enabledInstances, org.apache.helix.model.IdealState idealState, org.apache.helix.model.ExternalView externalView, Set<String> onlineSegments)Initializes the instance selector with the enabled instances, ideal state, external view and online segments (segments with ONLINE/CONSUMING instances in the ideal state and pre-selected by theSegmentPreSelector).voidonAssignmentChange(org.apache.helix.model.IdealState idealState, org.apache.helix.model.ExternalView externalView, Set<String> onlineSegments)Processes the segment assignment (ideal state or external view) change based on the given online segments (segments with ONLINE/CONSUMING instances in the ideal state and pre-selected by theSegmentPreSelector).voidonInstancesChange(Set<String> enabledInstances, List<String> changedInstances)Processes the instances change.InstanceSelector.SelectionResultselect(org.apache.pinot.common.request.BrokerRequest brokerRequest, List<String> segments, long requestId)Selects the server instances for the given segments queried by the given broker request, returns a map from segment to selected server instance hosting the segment and a set of unavailable segments (no enabled instance or all enabled instances are in ERROR state).
-
-
-
Field Detail
-
_adaptiveServerSelector
protected final AdaptiveServerSelector _adaptiveServerSelector
-
-
Constructor Detail
-
StrictReplicaGroupInstanceSelector
public StrictReplicaGroupInstanceSelector(String tableNameWithType, org.apache.pinot.common.metrics.BrokerMetrics brokerMetrics, @Nullable AdaptiveServerSelector adaptiveServerSelector)
-
-
Method Detail
-
init
public void init(Set<String> enabledInstances, org.apache.helix.model.IdealState idealState, org.apache.helix.model.ExternalView externalView, Set<String> onlineSegments)
Description copied from interface:InstanceSelectorInitializes the instance selector with the enabled instances, ideal state, external view and online segments (segments with ONLINE/CONSUMING instances in the ideal state and pre-selected by theSegmentPreSelector). Should be called only once before calling other methods.- Specified by:
initin interfaceInstanceSelector
-
onInstancesChange
public void onInstancesChange(Set<String> enabledInstances, List<String> changedInstances)
Processes the instances change. Changed instances are pre-computed based on the current and previous enabled instances only once on the caller side and passed to all the instance selectors.Updates the cached enabled instances and re-calculates
segmentToEnabledInstancesMapandunavailableSegmentsbased on the cached states.- Specified by:
onInstancesChangein interfaceInstanceSelector
-
onAssignmentChange
public void onAssignmentChange(org.apache.helix.model.IdealState idealState, org.apache.helix.model.ExternalView externalView, Set<String> onlineSegments)Processes the segment assignment (ideal state or external view) change based on the given online segments (segments with ONLINE/CONSUMING instances in the ideal state and pre-selected by theSegmentPreSelector).Updates the cached maps (
segmentToOnlineInstancesMap,segmentToOfflineInstancesMapandinstanceToSegmentsMap) and re-calculatessegmentToEnabledInstancesMapandunavailableSegmentsbased on the cached states.- Specified by:
onAssignmentChangein interfaceInstanceSelector
-
select
public InstanceSelector.SelectionResult select(org.apache.pinot.common.request.BrokerRequest brokerRequest, List<String> segments, long requestId)
Description copied from interface:InstanceSelectorSelects the server instances for the given segments queried by the given broker request, returns a map from segment to selected server instance hosting the segment and a set of unavailable segments (no enabled instance or all enabled instances are in ERROR state).- Specified by:
selectin interfaceInstanceSelector- Parameters:
brokerRequest- BrokerRequest for the querysegments- segments for which instance needs to be selectedrequestId- requestId generated by the Broker for a query- Returns:
- instance of SelectionResult which describes the instance to pick for a given segment
-
-