org.apache.hadoop.hbase.replication
Class ReplicationPeersZKImpl

java.lang.Object
  extended by org.apache.hadoop.hbase.replication.ReplicationStateZKBase
      extended by org.apache.hadoop.hbase.replication.ReplicationPeersZKImpl
All Implemented Interfaces:
ReplicationPeers

public class ReplicationPeersZKImpl
extends ReplicationStateZKBase
implements ReplicationPeers

This class provides an implementation of the ReplicationPeers interface using Zookeeper. The peers znode contains a list of all peer replication clusters and the current replication state of those clusters. It has one child peer znode for each peer cluster. The peer znode is named with the cluster id provided by the user in the HBase shell. The value of the peer znode contains the peers cluster key provided by the user in the HBase Shell. The cluster key contains a list of zookeeper quorum peers, the client port for the zookeeper quorum, and the base znode for HBase. For example: /hbase/replication/peers/1 [Value: zk1.host.com,zk2.host.com,zk3.host.com:2181:/hbase] /hbase/replication/peers/2 [Value: zk5.host.com,zk6.host.com,zk7.host.com:2181:/hbase] Each of these peer znodes has a child znode that indicates whether or not replication is enabled on that peer cluster. These peer-state znodes do not have child znodes and simply contain a boolean value (i.e. ENABLED or DISABLED). This value is read/maintained by the ReplicationPeer.PeerStateTracker class. For example: /hbase/replication/peers/1/peer-state [Value: ENABLED]


Nested Class Summary
static class ReplicationPeersZKImpl.PeerRegionServerListener
          Tracks changes to the list of region servers in a peer's cluster.
 
Field Summary
 
Fields inherited from class org.apache.hadoop.hbase.replication.ReplicationStateZKBase
abortable, conf, DISABLED_ZNODE_BYTES, ENABLED_ZNODE_BYTES, ourClusterKey, peerStateNodeName, peersZNode, queuesZNode, replicationZNode, zookeeper
 
Constructor Summary
ReplicationPeersZKImpl(ZooKeeperWatcher zk, org.apache.hadoop.conf.Configuration conf, Abortable abortable)
           
 
Method Summary
 void addPeer(String id, String clusterKey)
          Add a new remote slave cluster for replication.
 boolean connectToPeer(String peerId)
          Attempt to connect to a new remote slave cluster.
 void disablePeer(String id)
          Stop the replication to the specified remote slave cluster.
 void disconnectFromPeer(String peerId)
          Disconnect from a remote slave cluster.
 void enablePeer(String id)
          Restart the replication to the specified remote slave cluster.
 Map<String,String> getAllPeerClusterKeys()
          List the cluster keys of all remote slave clusters (whether they are enabled/disabled or connected/disconnected).
 List<String> getAllPeerIds()
          List all registered peer clusters and set a watch on their znodes.
 Set<String> getConnectedPeers()
          Get a set of all connected remote slave clusters.
 org.apache.hadoop.conf.Configuration getPeerConf(String peerId)
          Returns the configuration needed to talk to the remote slave cluster.
 UUID getPeerUUID(String peerId)
          Returns the UUID of the provided peer id.
 List<ServerName> getRegionServersOfConnectedPeer(String peerId)
          Returns all region servers from given connected remote slave cluster.
 boolean getStatusOfConnectedPeer(String id)
          Get the replication status for the specified connected remote slave cluster.
 boolean getStatusOfPeerFromBackingStore(String id)
          Get the replication status for the specified remote slave cluster, which doesn't have to be connected.
 long getTimestampOfLastChangeToPeer(String peerId)
          Get the timestamp of the last change in composition of a given peer cluster.
 void init()
          Initialize the ReplicationPeers interface.
 void removePeer(String id)
          Removes a remote slave cluster and stops the replication to it.
 
Methods inherited from class org.apache.hadoop.hbase.replication.ReplicationStateZKBase
getListOfReplicators, isPeerPath, peerExists, toByteArray
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReplicationPeersZKImpl

public ReplicationPeersZKImpl(ZooKeeperWatcher zk,
                              org.apache.hadoop.conf.Configuration conf,
                              Abortable abortable)
Method Detail

init

public void init()
          throws ReplicationException
Description copied from interface: ReplicationPeers
Initialize the ReplicationPeers interface.

Specified by:
init in interface ReplicationPeers
Throws:
ReplicationException

addPeer

public void addPeer(String id,
                    String clusterKey)
             throws ReplicationException
Description copied from interface: ReplicationPeers
Add a new remote slave cluster for replication.

Specified by:
addPeer in interface ReplicationPeers
Parameters:
id - a short that identifies the cluster
clusterKey - the concatenation of the slave cluster's: hbase.zookeeper.quorum:hbase.zookeeper.property.clientPort:zookeeper.znode.parent
Throws:
ReplicationException

removePeer

public void removePeer(String id)
                throws ReplicationException
Description copied from interface: ReplicationPeers
Removes a remote slave cluster and stops the replication to it.

