Class SimpleClusterChangeHandler

  • 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 SimpleClusterChangeHandler
    extends java.lang.Object
    An implementation of HelixClusterChangeHandler to register as listener for Helix related changes in each datacenter. This class is also responsible for handling events received.
    • 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)
      Get AmbryReplica 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 state
      org.apache.helix.spectator.RoutingTableSnapshot getRoutingTableSnapshot()  
      void onDataNodeConfigChange​(java.lang.Iterable<com.github.ambry.clustermap.DataNodeConfig> configs)
      Called when there is a relevant update to one or more DataNodeConfigs.
      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()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • onDataNodeConfigChange

        public void onDataNodeConfigChange​(java.lang.Iterable<com.github.ambry.clustermap.DataNodeConfig> configs)
        Description copied from interface: DataNodeConfigChangeListener
        Called when there is a relevant update to one or more DataNodeConfigs.
        Specified by:
        onDataNodeConfigChange in interface DataNodeConfigChangeListener
        Parameters:
        configs - the new or updated configs.
      • onIdealStateChange

        public void onIdealStateChange​(java.util.List<org.apache.helix.model.IdealState> idealState,
                                       org.apache.helix.NotificationContext changeContext)
                                throws java.lang.InterruptedException
        Triggered whenever the IdealState in current data center has changed (for now, it is usually updated by Helix Bootstrap tool).
        Specified by:
        onIdealStateChange in interface org.apache.helix.api.listeners.IdealStateChangeListener
        Parameters:
        idealState - a list of IdealState that specifies ideal location of replicas.
        changeContext - the NotificationContext associated.
        Throws:
        java.lang.InterruptedException
      • 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 interface org.apache.helix.api.listeners.LiveInstanceChangeListener
        Parameters:
        liveInstances - the list of all live instances (not a change set) at the time of this call.
        changeContext - the NotificationContext 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 interface org.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 interface ClusterChangeHandler
        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 interface ClusterChangeHandler
        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
        Get AmbryReplica on given node that belongs to specified partition.
        Specified by:
        getReplicaId in interface ClusterChangeHandler
        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 interface ClusterChangeHandler
        Parameters:
        ambryDataNode - the node on which replicas reside
        Returns:
        a list of AmbryReplica on given node.
      • 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 interface ClusterChangeHandler
        Parameters:
        ambryDataNode - the node which the disks belong to.
        Returns:
        a set of AmbryDisk that belongs to given node.
      • getErrorCount

        public long getErrorCount()
        Specified by:
        getErrorCount in interface ClusterChangeHandler
        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 interface ClusterChangeHandler
        Parameters:
        clusterMapChangeListener - the ClusterMapChangeListener 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 interface ClusterChangeHandler
        Parameters:
        partition - the PartitionId for which to get the list of replicas.
        state - ReplicaState associated with replica
        Returns:
        the ReplicaIds satisfying requirements.