Package com.github.ambry.clustermap
Interface ClusterMap
-
- All Superinterfaces:
java.lang.AutoCloseable
public interface ClusterMap extends java.lang.AutoCloseable
-
-
Field Summary
Fields Modifier and Type Field Description static byte
UNKNOWN_DATACENTER_ID
Indicates that a blob ID does not have a datacenter ID
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
close()
Close the cluster map.java.util.List<? extends PartitionId>
getAllPartitionIds(java.lang.String partitionClass)
Gets a list of all partitions in the cluster.ReplicaId
getBootstrapReplica(java.lang.String partitionIdStr, DataNodeId dataNodeId)
Attempt to get a bootstrap replica of certain partition that is supposed to be added onto specified data node.java.lang.String
getDatacenterName(byte id)
Gets the name of the datacenter from the ID.DataNodeId
getDataNodeId(java.lang.String hostname, int port)
Gets a specific DataNodeId by its hostname and port.java.util.List<? extends DataNodeId>
getDataNodeIds()
Gets the DataNodeIds for all nodes in the cluster.byte
getLocalDatacenterId()
Gets the id of the local datacenter.com.codahale.metrics.MetricRegistry
getMetricRegistry()
Gets the MetricRegistry that other users of the ClusterMap ought to use for metrics.PartitionId
getPartitionIdFromStream(java.io.InputStream stream)
Gets PartitionId based on serialized bytes.PartitionId
getRandomWritablePartition(java.lang.String partitionClass, java.util.List<PartitionId> partitionsToExclude)
Get a writable partition chosen at random that belongs to given partition class.java.util.List<? extends ReplicaId>
getReplicaIds(DataNodeId dataNodeId)
Gets the ReplicaIds stored on the specified DataNodeId.org.json.JSONObject
getSnapshot()
java.util.List<? extends PartitionId>
getWritablePartitionIds(java.lang.String partitionClass)
Gets a list of partitions that are available for writes.boolean
hasDatacenter(java.lang.String datacenterName)
Checks if datacenter name corresponds to some datacenter in this cluster map's hardware layout.void
onReplicaEvent(ReplicaId replicaId, ReplicaEventType event)
Performs the required action for a replica related event.void
registerClusterMapListener(ClusterMapChangeListener clusterMapChangeListener)
Register a listener of cluster map for any changes.
-
-
-
Field Detail
-
UNKNOWN_DATACENTER_ID
static final byte UNKNOWN_DATACENTER_ID
Indicates that a blob ID does not have a datacenter ID- See Also:
- Constant Field Values
-
-
Method Detail
-
getPartitionIdFromStream
PartitionId getPartitionIdFromStream(java.io.InputStream stream) throws java.io.IOException
Gets PartitionId based on serialized bytes.- Parameters:
stream
-InputStream
that contains the serialized partition bytes- Returns:
- deserialized PartitionId
- Throws:
java.io.IOException
-
getWritablePartitionIds
java.util.List<? extends PartitionId> getWritablePartitionIds(java.lang.String partitionClass)
Gets a list of partitions that are available for writes. Gets a mutable shallow copy of the list of the partitions that are available for writes- Parameters:
partitionClass
- the partition class whose writable partitions are required. Can benull
- Returns:
- a list of all writable partitions belonging to the partition class (or all writable partitions if
partitionClass
isnull
)
-
getRandomWritablePartition
PartitionId getRandomWritablePartition(java.lang.String partitionClass, java.util.List<PartitionId> partitionsToExclude)
Get a writable partition chosen at random that belongs to given partition class.- Parameters:
partitionClass
- the partition class whose writable partitions are required. Can benull
partitionsToExclude
- list of partitions that shouldn't be considered as a possible partition returned- Returns:
- chosen random partition. Can be
null
-
getAllPartitionIds
java.util.List<? extends PartitionId> getAllPartitionIds(java.lang.String partitionClass)
Gets a list of all partitions in the cluster. Gets a mutable shallow copy of the list of all partitions.- Parameters:
partitionClass
- the partition class whose partitions are required. Can benull
- Returns:
- a list of all partitions belonging to the partition class (or all partitions if
partitionClass
isnull
)
-
hasDatacenter
boolean hasDatacenter(java.lang.String datacenterName)
Checks if datacenter name corresponds to some datacenter in this cluster map's hardware layout.- Parameters:
datacenterName
- name of datacenter- Returns:
- true if datacenter with datacenterName is in the hardware layout of this cluster map.
-
getLocalDatacenterId
byte getLocalDatacenterId()
Gets the id of the local datacenter.- Returns:
- The id of the local datacenter.
-
getDatacenterName
java.lang.String getDatacenterName(byte id)
Gets the name of the datacenter from the ID.- Parameters:
id
- the ID of the datacenter- Returns:
- name of the datacenter from the ID or null if not found.
-
getDataNodeId
DataNodeId getDataNodeId(java.lang.String hostname, int port)
Gets a specific DataNodeId by its hostname and port.- Parameters:
hostname
- of the DataNodeIdport
- of the DataNodeId- Returns:
- DataNodeId for this hostname and port, or
null
if the hostname and port does not match a node in the cluster.
-
getReplicaIds
java.util.List<? extends ReplicaId> getReplicaIds(DataNodeId dataNodeId)
Gets the ReplicaIds stored on the specified DataNodeId.- Parameters:
dataNodeId
- theDataNodeId
whose replicas are to be returned.- Returns:
- list of ReplicaIds on the specified dataNodeId
-
getDataNodeIds
java.util.List<? extends DataNodeId> getDataNodeIds()
Gets the DataNodeIds for all nodes in the cluster.- Returns:
- list of all DataNodeIds
-
getMetricRegistry
com.codahale.metrics.MetricRegistry getMetricRegistry()
Gets the MetricRegistry that other users of the ClusterMap ought to use for metrics.- Returns:
- MetricRegistry
-
onReplicaEvent
void onReplicaEvent(ReplicaId replicaId, ReplicaEventType event)
Performs the required action for a replica related event.
-
getSnapshot
org.json.JSONObject getSnapshot()
- Returns:
- a snapshot which includes information that the implementation considers relevant. Must necessarily contain information about nodes, partitions and replicas from each datacenter
-
getBootstrapReplica
ReplicaId getBootstrapReplica(java.lang.String partitionIdStr, DataNodeId dataNodeId)
Attempt to get a bootstrap replica of certain partition that is supposed to be added onto specified data node. This method is designed to fetch detailed infos about bootstrap replica and create an instance of this replica. The purpose is to support dynamically adding new replica to specified data node.- Parameters:
partitionIdStr
- the partition id stringdataNodeId
- theDataNodeId
on which bootstrap replica is placed- Returns:
ReplicaId
if there is a new replica satisfying given partition and data node.null
otherwise.
-
registerClusterMapListener
void registerClusterMapListener(ClusterMapChangeListener clusterMapChangeListener)
Register a listener of cluster map for any changes.- Parameters:
clusterMapChangeListener
- theClusterMapChangeListener
to add.
-
close
void close()
Close the cluster map. Any cleanups should be done in this call.- Specified by:
close
in interfacejava.lang.AutoCloseable
-
-