Class ZKReplicationQueueStorage
java.lang.Object
org.apache.hadoop.hbase.replication.ZKReplicationStorageBase
org.apache.hadoop.hbase.replication.ZKReplicationQueueStorage
- All Implemented Interfaces:
- ReplicationQueueStorage
@Private
class ZKReplicationQueueStorage
extends ZKReplicationStorageBase
implements ReplicationQueueStorage
ZK based replication queue storage.
 
The base znode for each regionserver is the regionserver name. For example:
/hbase/replication/rs/hostname.example.org,6020,1234Within this znode, the region server maintains a set of WAL replication queues. These queues are represented by child znodes named using there give queue id. For example:
/hbase/replication/rs/hostname.example.org,6020,1234/1 /hbase/replication/rs/hostname.example.org,6020,1234/2Each queue has one child znode for every WAL that still needs to be replicated. The value of these WAL child znodes is the latest position that has been replicated. This position is updated every time a WAL entry is replicated. For example:
/hbase/replication/rs/hostname.example.org,6020,1234/1/23522342.23422 [VALUE: 254]
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprivate final StringThe name of the znode that contains queues of hfile references to be replicatedprivate static final org.slf4j.Loggerprivate final StringThe name of the znode that contains all replication queues(package private) final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringFields inherited from class org.apache.hadoop.hbase.replication.ZKReplicationStorageBaseconf, REPLICATION_ZNODE, REPLICATION_ZNODE_DEFAULT, replicationZNode, zookeeper
- 
Constructor SummaryConstructorsConstructorDescriptionZKReplicationQueueStorage(ZKWatcher zookeeper, org.apache.hadoop.conf.Configuration conf) 
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddHFileRefs(String peerId, List<Pair<org.apache.hadoop.fs.Path, org.apache.hadoop.fs.Path>> pairs) Add new hfile references to the queue.private voidaddLastSeqIdsToOps(String queueId, Map<String, Long> lastSeqIds, List<ZKUtil.ZKUtilOp> listOfOps) voidaddPeerToHFileRefs(String peerId) Add a peer to hfile reference queue if peer does not exist.voidaddWAL(ServerName serverName, String queueId, String fileName) Add a new WAL file to the given queue for a given regionserver.claimQueue(ServerName sourceServerName, String queueId, ServerName destServerName) This implement must update the cversion of rootqueuesZNode.Load all hfile references in all replication queues.Get list of all peers from hfile reference queue.getAllQueues(ServerName serverName) Get a list of all queues for the specified region server.getAllQueues0(ServerName serverName) The optimistic lock of this implement is based on the cversion of rootqueuesZNode.private StringgetFileNode(String queueNode, String fileName) private StringgetFileNode(ServerName serverName, String queueId, String fileName) private StringgetHFileNode(String peerNode, String fileName) private StringgetHFileRefsPeerNode(String peerId) protected intlonggetLastSequenceId(String encodedRegionName, String peerId) Read the max sequence id of the specific region for a given peer.getLastSequenceIdWithVersion(String encodedRegionName, String peerId) Return the {lastPushedSequenceId, ZNodeDataVersion} pair.Get a list of all region servers that have outstanding replication queues.private List<ServerName>private StringgetQueueNode(ServerName serverName, String queueId) protected intgetReplicableHFiles(String peerId) Get a list of all hfile references in the given peer.getReplicableHFiles0(String peerId) getRsNode(ServerName serverName) Get full znode name for given region server(package private) StringgetSerialReplicationRegionPeerNode(String encodedRegionName, String peerId) Put all regions under /hbase/replication/regions znode will lead to too many children because of the huge number of regions in real production environment.longgetWALPosition(ServerName serverName, String queueId, String fileName) Get the current position for a specific WAL in a given queue for a given regionserver.getWALsInQueue(ServerName serverName, String queueId) Get a list of all WALs in the given queue on the given region server.getWALsInQueue0(ServerName serverName, String queueId) voidremoveHFileRefs(String peerId, List<String> files) Remove hfile references from the queue.voidremoveLastSequenceIds(String peerId) Remove all the max sequence id record for the given peer.voidremoveLastSequenceIds(String peerId, List<String> encodedRegionNames) Remove the max sequence id record for the given peer and regions.voidremovePeerFromHFileRefs(String peerId) Remove a peer from hfile reference queue.voidremoveQueue(ServerName serverName, String queueId) Remove a replication queue for a given regionserver.voidremoveReplicatorIfQueueIsEmpty(ServerName serverName) Remove the record of region server if the queue is empty.voidremoveWAL(ServerName serverName, String queueId, String fileName) Remove an WAL file from the given queue for a given regionserver.voidsetLastSequenceIds(String peerId, Map<String, Long> lastSeqIds) Set the max sequence id of a bunch of regions for a given peer.voidsetWALPosition(ServerName serverName, String queueId, String fileName, long position, Map<String, Long> lastSeqIds) Set the current position for a specific WAL in a given queue for a given regionserver.Methods inherited from class org.apache.hadoop.hbase.replication.ZKReplicationStorageBasetoByteArray
- 
Field Details- 
LOG
- 
ZOOKEEPER_ZNODE_REPLICATION_HFILE_REFS_KEY- See Also:
 