Specified by:
removePeer in interface ReplicationPeers
Parameters:
id - a short that identifies the cluster
Throws:
ReplicationException

enablePeer

public void enablePeer(String id)
                throws ReplicationException
Description copied from interface: ReplicationPeers
Restart the replication to the specified remote slave cluster.

Specified by:
enablePeer in interface ReplicationPeers
Parameters:
id - a short that identifies the cluster
Throws:
ReplicationException

disablePeer

public void disablePeer(String id)
                 throws ReplicationException
Description copied from interface: ReplicationPeers
Stop the replication to the specified remote slave cluster.

Specified by:
disablePeer in interface ReplicationPeers
Parameters:
id - a short that identifies the cluster
Throws:
ReplicationException

getStatusOfConnectedPeer

public boolean getStatusOfConnectedPeer(String id)
Description copied from interface: ReplicationPeers
Get the replication status for the specified connected remote slave cluster. The value might be read from cache, so it is recommended to use ReplicationPeers.getStatusOfPeerFromBackingStore(String) if reading the state after enabling or disabling it.

Specified by:
getStatusOfConnectedPeer in interface ReplicationPeers
Parameters:
id - a short that identifies the cluster
Returns:
true if replication is enabled, false otherwise.

getStatusOfPeerFromBackingStore

public boolean getStatusOfPeerFromBackingStore(String id)
                                        throws ReplicationException
Description copied from interface: ReplicationPeers
Get the replication status for the specified remote slave cluster, which doesn't have to be connected. The state is read directly from the backing store.

Specified by:
getStatusOfPeerFromBackingStore in interface ReplicationPeers
Parameters:
id - a short that identifies the cluster
Returns:
true if replication is enabled, false otherwise.
Throws:
ReplicationException

connectToPeer

public boolean connectToPeer(String peerId)
                      throws ReplicationException
Description copied from interface: ReplicationPeers
Attempt to connect to a new remote slave cluster.

Specified by:
connectToPeer in interface ReplicationPeers
Parameters:
peerId - a short that identifies the cluster
Returns:
true if a new connection was made, false if no new connection was made.
Throws:
ReplicationException

disconnectFromPeer

public void disconnectFromPeer(String peerId)
Description copied from interface: ReplicationPeers
Disconnect from a remote slave cluster.

Specified by:
disconnectFromPeer in interface ReplicationPeers
Parameters:
peerId - a short that identifies the cluster

getAllPeerClusterKeys

public Map<String,String> getAllPeerClusterKeys()
Description copied from interface: ReplicationPeers
List the cluster keys of all remote slave clusters (whether they are enabled/disabled or connected/disconnected).

Specified by:
getAllPeerClusterKeys in interface ReplicationPeers
Returns:
A map of peer ids to peer cluster keys

getRegionServersOfConnectedPeer

public List<ServerName> getRegionServersOfConnectedPeer(String peerId)
Description copied from interface: ReplicationPeers
Returns all region servers from given connected remote slave cluster.

Specified by:
getRegionServersOfConnectedPeer in interface ReplicationPeers
Parameters:
peerId - a short that identifies the cluster
Returns:
addresses of all region servers in the peer cluster. Returns an empty list if the peer cluster is unavailable or there are no region servers in the cluster.

getPeerUUID

public UUID getPeerUUID(String peerId)
Description copied from interface: ReplicationPeers
Returns the UUID of the provided peer id.

Specified by:
getPeerUUID in interface ReplicationPeers
Parameters:
peerId - the peer's ID that will be converted into a UUID
Returns:
a UUID or null if the peer cluster does not exist or is not connected.

getConnectedPeers

public Set<String> getConnectedPeers()
Description copied from interface: ReplicationPeers
Get a set of all connected remote slave clusters.

Specified by:
getConnectedPeers in interface ReplicationPeers
Returns:
set of peer ids

getPeerConf

public org.apache.hadoop.conf.Configuration getPeerConf(String peerId)
                                                 throws ReplicationException
Description copied from interface: ReplicationPeers
Returns the configuration needed to talk to the remote slave cluster.

Specified by:
getPeerConf in interface ReplicationPeers
Parameters:
peerId - a short that identifies the cluster
Returns:
the configuration for the peer cluster, null if it was unable to get the configuration
Throws:
ReplicationException

getAllPeerIds

public List<String> getAllPeerIds()
List all registered peer clusters and set a watch on their znodes.

Specified by:
getAllPeerIds in interface ReplicationPeers
Returns:
A list of peer ids

getTimestampOfLastChangeToPeer

public long getTimestampOfLastChangeToPeer(String peerId)
Description copied from interface: ReplicationPeers
Get the timestamp of the last change in composition of a given peer cluster.

Specified by:
getTimestampOfLastChangeToPeer in interface ReplicationPeers
Parameters:
peerId - identifier of the peer cluster for which the timestamp is requested
Returns:
the timestamp (in milliseconds) of the last change to the composition of the peer cluster


Copyright © 2013 The Apache Software Foundation. All Rights Reserved.