Class 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.
    
     Note that new segments won't be used to exclude instances from serving when the segment is unavailable.
     
    • Constructor Detail

      • StrictReplicaGroupInstanceSelector

        public StrictReplicaGroupInstanceSelector​(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: InstanceSelector
        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 the SegmentPreSelector). Should be called only once before calling other methods.
        Specified by:
        init in interface InstanceSelector
      • 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 segmentToEnabledInstancesMap and unavailableSegments based on the cached states.

        Specified by:
        onInstancesChange in interface InstanceSelector
      • 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 the SegmentPreSelector).

        Updates the cached maps (segmentToOnlineInstancesMap, segmentToOfflineInstancesMap and instanceToSegmentsMap) and re-calculates segmentToEnabledInstancesMap and unavailableSegments based on the cached states.

        Specified by:
        onAssignmentChange in interface InstanceSelector
      • select

        public InstanceSelector.SelectionResult select​(org.apache.pinot.common.request.BrokerRequest brokerRequest,
                                                       List<String> segments,
                                                       long requestId)
        Description copied from interface: InstanceSelector
        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).
        Specified by:
        select in interface InstanceSelector
        Parameters:
        brokerRequest - BrokerRequest for the query
        segments - segments for which instance needs to be selected
        requestId - requestId generated by the Broker for a query
        Returns:
        instance of SelectionResult which describes the instance to pick for a given segment