org.apache.hadoop.hbase.replication
Class ReplicationZookeeperWrapper

java.lang.Object
  extended by org.apache.hadoop.hbase.replication.ReplicationZookeeperWrapper

public class ReplicationZookeeperWrapper
extends Object

This class serves as a helper for all things related to zookeeper in replication.

The layout looks something like this under zookeeper.znode.parent for the master cluster:

 replication/
  master     {contains a full cluster address}
  state      {contains true or false}
  clusterId  {contains a byte}
  peers/
    1/   {contains a full cluster address}
    2/
    ...
  rs/ {lists all RS that replicate}
    startcode1/ {lists all peer clusters}
      1/ {lists hlogs to process}
        10.10.1.76%3A53488.123456789 {contains nothing or a position}
        10.10.1.76%3A53488.123456790
        ...
      2/
      ...
    startcode2/
    ...
 


Nested Class Summary
 class ReplicationZookeeperWrapper.ReplicationStatusWatcher
          Watcher for the status of the replication
 
Constructor Summary
ReplicationZookeeperWrapper(ZooKeeperWrapper zookeeperWrapper, org.apache.hadoop.conf.Configuration conf, AtomicBoolean replicating, String rsName)
          Constructor used by region servers, connects to the peer cluster right away.
 
Method Summary
 void addLogToList(String filename, String clusterId)
          Add a new log to the list of hlogs in zookeeper
 SortedMap<String,SortedSet<String>> copyQueuesFromRS(String znode)
          This methods copies all the hlogs queues from another region server and returns them all sorted per peer cluster (appended with the dead server's znode)
 void deleteOwnRSZNode()
          Delete this cluster's queues
 void deleteRsQueues(String znode)
          Recursive deletion of all znodes in specified rs' znode
 void deleteSource(String peerZnode)
          Delete a complete queue of hlogs
 String getClusterId()
          Get the identification of the cluster
 long getHLogRepPosition(String peerId, String hlog)
          Get the position of the specified hlog in the specified peer znode
 List<String> getListHLogsForPeerForRS(String rs, String id, org.apache.zookeeper.Watcher watch)
          Get the list of hlogs for the specified region server and peer cluster
 List<String> getListOfReplicators(org.apache.zookeeper.Watcher watch)
          Get the list of the replicators that have queues, they can be alive, dead or simply from a previous run
 List<String> getListPeersForRS(String rs, org.apache.zookeeper.Watcher watch)
          Get the list of peer clusters for the specified server names
 Map<String,ZooKeeperWrapper> getPeerClusters()
          Get a map of all peer clusters
 List<HServerAddress> getPeersAddresses(String peerClusterId)
          Returns all region servers from given peer
 List<String> getRegisteredRegionServers(org.apache.zookeeper.Watcher watch)
          Get a list of all the other region servers in this cluster and set a watch
 boolean isReplicationMaster()
          Tells if this cluster replicates or not
 boolean lockOtherRS(String znode)
          Try to set a lock in another server's znode.
 void removeLogFromList(String filename, String clusterId)
          Remove a log from the list of hlogs in zookeeper
 void writeReplicationStatus(String filename, String clusterId, long position)
          Set the current position of the specified cluster in the current hlog
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReplicationZookeeperWrapper

public ReplicationZookeeperWrapper(ZooKeeperWrapper zookeeperWrapper,
                                   org.apache.hadoop.conf.Configuration conf,
                                   AtomicBoolean replicating,
                                   String rsName)
                            throws IOException
Constructor used by region servers, connects to the peer cluster right away.

Parameters:
zookeeperWrapper - zkw to wrap
conf - conf to use
replicating - atomic boolean to start/stop replication
rsName - the name of this region server, null if using RZH only to use the helping methods
Throws:
IOException
Method Detail

getPeersAddresses

public List<HServerAddress> getPeersAddresses(String peerClusterId)
Returns all region servers from given peer

Parameters:
peerClusterId - (byte) the cluster to interrogate
Returns:
addresses of all region servers

addLogToList

public void addLogToList(String filename,
                         String clusterId)
Add a new log to the list of hlogs in zookeeper

Parameters:
filename - name of the hlog's znode
clusterId - name of the cluster's znode

removeLogFromList

public void removeLogFromList(String filename,
                              String clusterId)
Remove a log from the list of hlogs in zookeeper

Parameters:
filename - name of the hlog's znode
clusterId - name of the cluster's znode

writeReplicationStatus

public void writeReplicationStatus(String filename,
                                   String clusterId,
                                   long position)
Set the current position of the specified cluster in the current hlog

Parameters:
filename - filename name of the hlog's znode
clusterId - clusterId name of the cluster's znode
position - the position in the file
Throws:
IOException

getRegisteredRegionServers

public List<String> getRegisteredRegionServers(org.apache.zookeeper.Watcher watch)
Get a list of all the other region servers in this cluster and set a watch

Parameters:
watch - the watch to set
Returns:
a list of server nanes

getListOfReplicators

public List<String> getListOfReplicators(org.apache.zookeeper.Watcher watch)
Get the list of the replicators that have queues, they can be alive, dead or simply from a previous run

Parameters:
watch - the watche to set
Returns:
a list of server names

getListPeersForRS

public List<String> getListPeersForRS(String rs,
                                      org.apache.zookeeper.Watcher watch)
Get the list of peer clusters for the specified server names

Parameters:
rs - server names of the rs
watch - the watch to set
Returns:
a list of peer cluster

getListHLogsForPeerForRS

public List<String> getListHLogsForPeerForRS(String rs,
                                             String id,
                                             org.apache.zookeeper.Watcher watch)
Get the list of hlogs for the specified region server and peer cluster

Parameters:
rs - server names of the rs
id - peer cluster
watch - the watch to set
Returns:
a list of hlogs

lockOtherRS

public boolean lockOtherRS(String znode)
Try to set a lock in another server's znode.

Parameters:
znode - the server names of the other server
Returns:
true if the lock was acquired, false in every other cases

copyQueuesFromRS

public SortedMap<String,SortedSet<String>> copyQueuesFromRS(String znode)
This methods copies all the hlogs queues from another region server and returns them all sorted per peer cluster (appended with the dead server's znode)

Parameters:
znode - server names to copy
Returns:
all hlogs for all peers of that cluster, null if an error occurred

deleteSource

public void deleteSource(String peerZnode)
Delete a complete queue of hlogs

Parameters:
peerZnode - znode of the peer cluster queue of hlogs to delete

deleteRsQueues

public void deleteRsQueues(String znode)
Recursive deletion of all znodes in specified rs' znode

Parameters:
znode -

deleteOwnRSZNode

public void deleteOwnRSZNode()
Delete this cluster's queues


getHLogRepPosition

public long getHLogRepPosition(String peerId,
                               String hlog)
Get the position of the specified hlog in the specified peer znode

Parameters:
peerId - znode of the peer cluster
hlog - name of the hlog
Returns:
the position in that hlog

isReplicationMaster

public boolean isReplicationMaster()
Tells if this cluster replicates or not

Returns:
if this is a master

getClusterId

public String getClusterId()
Get the identification of the cluster

Returns:
the id for the cluster

getPeerClusters

public Map<String,ZooKeeperWrapper> getPeerClusters()
Get a map of all peer clusters

Returns:
map of peer cluster, zk address to ZKW


Copyright © 2010 Apache Software Foundation. All Rights Reserved.