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

@InterfaceAudience.Private
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] Each of these peer znodes has a child znode that indicates which data will be replicated to the peer cluster. These peer-tableCFs znodes do not have child znodes and only have a table/cf list config. This value is read/maintained by the ReplicationPeer.TableCFsTracker class. For example: /hbase/replication/peers/1/tableCFs [Value: "table1; table2:cf1,cf3; table3:cfx,cfy"]


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, ReplicationPeerConfig peerConfig, String tableCFs)
          Add a new remote slave cluster for replication.
 boolean createAndAddPeer(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 enablePeer(String id)
          Restart the replication to the specified remote slave cluster.
 Map<String,ReplicationPeerConfig> getAllPeerConfigs()
          List the cluster replication configs 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.
 ReplicationPeer getPeer(String peerId)
          Returns the ReplicationPeer
 Pair<ReplicationPeerConfig,org.apache.hadoop.conf.Configuration> getPeerConf(String peerId)
          Returns the configuration needed to talk to the remote slave cluster.
 Set<String> getPeerIds()
          Returns the set of peerIds defined
 String getPeerTableCFsConfig(String id)
          Get the table and column-family list string of the peer from ZK.
 ReplicationPeerConfig getReplicationPeerConfig(String peerId)
          Returns the configured ReplicationPeerConfig for this peerId
 boolean getStatusOfPeer(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.
 Map<String,List<String>> getTableCFs(String id)
          Get the table and column-family-list map of the peer.
 void init()
          Initialize the ReplicationPeers interface.
 boolean peerAdded(String peerId)
           
 void peerRemoved(String peerId)
           
 void removePeer(String id)
          Removes a remote slave cluster and stops the replication to it.
 void setPeerTableCFsConfig(String id, String tableCFsStr)
          Set the table and column-family list string of the peer to ZK.
 
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,
                    ReplicationPeerConfig peerConfig,
                    String tableCFs)
             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
peerConfig - configuration for the replication slave cluster
tableCFs - the table and column-family list which will be replicated for this peer or null for all table and column families
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

getPeerTableCFsConfig

public String getPeerTableCFsConfig(String id)
                             throws ReplicationException
Description copied from interface: ReplicationPeers
Get the table and column-family list string of the peer from ZK.

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

setPeerTableCFsConfig

public void setPeerTableCFsConfig(String id,
                                  String tableCFsStr)
                           throws ReplicationException
Description copied from interface: ReplicationPeers
Set the table and column-family list string of the peer to ZK.

Specified by:
setPeerTableCFsConfig in interface ReplicationPeers
Parameters:
id - a short that identifies the cluster
tableCFsStr - the table and column-family list which will be replicated for this peer
Throws:
ReplicationException

getTableCFs

public Map<String,List<String>> getTableCFs(String id)
                                     throws IllegalArgumentException
Description copied from interface: ReplicationPeers
Get the table and column-family-list map of the peer.

Specified by:
getTableCFs in interface ReplicationPeers
Parameters:
id - a short that identifies the cluster
Returns:
the table and column-family list which will be replicated for this peer
Throws:
IllegalArgumentException

getStatusOfPeer

public boolean getStatusOfPeer(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:
getStatusOfPeer 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

getAllPeerConfigs

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

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

getReplicationPeerConfig

public ReplicationPeerConfig getReplicationPeerConfig(String peerId)
                                               throws ReplicationException
Description copied from interface: ReplicationPeers
Returns the configured ReplicationPeerConfig for this peerId

Specified by:
getReplicationPeerConfig in interface ReplicationPeers
Parameters:
peerId - a short name that identifies the cluster
Returns:
ReplicationPeerConfig for the peer
Throws:
ReplicationException

getPeerConf

public Pair<ReplicationPeerConfig,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

getPeerIds

public Set<String> getPeerIds()
Description copied from interface: ReplicationPeers
Returns the set of peerIds defined

Specified by:
getPeerIds in interface ReplicationPeers
Returns:
a Set of Strings for peerIds

getPeer

public ReplicationPeer getPeer(String peerId)
Description copied from interface: ReplicationPeers
Returns the ReplicationPeer

Specified by:
getPeer in interface ReplicationPeers
Parameters:
peerId - id for the peer
Returns:
ReplicationPeer object

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

peerAdded

public boolean peerAdded(String peerId)
                  throws ReplicationException
Specified by:
peerAdded in interface ReplicationPeers
Throws:
ReplicationException

peerRemoved

public void peerRemoved(String peerId)
Specified by:
peerRemoved in interface ReplicationPeers

createAndAddPeer

public boolean createAndAddPeer(String peerId)
                         throws ReplicationException
Attempt to connect to a new remote slave cluster.

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


Copyright © 2007-2015 The Apache Software Foundation. All Rights Reserved.