Package com.github.ambry.clustermap
Class DynamicClusterChangeHandler
- java.lang.Object
-
- com.github.ambry.clustermap.DynamicClusterChangeHandler
-
- All Implemented Interfaces:
ClusterChangeHandler
,DataNodeConfigChangeListener
,org.apache.helix.api.listeners.IdealStateChangeListener
,org.apache.helix.api.listeners.LiveInstanceChangeListener
,org.apache.helix.api.listeners.RoutingTableChangeListener
public class DynamicClusterChangeHandler extends java.lang.Object
A more dynamic implementation ofHelixClusterChangeHandler
which supports adding new nodes/partitions at runtime. It is also able to absorb replica location changes in cluster.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Default Methods Modifier and Type Method Description java.util.List<com.github.ambry.clustermap.AmbryDataNode>
getAllDataNodes()
com.github.ambry.clustermap.AmbryDataNode
getDataNode(java.lang.String instanceName)
Get ambry data node associated with given instance name.java.util.Map<com.github.ambry.clustermap.AmbryDataNode,java.util.Set<com.github.ambry.clustermap.AmbryDisk>>
getDataNodeToDisksMap()
java.util.Set<com.github.ambry.clustermap.AmbryDisk>
getDisks(com.github.ambry.clustermap.AmbryDataNode ambryDataNode)
Get all disks belong to given data node.long
getErrorCount()
java.util.Map<java.lang.String,java.lang.String>
getPartitionToResourceMap()
AmbryReplica
getReplicaId(com.github.ambry.clustermap.AmbryDataNode ambryDataNode, java.lang.String partitionName)
GetAmbryReplica
on given node that belongs to specified partition.java.util.List<AmbryReplica>
getReplicaIds(com.github.ambry.clustermap.AmbryDataNode ambryDataNode)
Get all replicas on given node.default java.util.stream.Stream<AmbryReplica>
getReplicaIdsByState(AmbryPartition partition, com.github.ambry.clustermap.ReplicaState state)
Get replicas of given partition from this datacenter that are in required stateorg.apache.helix.spectator.RoutingTableSnapshot
getRoutingTableSnapshot()
void
onDataNodeConfigChange(java.lang.Iterable<com.github.ambry.clustermap.DataNodeConfig> configs)
Handle anyDataNodeConfig
related change in current datacenter.void
onIdealStateChange(java.util.List<org.apache.helix.model.IdealState> idealState, org.apache.helix.NotificationContext changeContext)
Triggered whenever the IdealState in current data center has changed (for now, it is usually updated by Helix Bootstrap tool).void
onLiveInstanceChange(java.util.List<org.apache.helix.model.LiveInstance> liveInstances, org.apache.helix.NotificationContext changeContext)
Triggered whenever there is a change in the list of live instances.void
onRoutingTableChange(org.apache.helix.spectator.RoutingTableSnapshot routingTableSnapshot, java.lang.Object context)
Triggered whenever the state of replica in cluster has changed.void
registerClusterMapListener(com.github.ambry.clustermap.ClusterMapChangeListener clusterMapChangeListener)
Register a listener of cluster map for any changes.void
setRoutingTableSnapshot(org.apache.helix.spectator.RoutingTableSnapshot routingTableSnapshot)
void
waitForInitNotification()
-
-
-
Method Detail
-
onDataNodeConfigChange
public void onDataNodeConfigChange(java.lang.Iterable<com.github.ambry.clustermap.DataNodeConfig> configs)
Handle anyDataNodeConfig
related change in current datacenter. Several events will trigger instance config change: (1) replica's seal or stop state has changed; (2) new node or new partition is added; (3) new replica is added to existing node; (4) old replica is removed from existing node; (5) data node is deleted from cluster. For now,DynamicClusterChangeHandler
supports (1)~(4). We may consider supporting (5) in the future. (The ZNode path of instance config in Helix is [AmbryClusterName]/CONFIGS/PARTICIPANT/[hostname_port])- Specified by:
onDataNodeConfigChange
in interfaceDataNodeConfigChangeListener
- Parameters:
configs
- all theDataNodeConfig
(s) in current data center. (Note that PreFetch is enabled by default in Helix, which means all instance configs under "participants" ZNode will be sent to this method)
-
onIdealStateChange
public void onIdealStateChange(java.util.List<org.apache.helix.model.IdealState> idealState, org.apache.helix.NotificationContext changeContext)
Triggered whenever the IdealState in current data center has changed (for now, it is usually updated by Helix Bootstrap tool).- Specified by:
onIdealStateChange
in interfaceorg.apache.helix.api.listeners.IdealStateChangeListener
- Parameters:
idealState
- a list ofIdealState
that specifies ideal location of replicas.changeContext
- theNotificationContext
associated.
-
onLiveInstanceChange
public void onLiveInstanceChange(java.util.List<org.apache.helix.model.LiveInstance> liveInstances, org.apache.helix.NotificationContext changeContext)
Triggered whenever there is a change in the list of live instances.- Specified by:
onLiveInstanceChange
in interfaceorg.apache.helix.api.listeners.LiveInstanceChangeListener
- Parameters:
liveInstances
- the list of all live instances (not a change set) at the time of this call.changeContext
- theNotificationContext
associated.
-
onRoutingTableChange
public void onRoutingTableChange(org.apache.helix.spectator.RoutingTableSnapshot routingTableSnapshot, java.lang.Object context)
Triggered whenever the state of replica in cluster has changed. The snapshot contains up-to-date state of all resources(replicas) in this data center.- Specified by:
onRoutingTableChange
in interfaceorg.apache.helix.api.listeners.RoutingTableChangeListener
- Parameters:
routingTableSnapshot
- a snapshot of routing table for this data center.context
- additional context associated with this change.
-
setRoutingTableSnapshot
public void setRoutingTableSnapshot(org.apache.helix.spectator.RoutingTableSnapshot routingTableSnapshot)
-
getRoutingTableSnapshot
public org.apache.helix.spectator.RoutingTableSnapshot getRoutingTableSnapshot()
-
getDataNodeToDisksMap
public java.util.Map<com.github.ambry.clustermap.AmbryDataNode,java.util.Set<com.github.ambry.clustermap.AmbryDisk>> getDataNodeToDisksMap()
- Specified by:
getDataNodeToDisksMap
in interfaceClusterChangeHandler
- Returns:
- a map from ambry data node to its disks.
-
getDataNode
public com.github.ambry.clustermap.AmbryDataNode getDataNode(java.lang.String instanceName)
Description copied from interface:ClusterChangeHandler
Get ambry data node associated with given instance name.- Specified by:
getDataNode
in interfaceClusterChangeHandler
- Parameters:
instanceName
- associated with ambry node.- Returns:
- requested
AmbryDataNode
-
getReplicaId
public AmbryReplica getReplicaId(com.github.ambry.clustermap.AmbryDataNode ambryDataNode, java.lang.String partitionName)
Description copied from interface:ClusterChangeHandler
GetAmbryReplica
on given node that belongs to specified partition.- Specified by:
getReplicaId
in interfaceClusterChangeHandler
- Parameters:
ambryDataNode
- the node on which the replica resides.partitionName
- name of partition which the replica belongs to.- Returns:
- requested
AmbryReplica
-
getReplicaIds
public java.util.List<AmbryReplica> getReplicaIds(com.github.ambry.clustermap.AmbryDataNode ambryDataNode)
Description copied from interface:ClusterChangeHandler
Get all replicas on given node.- Specified by:
getReplicaIds
in interfaceClusterChangeHandler
- Parameters:
ambryDataNode
- the node on which replicas reside- Returns:
- a list of
AmbryReplica
on given node.
-
getAllDataNodes
public java.util.List<com.github.ambry.clustermap.AmbryDataNode> getAllDataNodes()
- Specified by:
getAllDataNodes
in interfaceClusterChangeHandler
- Returns:
- all
AmbryDataNode
tracked by thisClusterChangeHandler
-
getDisks
public java.util.Set<com.github.ambry.clustermap.AmbryDisk> getDisks(com.github.ambry.clustermap.AmbryDataNode ambryDataNode)
Description copied from interface:ClusterChangeHandler
Get all disks belong to given data node.- Specified by:
getDisks
in interfaceClusterChangeHandler
- Parameters:
ambryDataNode
- the node which the disks belong to.- Returns:
- a set of
AmbryDisk
that belongs to given node.
-
getPartitionToResourceMap
public java.util.Map<java.lang.String,java.lang.String> getPartitionToResourceMap()
- Specified by:
getPartitionToResourceMap
in interfaceClusterChangeHandler
- Returns:
- a map from partition name to its corresponding resource name in this
ClusterChangeHandler
.
-
getErrorCount
public long getErrorCount()
- Specified by:
getErrorCount
in interfaceClusterChangeHandler
- Returns:
- number of errors occurred during handling cluster changes.
-
waitForInitNotification
public void waitForInitNotification() throws java.lang.InterruptedException
- Throws:
java.lang.InterruptedException
-
registerClusterMapListener
public void registerClusterMapListener(com.github.ambry.clustermap.ClusterMapChangeListener clusterMapChangeListener)
Description copied from interface:ClusterChangeHandler
Register a listener of cluster map for any changes.- Specified by:
registerClusterMapListener
in interfaceClusterChangeHandler
- Parameters:
clusterMapChangeListener
- theClusterMapChangeListener
to add.
-
getReplicaIdsByState
public default java.util.stream.Stream<AmbryReplica> getReplicaIdsByState(AmbryPartition partition, com.github.ambry.clustermap.ReplicaState state)
Description copied from interface:ClusterChangeHandler
Get replicas of given partition from this datacenter that are in required state- Specified by:
getReplicaIdsByState
in interfaceClusterChangeHandler
- Parameters:
partition
- thePartitionId
for which to get the list of replicas.state
-ReplicaState
associated with replica- Returns:
- the
ReplicaId
s satisfying requirements.
-
-