Package com.linkedin.venice.helix
Class HelixBaseRoutingRepository
java.lang.Object
com.linkedin.venice.helix.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 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.
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.linkedin.venice.meta.RoutingDataRepository
RoutingDataRepository.RoutingDataChangedListener -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.apache.helix.PropertyKey.BuilderBuilder used to build the data path to access Helix internal data.protected final ListenerManager<RoutingDataRepository.RoutingDataChangedListener>protected final Lockprotected final SafeHelixManagerManager used to communicate with Helix.protected ResourceAssignment -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()booleancontainsKafkaTopic(String kafkaTopic) Whether this repository contains routing data for given kafka topic or not.convertLiveInstances(Collection<org.apache.helix.model.LiveInstance> helixLiveInstances) booleandoesResourcesExistInIdealState(String resource) Whether the resources names exist in ideal state or not.getAllInstances(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.Query the leader controller of current cluster.longTimestamp in milliseconds of the last time leader controller changed.getLeaderInstance(String resourceName, int partition) Used by tests only.intgetNumberOfPartitions(String resourceName) Query number of partition in given kafka topic.getPartitionAssignments(String resourceName) Query all partitions allocations that belong to given kafka topic.getReadyToServeInstances(PartitionAssignment partitionAssignment, int partitionId) Get ready to serve instances from local memory.getReadyToServeInstances(String kafkaTopic, int partitionId) Get instances from local memory.getWorkingInstances(String kafkaTopic, int partitionId) Get instances from local memory.booleanisLiveInstance(String instanceId) voidonControllerChange(org.apache.helix.NotificationContext changeContext) protected abstract voidonCustomizedViewDataChange(org.apache.helix.spectator.RoutingTableSnapshot routingTableSnapshot) protected abstract voidonExternalViewDataChange(org.apache.helix.spectator.RoutingTableSnapshot routingTableSnapshot) voidonRoutingTableChange(org.apache.helix.spectator.RoutingTableSnapshot routingTableSnapshot, Object context) voidrefresh()This method is used to add listener after HelixManager being connected.voidsubscribeRoutingDataChange(String kafkaTopic, RoutingDataRepository.RoutingDataChangedListener listener) Add a listener on kafka topic to get the notification when routing data is changed.voidunSubscribeRoutingDataChange(String kafkaTopic, RoutingDataRepository.RoutingDataChangedListener listener) Remove the listener for given kafka topic.
-
Field Details
-
manager
Manager used to communicate with Helix. -
keyBuilder
protected final org.apache.helix.PropertyKey.Builder keyBuilderBuilder used to build the data path to access Helix internal data. -
resourceAssignment
-
listenerManager
-
liveInstancesMapLock
-
liveInstancesMap
-
dataSource
-
-
Constructor Details
-
HelixBaseRoutingRepository
-
-
Method Details
-
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:
refreshin interfaceVeniceResource
-
clear
public void clear()- Specified by:
clearin interfaceVeniceResource
-
getWorkingInstances
Get instances from local memory. All instances are inHelixState.LEADERorHelixState.STANDBYstate.- Specified by:
getWorkingInstancesin interfaceOnlineInstanceFinder
-
getReadyToServeInstances
Get instances from local memory. All instances are inExecutionStatus.COMPLETEDstate.- Specified by:
getReadyToServeInstancesin interfaceOnlineInstanceFinder
-
getReadyToServeInstances
public List<Instance> getReadyToServeInstances(PartitionAssignment partitionAssignment, int partitionId) Get ready to serve instances from local memory. All instances are inExecutionStatus.COMPLETEDstate.- Specified by:
getReadyToServeInstancesin interfaceOnlineInstanceFinder
-
getAllInstances
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:
getAllInstancesin interfaceOnlineInstanceFinder- Returns:
- a map that has
HelixStateas the key and list of instances as the value
-
getPartitionAssignments
Description copied from interface:RoutingDataRepositoryQuery all partitions allocations that belong to given kafka topic. The instances in returned allocations are ready to serve OR being bootstrap.- Specified by:
getPartitionAssignmentsin interfaceRoutingDataRepository- Parameters:
resourceName- Name of the resource.- Returns:
PartitionAssignmentof the resource from local memory.
-
getNumberOfPartitions
Description copied from interface:OnlineInstanceFinderQuery number of partition in given kafka topic.- Specified by:
getNumberOfPartitionsin interfaceOnlineInstanceFinder- Parameters:
resourceName- Name of the resource.- Returns:
- The number of partition of the resource from local memory cache.
-
containsKafkaTopic
Description copied from interface:RoutingDataRepositoryWhether this repository contains routing data for given kafka topic or not.- Specified by:
containsKafkaTopicin interfaceRoutingDataRepository
-
getLeaderController
Description copied from interface:RoutingDataRepositoryQuery the leader controller of current cluster.- Specified by:
getLeaderControllerin interfaceRoutingDataRepository
-
subscribeRoutingDataChange
public void subscribeRoutingDataChange(String kafkaTopic, RoutingDataRepository.RoutingDataChangedListener listener) Description copied from interface:RoutingDataRepositoryAdd a listener on kafka topic to get the notification when routing data is changed.- Specified by:
subscribeRoutingDataChangein interfaceRoutingDataRepository
-
unSubscribeRoutingDataChange
public void unSubscribeRoutingDataChange(String kafkaTopic, RoutingDataRepository.RoutingDataChangedListener listener) Description copied from interface:RoutingDataRepositoryRemove the listener for given kafka topic.- Specified by:
unSubscribeRoutingDataChangein interfaceRoutingDataRepository
-
isLiveInstance
- Specified by:
isLiveInstancein interfaceRoutingDataRepository
-
getLeaderControllerChangeTimeMs
public long getLeaderControllerChangeTimeMs()Description copied from interface:RoutingDataRepositoryTimestamp in milliseconds of the last time leader controller changed.- Specified by:
getLeaderControllerChangeTimeMsin interfaceRoutingDataRepository
-
onControllerChange
public void onControllerChange(org.apache.helix.NotificationContext changeContext) - Specified by:
onControllerChangein interfaceorg.apache.helix.api.listeners.ControllerChangeListener
-
getResourceAssignment
- Specified by:
getResourceAssignmentin interfaceRoutingDataRepository
-
doesResourcesExistInIdealState
Description copied from interface:RoutingDataRepositoryWhether the resources names exist in ideal state or not.- Specified by:
doesResourcesExistInIdealStatein interfaceRoutingDataRepository
-
convertLiveInstances
protected Map<String,Instance> convertLiveInstances(Collection<org.apache.helix.model.LiveInstance> helixLiveInstances) -
onRoutingTableChange
public void onRoutingTableChange(org.apache.helix.spectator.RoutingTableSnapshot routingTableSnapshot, Object context) - Specified by:
onRoutingTableChangein interfaceorg.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
Used by tests only. Evaluate carefully if there is an intent to start using this in the main code.- Specified by:
getLeaderInstancein interfaceRoutingDataRepository- Returns:
- the leader
Instanceor null if there isn't one
-