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 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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.linkedin.venice.meta.RoutingDataRepository
RoutingDataRepository.RoutingDataChangedListener
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<org.apache.helix.PropertyType,java.util.List<java.lang.String>>
dataSource
protected org.apache.helix.PropertyKey.Builder
keyBuilder
Builder used to build the data path to access Helix internal data.protected ListenerManager<RoutingDataRepository.RoutingDataChangedListener>
listenerManager
protected java.util.Map<java.lang.String,Instance>
liveInstancesMap
protected java.util.concurrent.locks.Lock
liveInstancesMapLock
protected SafeHelixManager
manager
Manager used to communicate with Helix.protected ResourceAssignment
resourceAssignment
-
Constructor Summary
Constructors Constructor Description HelixBaseRoutingRepository(SafeHelixManager manager)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
clear()
boolean
containsKafkaTopic(java.lang.String kafkaTopic)
Whether this repository contains routing data for given kafka topic or not.protected java.util.Map<java.lang.String,Instance>
convertLiveInstances(java.util.Collection<org.apache.helix.model.LiveInstance> helixLiveInstances)
boolean
doesResourcesExistInIdealState(java.lang.String resource)
Whether the resources names exist in ideal state or not.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.Instance
getLeaderController()
Query the leader controller of current cluster.long
getLeaderControllerChangeTimeMs()
Timestamp in milliseconds of the last time leader controller changed.Instance
getLeaderInstance(java.lang.String resourceName, int partition)
Used by tests only.int
getNumberOfPartitions(java.lang.String resourceName)
Query number of partition in given kafka topic.PartitionAssignment
getPartitionAssignments(java.lang.String resourceName)
Query all partitions allocations that belong to given kafka topic.java.util.List<Instance>
getReadyToServeInstances(PartitionAssignment partitionAssignment, int partitionId)
Get ready to serve instances from local memory.java.util.List<Instance>
getReadyToServeInstances(java.lang.String kafkaTopic, int partitionId)
Get instances from local memory.ResourceAssignment
getResourceAssignment()
java.util.List<Instance>
getWorkingInstances(java.lang.String kafkaTopic, int partitionId)
Get instances from local memory.boolean
isLiveInstance(java.lang.String instanceId)
void
onControllerChange(org.apache.helix.NotificationContext changeContext)
protected abstract void
onCustomizedViewDataChange(org.apache.helix.spectator.RoutingTableSnapshot routingTableSnapshot)
protected abstract void
onExternalViewDataChange(org.apache.helix.spectator.RoutingTableSnapshot routingTableSnapshot)
void
onRoutingTableChange(org.apache.helix.spectator.RoutingTableSnapshot routingTableSnapshot, java.lang.Object context)
void
refresh()
This method is used to add listener after HelixManager being connected.void
subscribeRoutingDataChange(java.lang.String kafkaTopic, RoutingDataRepository.RoutingDataChangedListener listener)
Add a listener on kafka topic to get the notification when routing data is changed.void
unSubscribeRoutingDataChange(java.lang.String kafkaTopic, RoutingDataRepository.RoutingDataChangedListener listener)
Remove the listener for given kafka topic.
-
-
-
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.
-
resourceAssignment
protected ResourceAssignment resourceAssignment
-
listenerManager
protected final ListenerManager<RoutingDataRepository.RoutingDataChangedListener> listenerManager
-
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 interfaceVeniceResource
-
clear
public void clear()
- Specified by:
clear
in interfaceVeniceResource
-
getWorkingInstances
public java.util.List<Instance> getWorkingInstances(java.lang.String kafkaTopic, int partitionId)
Get instances from local memory. All instances are inHelixState.LEADER
orHelixState.STANDBY
state.- Specified by:
getWorkingInstances
in interfaceOnlineInstanceFinder
-
getReadyToServeInstances
public java.util.List<Instance> getReadyToServeInstances(java.lang.String kafkaTopic, int partitionId)
Get instances from local memory. All instances are inExecutionStatus.COMPLETED
state.- Specified by:
getReadyToServeInstances
in interfaceOnlineInstanceFinder
-
getReadyToServeInstances
public java.util.List<Instance> getReadyToServeInstances(PartitionAssignment partitionAssignment, int partitionId)
Get ready to serve instances from local memory. All instances are inExecutionStatus.COMPLETED
state.- Specified by:
getReadyToServeInstances
in interfaceOnlineInstanceFinder
-
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 interfaceOnlineInstanceFinder
- Returns:
- a map that has
HelixState
as the key and list of instances as the value
-
getPartitionAssignments
public PartitionAssignment getPartitionAssignments(@Nonnull java.lang.String resourceName)
Description copied from interface:RoutingDataRepository
Query all partitions allocations that belong to given kafka topic. The instances in returned allocations are ready to serve OR being bootstrap.- Specified by:
getPartitionAssignments
in interfaceRoutingDataRepository
- Parameters:
resourceName
- Name of the resource.- Returns:
PartitionAssignment
of the resource from local memory.
-
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 interfaceOnlineInstanceFinder
- Parameters:
resourceName
- Name of the resource.- Returns:
- The number of partition of the resource from local memory cache.
-
containsKafkaTopic
public boolean containsKafkaTopic(java.lang.String kafkaTopic)
Description copied from interface:RoutingDataRepository
Whether this repository contains routing data for given kafka topic or not.- Specified by:
containsKafkaTopic
in interfaceRoutingDataRepository
-
getLeaderController
public Instance getLeaderController()
Description copied from interface:RoutingDataRepository
Query the leader controller of current cluster.- Specified by:
getLeaderController
in interfaceRoutingDataRepository
-
subscribeRoutingDataChange
public void subscribeRoutingDataChange(java.lang.String kafkaTopic, RoutingDataRepository.RoutingDataChangedListener listener)
Description copied from interface:RoutingDataRepository
Add a listener on kafka topic to get the notification when routing data is changed.- Specified by:
subscribeRoutingDataChange
in interfaceRoutingDataRepository
-
unSubscribeRoutingDataChange
public void unSubscribeRoutingDataChange(java.lang.String kafkaTopic, RoutingDataRepository.RoutingDataChangedListener listener)
Description copied from interface:RoutingDataRepository
Remove the listener for given kafka topic.- Specified by:
unSubscribeRoutingDataChange
in interfaceRoutingDataRepository
-
isLiveInstance
public boolean isLiveInstance(java.lang.String instanceId)
- Specified by:
isLiveInstance
in interfaceRoutingDataRepository
-
getLeaderControllerChangeTimeMs
public long getLeaderControllerChangeTimeMs()
Description copied from interface:RoutingDataRepository
Timestamp in milliseconds of the last time leader controller changed.- Specified by:
getLeaderControllerChangeTimeMs
in interfaceRoutingDataRepository
-
onControllerChange
public void onControllerChange(org.apache.helix.NotificationContext changeContext)
- Specified by:
onControllerChange
in interfaceorg.apache.helix.api.listeners.ControllerChangeListener
-
getResourceAssignment
public ResourceAssignment getResourceAssignment()
- Specified by:
getResourceAssignment
in interfaceRoutingDataRepository
-
doesResourcesExistInIdealState
public boolean doesResourcesExistInIdealState(java.lang.String resource)
Description copied from interface:RoutingDataRepository
Whether the resources names exist in ideal state or not.- Specified by:
doesResourcesExistInIdealState
in interfaceRoutingDataRepository
-
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 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
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 interfaceRoutingDataRepository
- Returns:
- the leader
Instance
or null if there isn't one
-
-