- 
ZOOKEEPER_ZNODE_REPLICATION_HFILE_REFS_DEFAULT- See Also:
 
- 
ZOOKEEPER_ZNODE_REPLICATION_REGIONS_KEY- See Also:
 
- 
ZOOKEEPER_ZNODE_REPLICATION_REGIONS_DEFAULT- See Also:
 
- 
queuesZNodeThe name of the znode that contains all replication queues
- 
hfileRefsZNodeThe name of the znode that contains queues of hfile references to be replicated
- 
regionsZNode
 
- 
- 
Constructor Details- 
ZKReplicationQueueStorage
 
- 
- 
Method Details- 
getRsNodeDescription copied from interface:ReplicationQueueStorageGet full znode name for given region server- Specified by:
- getRsNodein interface- ReplicationQueueStorage
- Parameters:
- serverName- the name of the region server
- Returns:
- full znode name
 
- 
getQueueNode
- 
getFileNode
- 
getFileNode
- 
getSerialReplicationRegionPeerNodePut all regions under /hbase/replication/regions znode will lead to too many children because of the huge number of regions in real production environment. So here we will distribute the znodes to multiple directories. So the final znode path will be format like this: /hbase/replication/regions/dd/04/e76a6966d4ffa908ed0586764767-100 Here the full encoded region name is dd04e76a6966d4ffa908ed0586764767, and we use the first two characters 'dd' as the first level directory name, and use the next two characters '04' as the second level directory name, and the rest part as the prefix of the znode, and the suffix '100' is the peer id.- Parameters:
- encodedRegionName- the encoded region name.
- peerId- peer id for replication.
- Returns:
- ZNode path to persist the max sequence id that we've pushed for the given region and peer.
 
- 
removeQueueDescription copied from interface:ReplicationQueueStorageRemove a replication queue for a given regionserver.- Specified by:
- removeQueuein interface- ReplicationQueueStorage
- Parameters:
- serverName- the name of the regionserver
- queueId- a String that identifies the queue.
- Throws:
- ReplicationException
 
- 
addWALpublic void addWAL(ServerName serverName, String queueId, String fileName) throws ReplicationException Description copied from interface:ReplicationQueueStorageAdd a new WAL file to the given queue for a given regionserver. If the queue does not exist it is created.- Specified by:
- addWALin interface- ReplicationQueueStorage
- Parameters:
- serverName- the name of the regionserver
- queueId- a String that identifies the queue.
- fileName- name of the WAL
- Throws:
- ReplicationException
 
- 
removeWALpublic void removeWAL(ServerName serverName, String queueId, String fileName) throws ReplicationException Description copied from interface:ReplicationQueueStorageRemove an WAL file from the given queue for a given regionserver.- Specified by:
- removeWALin interface- ReplicationQueueStorage
- Parameters:
- serverName- the name of the regionserver
- queueId- a String that identifies the queue.
- fileName- name of the WAL
- Throws:
- ReplicationException
 
- 
addLastSeqIdsToOpsprivate void addLastSeqIdsToOps(String queueId, Map<String, Long> lastSeqIds, List<ZKUtil.ZKUtilOp> listOfOps) throws org.apache.zookeeper.KeeperException, ReplicationException- Throws:
- org.apache.zookeeper.KeeperException
- ReplicationException
 
- 
setWALPositionpublic void setWALPosition(ServerName serverName, String queueId, String fileName, long position, Map<String, Long> lastSeqIds) throws ReplicationExceptionDescription copied from interface:ReplicationQueueStorageSet the current position for a specific WAL in a given queue for a given regionserver.- Specified by:
- setWALPositionin interface- ReplicationQueueStorage
- Parameters:
- serverName- the name of the regionserver
- queueId- a String that identifies the queue
- fileName- name of the WAL
- position- the current position in the file. Will ignore if less than or equal to 0.
- lastSeqIds- map with {encodedRegionName, sequenceId} pairs for serial replication.
- Throws:
- ReplicationException
 
