Class HelixBaseRoutingRepository

  • All Implemented Interfaces:
    OnlineInstanceFinder, RoutingDataRepository, VeniceResource, org.apache.helix.api.listeners.ControllerChangeListener, org.apache.helix.api.listeners.RoutingTableChangeListener
    Direct Known Subclasses:
    HelixCustomizedViewOfflinePushRepository, HelixExternalViewRepository

    public abstract class HelixBaseRoutingRepository
    extends java.lang.Object
    implements RoutingDataRepository, org.apache.helix.api.listeners.ControllerChangeListener, org.apache.helix.api.listeners.RoutingTableChangeListener
    Get routing data from Helix and convert it to our Venice partition and replica objects.

    Although Helix RoutingTableProvider already cached routing data in local memory. But it only gets data from /$cluster/EXTERNALVIEW, /$cluster/CONFIGS/PARTICIPANTS, /$cluster/CUSTOMIZEDVIEW. Two parts of data are missed: Additional data in /$cluster/LIVEINSTANCES and partition number in /$cluster/IDEALSTATES. So we cached Venice partitions and instances here to include all of them and also convert them from Helix data structure to Venice data structure.

    As this repository is used by Router, so here only cached the online instance at first. If Venice needs some more instances in other state, could add them in the further.

    • Field Detail

      • manager

        protected final SafeHelixManager manager
        Manager used to communicate with Helix.
      • keyBuilder

        protected final org.apache.helix.PropertyKey.Builder keyBuilder
        Builder used to build the data path to access Helix internal data.
      • liveInstancesMapLock

        protected final java.util.concurrent.locks.Lock liveInstancesMapLock
      • liveInstancesMap

        protected java.util.Map<java.lang.String,​Instance> liveInstancesMap
      • dataSource

        protected final java.util.Map<org.apache.helix.PropertyType,​java.util.List<java.lang.String>> dataSource
    • Constructor Detail

      • HelixBaseRoutingRepository

        public HelixBaseRoutingRepository​(SafeHelixManager manager)
    • Method Detail

      • refresh

        public void refresh()
        This method is used to add listener after HelixManager being connected. Otherwise, it will met error because adding listener before connecting.
        Specified by:
        refresh in interface VeniceResource
      • getAllInstances

        public java.util.Map<ExecutionStatus,​java.util.List<Instance>> getAllInstances​(java.lang.String kafkaTopic,
                                                                                             int partitionId)
        This function is mainly used in VeniceVersionFinder#anyOfflinePartitions() when there is no online replica for a specific partition, and it calls this function to get the partition assignment info for error msg. It's valid case that there is no partition assignment for a specific partition and we return EMPTY_MAP.
        Specified by:
        getAllInstances in interface OnlineInstanceFinder
        Returns:
        a map that has HelixState as the key and list of instances as the value
      • getNumberOfPartitions

        public int getNumberOfPartitions​(@Nonnull
                                         java.lang.String resourceName)
        Description copied from interface: OnlineInstanceFinder
        Query number of partition in given kafka topic.
        Specified by:
        getNumberOfPartitions in interface OnlineInstanceFinder
        Parameters:
        resourceName - Name of the resource.
        Returns:
        The number of partition of the resource from local memory cache.
      • onControllerChange

        public void onControllerChange​(org.apache.helix.NotificationContext changeContext)
        Specified by:
        onControllerChange in interface org.apache.helix.api.listeners.ControllerChangeListener
      • convertLiveInstances

        protected java.util.Map<java.lang.String,​Instance> convertLiveInstances​(java.util.Collection<org.apache.helix.model.LiveInstance> helixLiveInstances)
      • onRoutingTableChange

        public void onRoutingTableChange​(org.apache.helix.spectator.RoutingTableSnapshot routingTableSnapshot,
                                         java.lang.Object context)
        Specified by:
        onRoutingTableChange in interface org.apache.helix.api.listeners.RoutingTableChangeListener
      • onExternalViewDataChange

        protected abstract void onExternalViewDataChange​(org.apache.helix.spectator.RoutingTableSnapshot routingTableSnapshot)
      • onCustomizedViewDataChange

        protected abstract void onCustomizedViewDataChange​(org.apache.helix.spectator.RoutingTableSnapshot routingTableSnapshot)
      • getLeaderInstance

        public Instance getLeaderInstance​(java.lang.String resourceName,
                                          int partition)
        Used by tests only. Evaluate carefully if there is an intent to start using this in the main code.
        Specified by:
        getLeaderInstance in interface RoutingDataRepository
        Returns:
        the leader Instance or null if there isn't one