Class HelixClusterManager

  • All Implemented Interfaces:
    com.github.ambry.clustermap.ClusterMap, java.lang.AutoCloseable

    public class HelixClusterManager
    extends java.lang.Object
    implements com.github.ambry.clustermap.ClusterMap
    An implementation of ClusterMap that makes use of Helix to dynamically manage the cluster information.
    See Also:
    http://helix.apache.org
    • Field Summary

      • Fields inherited from interface com.github.ambry.clustermap.ClusterMap

        UNKNOWN_DATACENTER_ID
    • Constructor Summary

      Constructors 
      Constructor Description
      HelixClusterManager​(com.github.ambry.config.ClusterMapConfig clusterMapConfig, java.lang.String instanceName, HelixFactory helixFactory, com.codahale.metrics.MetricRegistry metricRegistry)
      Instantiate a HelixClusterManager.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Disconnect from the HelixManagers associated with each and every datacenter.
      java.util.List<com.github.ambry.clustermap.PartitionId> getAllPartitionIds​(java.lang.String partitionClass)  
      com.github.ambry.clustermap.ReplicaId getBootstrapReplica​(java.lang.String partitionIdStr, com.github.ambry.clustermap.DataNodeId dataNodeId)
      To create bootstrap replica, HelixClusterManager needs to fetch replica info (i.e.
      java.lang.String getDatacenterName​(byte id)  
      com.github.ambry.clustermap.AmbryDataNode getDataNodeId​(java.lang.String hostname, int port)  
      java.util.List<com.github.ambry.clustermap.AmbryDataNode> getDataNodeIds()  
      byte getLocalDatacenterId()  
      com.codahale.metrics.MetricRegistry getMetricRegistry()  
      com.github.ambry.clustermap.PartitionId getPartitionIdFromStream​(java.io.InputStream stream)  
      com.github.ambry.clustermap.PartitionId getRandomWritablePartition​(java.lang.String partitionClass, java.util.List<com.github.ambry.clustermap.PartitionId> partitionsToExclude)  
      java.util.List<AmbryReplica> getReplicaIds​(com.github.ambry.clustermap.DataNodeId dataNodeId)  
      org.json.JSONObject getSnapshot()  
      java.util.List<com.github.ambry.clustermap.PartitionId> getWritablePartitionIds​(java.lang.String partitionClass)  
      boolean hasDatacenter​(java.lang.String datacenterName)  
      void onReplicaEvent​(com.github.ambry.clustermap.ReplicaId replicaId, com.github.ambry.clustermap.ReplicaEventType event)  
      void registerClusterMapListener​(com.github.ambry.clustermap.ClusterMapChangeListener clusterMapChangeListener)  
      • Methods inherited from class java.lang.Object

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

      • HelixClusterManager

        public HelixClusterManager​(com.github.ambry.config.ClusterMapConfig clusterMapConfig,
                                   java.lang.String instanceName,
                                   HelixFactory helixFactory,
                                   com.codahale.metrics.MetricRegistry metricRegistry)
                            throws java.io.IOException
        Instantiate a HelixClusterManager.
        Parameters:
        clusterMapConfig - the ClusterMapConfig associated with this manager.
        instanceName - the String representation of the instance associated with this manager.
        helixFactory - the factory class to construct and get a reference to a HelixManager.
        metricRegistry - the registry of metric instances associated with this manager.
        Throws:
        java.io.IOException - if there is an error in parsing the clusterMapConfig or in connecting with the associated remote Zookeeper services.
    • Method Detail

      • hasDatacenter

        public boolean hasDatacenter​(java.lang.String datacenterName)
        Specified by:
        hasDatacenter in interface com.github.ambry.clustermap.ClusterMap
      • getLocalDatacenterId

        public byte getLocalDatacenterId()
        Specified by:
        getLocalDatacenterId in interface com.github.ambry.clustermap.ClusterMap
      • getDatacenterName

        public java.lang.String getDatacenterName​(byte id)
        Specified by:
        getDatacenterName in interface com.github.ambry.clustermap.ClusterMap
      • getDataNodeId

        public com.github.ambry.clustermap.AmbryDataNode getDataNodeId​(java.lang.String hostname,
                                                                       int port)
        Specified by:
        getDataNodeId in interface com.github.ambry.clustermap.ClusterMap
      • getReplicaIds

        public java.util.List<AmbryReplica> getReplicaIds​(com.github.ambry.clustermap.DataNodeId dataNodeId)
        Specified by:
        getReplicaIds in interface com.github.ambry.clustermap.ClusterMap
      • getDataNodeIds

        public java.util.List<com.github.ambry.clustermap.AmbryDataNode> getDataNodeIds()
        Specified by:
        getDataNodeIds in interface com.github.ambry.clustermap.ClusterMap
      • getMetricRegistry

        public com.codahale.metrics.MetricRegistry getMetricRegistry()
        Specified by:
        getMetricRegistry in interface com.github.ambry.clustermap.ClusterMap
      • onReplicaEvent

        public void onReplicaEvent​(com.github.ambry.clustermap.ReplicaId replicaId,
                                   com.github.ambry.clustermap.ReplicaEventType event)
        Specified by:
        onReplicaEvent in interface com.github.ambry.clustermap.ClusterMap
      • getSnapshot

        public org.json.JSONObject getSnapshot()
        Specified by:
        getSnapshot in interface com.github.ambry.clustermap.ClusterMap
      • getPartitionIdFromStream

        public com.github.ambry.clustermap.PartitionId getPartitionIdFromStream​(java.io.InputStream stream)
                                                                         throws java.io.IOException
        Specified by:
        getPartitionIdFromStream in interface com.github.ambry.clustermap.ClusterMap
        Throws:
        java.io.IOException
      • getWritablePartitionIds

        public java.util.List<com.github.ambry.clustermap.PartitionId> getWritablePartitionIds​(java.lang.String partitionClass)
        Specified by:
        getWritablePartitionIds in interface com.github.ambry.clustermap.ClusterMap
      • getRandomWritablePartition

        public com.github.ambry.clustermap.PartitionId getRandomWritablePartition​(java.lang.String partitionClass,
                                                                                  java.util.List<com.github.ambry.clustermap.PartitionId> partitionsToExclude)
        Specified by:
        getRandomWritablePartition in interface com.github.ambry.clustermap.ClusterMap
      • getAllPartitionIds

        public java.util.List<com.github.ambry.clustermap.PartitionId> getAllPartitionIds​(java.lang.String partitionClass)
        Specified by:
        getAllPartitionIds in interface com.github.ambry.clustermap.ClusterMap
      • getBootstrapReplica

        public com.github.ambry.clustermap.ReplicaId getBootstrapReplica​(java.lang.String partitionIdStr,
                                                                         com.github.ambry.clustermap.DataNodeId dataNodeId)
        To create bootstrap replica, HelixClusterManager needs to fetch replica info (i.e. capacity, mount path) from Helix PropertyStore. This method looks up the ZNode in local datacenter and does some validation. Right now, HelixClusterManager supports getting bootstrap replica of new partition but it doesn't support getting replica residing on hosts that are not present in clustermap. The ZNRecord of REPLICA_ADDITION_ZNODE has following format in mapFields.
         "mapFields": {
             "1": {
                 "replicaCapacityInBytes": 107374182400,
                 "partitionClass": "max-replicas-all-datacenters",
                 "localhost1_17088": "/tmp/c/1",
                 "localhost2_17088": "/tmp/d/1"
             },
             "2": {
                 "replicaCapacityInBytes": 107374182400,
                 "partitionClass": "max-replicas-all-datacenters",
                 "localhost3_17088": "/tmp/e/1"
             }
         }
         
        In above example, two bootstrap replicas of partition[1] will be added to localhost1 and localhost2 respectively. The host name is followed by mount path on which the bootstrap replica should be placed.
        Specified by:
        getBootstrapReplica in interface com.github.ambry.clustermap.ClusterMap
      • registerClusterMapListener

        public void registerClusterMapListener​(com.github.ambry.clustermap.ClusterMapChangeListener clusterMapChangeListener)
        Specified by:
        registerClusterMapListener in interface com.github.ambry.clustermap.ClusterMap
      • close

        public void close()
        Disconnect from the HelixManagers associated with each and every datacenter.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface com.github.ambry.clustermap.ClusterMap