- 
getLastSequenceIdWithVersionprotected Pair<Long,Integer> getLastSequenceIdWithVersion(String encodedRegionName, String peerId) throws org.apache.zookeeper.KeeperException Return the {lastPushedSequenceId, ZNodeDataVersion} pair. if ZNodeDataVersion is -1, it means that the ZNode does not exist.- Throws:
- org.apache.zookeeper.KeeperException
 
- 
getLastSequenceIdDescription copied from interface:ReplicationQueueStorageRead the max sequence id of the specific region for a given peer. For serial replication, we need the max sequenced id to decide whether we can push the next entries.- Specified by:
- getLastSequenceIdin interface- ReplicationQueueStorage
- Parameters:
- encodedRegionName- the encoded region name
- peerId- peer id
- Returns:
- the max sequence id of the specific region for a given peer.
- Throws:
- ReplicationException
 
- 
setLastSequenceIdspublic void setLastSequenceIds(String peerId, Map<String, Long> lastSeqIds) throws ReplicationExceptionDescription copied from interface:ReplicationQueueStorageSet the max sequence id of a bunch of regions for a given peer. Will be called when setting up a serial replication peer.- Specified by:
- setLastSequenceIdsin interface- ReplicationQueueStorage
- Parameters:
- peerId- peer id
- lastSeqIds- map with {encodedRegionName, sequenceId} pairs for serial replication.
- Throws:
- ReplicationException
 
- 
removeLastSequenceIdsDescription copied from interface:ReplicationQueueStorageRemove all the max sequence id record for the given peer.- Specified by:
- removeLastSequenceIdsin interface- ReplicationQueueStorage
- Parameters:
- peerId- peer id
- Throws:
- ReplicationException
 
- 
removeLastSequenceIdspublic void removeLastSequenceIds(String peerId, List<String> encodedRegionNames) throws ReplicationException Description copied from interface:ReplicationQueueStorageRemove the max sequence id record for the given peer and regions.- Specified by:
- removeLastSequenceIdsin interface- ReplicationQueueStorage
- Parameters:
- peerId- peer id
- encodedRegionNames- the encoded region names
- Throws:
- ReplicationException
 
- 
getWALPositionpublic long getWALPosition(ServerName serverName, String queueId, String fileName) throws ReplicationException Description copied from interface:ReplicationQueueStorageGet the current position for a specific WAL in a given queue for a given regionserver.- Specified by:
- getWALPositionin interface- ReplicationQueueStorage
- Parameters:
- serverName- the name of the regionserver
- queueId- a String that identifies the queue
- fileName- name of the WAL
- Returns:
- the current position in the file
- Throws:
- ReplicationException
 
- 
claimQueuepublic Pair<String,SortedSet<String>> claimQueue(ServerName sourceServerName, String queueId, ServerName destServerName) throws ReplicationException This implement must update the cversion of rootqueuesZNode. The optimistic lock of thegetAllWALs()method is based on the cversion of rootqueuesZNode.- Specified by:
- claimQueuein interface- ReplicationQueueStorage
- Parameters:
- sourceServerName- the name of the dead region server
- queueId- the id of the queue
- destServerName- the name of the target region server
- Returns:
- the new PeerId and A SortedSet of WALs in its queue
- Throws:
- ReplicationException
- See Also:
 
- 
removeReplicatorIfQueueIsEmptyDescription copied from interface:ReplicationQueueStorageRemove the record of region server if the queue is empty.- Specified by:
- removeReplicatorIfQueueIsEmptyin interface- ReplicationQueueStorage
- Throws:
- ReplicationException
 
- 
getListOfReplicators0- Throws:
- org.apache.zookeeper.KeeperException
 
- 
getListOfReplicatorsDescription copied from interface:ReplicationQueueStorageGet a list of all region servers that have outstanding replication queues. These servers could be alive, dead or from a previous run of the cluster.- Specified by:
- getListOfReplicatorsin interface- ReplicationQueueStorage
- Returns:
- a list of server names
- Throws:
- ReplicationException
 
- 
getWALsInQueue0private List<String> getWALsInQueue0(ServerName serverName, String queueId) throws org.apache.zookeeper.KeeperException - Throws:
- org.apache.zookeeper.KeeperException
 
