Class BalancedInstanceSelector
- java.lang.Object
-
- org.apache.pinot.broker.routing.instanceselector.BalancedInstanceSelector
-
- All Implemented Interfaces:
InstanceSelector
public class BalancedInstanceSelector extends Object
Instance selector to balance the number of segments served by each selected server instance.If AdaptiveServerSelection is enabled, the request is routed to the best available server for a segment when it is processed below. This is a best effort approach in distributing the query to all available servers. If some servers are performing poorly, they might not end up being picked for any of the segments. For example, there's a query for Segments 1 (Seg1), 2 (Seg2) and Seg3). The servers are S1, S2, S3. The algorithm works as follows: Step1: Process seg1. Fetch server rankings. Pick the best server. Step2: Process seg2. Fetch server rankings (could have changed or not since Step 1). Pick the best server. Step3: Process seg3. Fetch server rankings (could have changed or not since Step 2). Pick the best server.
If AdaptiveServerSelection is disabled, the selection algorithm will always evenly distribute the traffic to all replicas of each segment, and will try to select different replica id for each segment. The algorithm is very light-weight and will do best effort to balance the number of segments served by each selected server instance.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.pinot.broker.routing.instanceselector.InstanceSelector
InstanceSelector.SelectionResult
-
-
Field Summary
-
Fields inherited from interface org.apache.pinot.broker.routing.instanceselector.InstanceSelector
NEW_SEGMENT_EXPIRATION_MILLIS
-
-
Constructor Summary
Constructors Constructor Description BalancedInstanceSelector(String tableNameWithType, org.apache.helix.store.zk.ZkHelixPropertyStore<org.apache.helix.zookeeper.datamodel.ZNRecord> propertyStore, org.apache.pinot.common.metrics.BrokerMetrics brokerMetrics, AdaptiveServerSelector adaptiveServerSelector, Clock clock)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Set<String>getServingInstances()Returns the enabled server instances currently serving the table.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).
-
-
-
Constructor Detail
-
BalancedInstanceSelector
public BalancedInstanceSelector(String tableNameWithType, org.apache.helix.store.zk.ZkHelixPropertyStore<org.apache.helix.zookeeper.datamodel.ZNRecord> propertyStore, org.apache.pinot.common.metrics.BrokerMetrics brokerMetrics, @Nullable AdaptiveServerSelector adaptiveServerSelector, Clock clock)
-
-
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
-
getServingInstances
public Set<String> getServingInstances()
Description copied from interface:InstanceSelectorReturns the enabled server instances currently serving the table.- Specified by:
getServingInstancesin interfaceInstanceSelector
-
-