- 
getWALsInQueuepublic List<String> getWALsInQueue(ServerName serverName, String queueId) throws ReplicationException Description copied from interface:ReplicationQueueStorageGet a list of all WALs in the given queue on the given region server.- Specified by:
- getWALsInQueuein interface- ReplicationQueueStorage
- Parameters:
- serverName- the server name of the region server that owns the queue
- queueId- a String that identifies the queue
- Returns:
- a list of WALs
- Throws:
- ReplicationException
 
- 
getAllQueues0private List<String> getAllQueues0(ServerName serverName) throws org.apache.zookeeper.KeeperException - Throws:
- org.apache.zookeeper.KeeperException
 
- 
getAllQueuesDescription copied from interface:ReplicationQueueStorageGet a list of all queues for the specified region server.- Specified by:
- getAllQueuesin interface- ReplicationQueueStorage
- Parameters:
- serverName- the server name of the region server that owns the set of queues
- Returns:
- a list of queueIds
- Throws:
- ReplicationException
 
- 
getQueuesZNodeCversion- Throws:
- org.apache.zookeeper.KeeperException
 
- 
getAllWALsThe optimistic lock of this implement is based on the cversion of rootqueuesZNode. Therefore, we must update the cversion of rootqueuesZNodewhen migrate wal nodes to other queues.- Specified by:
- getAllWALsin interface- ReplicationQueueStorage
- Throws:
- ReplicationException
- See Also:
 
- 
getHFileRefsPeerNode
- 
getHFileNode
- 
addPeerToHFileRefsDescription copied from interface:ReplicationQueueStorageAdd a peer to hfile reference queue if peer does not exist.- Specified by:
- addPeerToHFileRefsin interface- ReplicationQueueStorage
- Parameters:
- peerId- peer cluster id to be added
- Throws:
- ReplicationException- if fails to add a peer id to hfile reference queue
 
- 
removePeerFromHFileRefsDescription copied from interface:ReplicationQueueStorageRemove a peer from hfile reference queue.- Specified by:
- removePeerFromHFileRefsin interface- ReplicationQueueStorage
- Parameters:
- peerId- peer cluster id to be removed
- Throws:
- ReplicationException
 
- 
addHFileRefspublic void addHFileRefs(String peerId, List<Pair<org.apache.hadoop.fs.Path, org.apache.hadoop.fs.Path>> pairs) throws ReplicationExceptionDescription copied from interface:ReplicationQueueStorageAdd new hfile references to the queue.- Specified by:
- addHFileRefsin interface- ReplicationQueueStorage
- Parameters:
- peerId- peer cluster id to which the hfiles need to be replicated
- pairs- list of pairs of { HFile location in staging dir, HFile path in region dir which will be added in the queue }
- Throws:
- ReplicationException- if fails to add a hfile reference
 
- 
removeHFileRefsDescription copied from interface:ReplicationQueueStorageRemove hfile references from the queue.- Specified by:
- removeHFileRefsin interface- ReplicationQueueStorage
- Parameters:
- peerId- peer cluster id from which this hfile references needs to be removed
- files- list of hfile references to be removed
- Throws:
- ReplicationException
 
- 
getAllPeersFromHFileRefsQueue0- Throws:
- org.apache.zookeeper.KeeperException
 
- 
getAllPeersFromHFileRefsQueueDescription copied from interface:ReplicationQueueStorageGet list of all peers from hfile reference queue.- Specified by:
- getAllPeersFromHFileRefsQueuein interface- ReplicationQueueStorage
- Returns:
- a list of peer ids
- Throws:
- ReplicationException
 
- 
getReplicableHFiles0private List<String> getReplicableHFiles0(String peerId) throws org.apache.zookeeper.KeeperException - Throws:
- org.apache.zookeeper.KeeperException
 
- 
getReplicableHFilesDescription copied from interface:ReplicationQueueStorageGet a list of all hfile references in the given peer.- Specified by:
- getReplicableHFilesin interface- ReplicationQueueStorage
- Parameters:
- peerId- a String that identifies the peer
- Returns:
- a list of hfile references
- Throws:
- ReplicationException
 
- 
getHFileRefsZNodeCversion- Throws:
- ReplicationException
 
- 
getAllHFileRefsDescription copied from interface:ReplicationQueueStorageLoad all hfile references in all replication queues. This method guarantees to return a snapshot which contains all hfile references at the start of this call. However, some newly created hfile references during the call may not be included.- Specified by:
- getAllHFileRefsin interface- ReplicationQueueStorage
- Throws:
- ReplicationException
 
 
-