@InterfaceAudience.Private class ZKReplicationQueueStorage extends ZKReplicationStorageBase implements ReplicationQueueStorage
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]
| Modifier and Type | Field and Description |
|---|---|
private String |
hfileRefsZNode
The name of the znode that contains queues of hfile references to be replicated
|
private static org.slf4j.Logger |
LOG |
private String |
queuesZNode
The name of the znode that contains all replication queues
|
(package private) String |
regionsZNode |
static String |
ZOOKEEPER_ZNODE_REPLICATION_HFILE_REFS_DEFAULT |
static String |
ZOOKEEPER_ZNODE_REPLICATION_HFILE_REFS_KEY |
static String |
ZOOKEEPER_ZNODE_REPLICATION_REGIONS_DEFAULT |
static String |
ZOOKEEPER_ZNODE_REPLICATION_REGIONS_KEY |
conf, REPLICATION_ZNODE, REPLICATION_ZNODE_DEFAULT, replicationZNode, zookeeper| Constructor and Description |
|---|
ZKReplicationQueueStorage(ZKWatcher zookeeper,
org.apache.hadoop.conf.Configuration conf) |
| Modifier and Type | Method and Description |
|---|---|
void |
addHFileRefs(String peerId,
List<Pair<org.apache.hadoop.fs.Path,org.apache.hadoop.fs.Path>> pairs)
Add new hfile references to the queue.
|
private void |
addLastSeqIdsToOps(String queueId,
Map<String,Long> lastSeqIds,
List<ZKUtil.ZKUtilOp> listOfOps) |
void |
addPeerToHFileRefs(String peerId)
Add a peer to hfile reference queue if peer does not exist.
|
void |
addWAL(ServerName serverName,
String queueId,
String fileName)
Add a new WAL file to the given queue for a given regionserver.
|
Pair<String,SortedSet<String>> |
claimQueue(ServerName sourceServerName,
String queueId,
ServerName destServerName)
This implement must update the cversion of root
queuesZNode. |
Set<String> |
getAllHFileRefs()
Load all hfile references in all replication queues.
|
List<String> |
getAllPeersFromHFileRefsQueue()
Get list of all peers from hfile reference queue.
|
private List<String> |
getAllPeersFromHFileRefsQueue0() |
List<String> |
getAllQueues(ServerName serverName)
Get a list of all queues for the specified region server.
|
private List<String> |
getAllQueues0(ServerName serverName) |
Set<String> |
getAllWALs()
The optimistic lock of this implement is based on the cversion of root
queuesZNode. |
private String |
getFileNode(ServerName serverName,
String queueId,
String fileName) |
private String |
getFileNode(String queueNode,
String fileName) |
private String |
getHFileNode(String peerNode,
String fileName) |
private String |
getHFileRefsPeerNode(String peerId) |
protected int |
getHFileRefsZNodeCversion() |
long |
getLastSequenceId(String encodedRegionName,
String peerId)
Read the max sequence id of the specific region for a given peer.
|
protected Pair<Long,Integer> |
getLastSequenceIdWithVersion(String encodedRegionName,
String peerId)
Return the {lastPushedSequenceId, ZNodeDataVersion} pair.
|
List<ServerName> |
getListOfReplicators()
Get a list of all region servers that have outstanding replication queues.
|
private List<ServerName> |
getListOfReplicators0() |
private String |
getQueueNode(ServerName serverName,
String queueId) |
protected int |
getQueuesZNodeCversion() |
List<String> |
getReplicableHFiles(String peerId)
Get a list of all hfile references in the given peer.
|
private List<String> |
getReplicableHFiles0(String peerId) |
String |
getRsNode(ServerName serverName)
Get full znode name for given region server
|
(package private) String |
getSerialReplicationRegionPeerNode(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.
|
long |
getWALPosition(ServerName serverName,
String queueId,
String fileName)
Get the current position for a specific WAL in a given queue for a given regionserver.
|
List<String> |
getWALsInQueue(ServerName serverName,
String queueId)
Get a list of all WALs in the given queue on the given region server.
|
private List<String> |
getWALsInQueue0(ServerName serverName,
String queueId) |
void |
removeHFileRefs(String peerId,
List<String> files)
Remove hfile references from the queue.
|
void |
removeLastSequenceIds(String peerId)
Remove all the max sequence id record for the given peer.
|
void |
removeLastSequenceIds(String peerId,
List<String> encodedRegionNames)
Remove the max sequence id record for the given peer and regions.
|
void |
removePeerFromHFileRefs(String peerId)
Remove a peer from hfile reference queue.
|
void |
removeQueue(ServerName serverName,
String queueId)
Remove a replication queue for a given regionserver.
|
void |
removeReplicatorIfQueueIsEmpty(ServerName serverName)
Remove the record of region server if the queue is empty.
|
void |
removeWAL(ServerName serverName,
String queueId,
String fileName)
Remove an WAL file from the given queue for a given regionserver.
|
void |
setLastSequenceIds(String peerId,
Map<String,Long> lastSeqIds)
Set the max sequence id of a bunch of regions for a given peer.
|
void |
setWALPosition(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.
|
toByteArrayprivate static final org.slf4j.Logger LOG
public static final String ZOOKEEPER_ZNODE_REPLICATION_HFILE_REFS_KEY
public static final String ZOOKEEPER_ZNODE_REPLICATION_HFILE_REFS_DEFAULT
public static final String ZOOKEEPER_ZNODE_REPLICATION_REGIONS_KEY
public static final String ZOOKEEPER_ZNODE_REPLICATION_REGIONS_DEFAULT
private final String queuesZNode
private final String hfileRefsZNode
final String regionsZNode
public ZKReplicationQueueStorage(ZKWatcher zookeeper, org.apache.hadoop.conf.Configuration conf)
public String getRsNode(ServerName serverName)
ReplicationQueueStoragegetRsNode in interface ReplicationQueueStorageserverName - the name of the region serverprivate String getQueueNode(ServerName serverName, String queueId)
private String getFileNode(String queueNode, String fileName)
private String getFileNode(ServerName serverName, String queueId, String fileName)
String getSerialReplicationRegionPeerNode(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. 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-100Here 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.
encodedRegionName - the encoded region name.peerId - peer id for replication.public void removeQueue(ServerName serverName, String queueId) throws ReplicationException
ReplicationQueueStorageremoveQueue in interface ReplicationQueueStorageserverName - the name of the regionserverqueueId - a String that identifies the queue.ReplicationExceptionpublic void addWAL(ServerName serverName, String queueId, String fileName) throws ReplicationException
ReplicationQueueStorageaddWAL in interface ReplicationQueueStorageserverName - the name of the regionserverqueueId - a String that identifies the queue.fileName - name of the WALReplicationExceptionpublic void removeWAL(ServerName serverName, String queueId, String fileName) throws ReplicationException
ReplicationQueueStorageremoveWAL in interface ReplicationQueueStorageserverName - the name of the regionserverqueueId - a String that identifies the queue.fileName - name of the WALReplicationExceptionprivate void addLastSeqIdsToOps(String queueId, Map<String,Long> lastSeqIds, List<ZKUtil.ZKUtilOp> listOfOps) throws org.apache.zookeeper.KeeperException, ReplicationException
org.apache.zookeeper.KeeperExceptionReplicationExceptionpublic void setWALPosition(ServerName serverName, String queueId, String fileName, long position, Map<String,Long> lastSeqIds) throws ReplicationException
ReplicationQueueStoragesetWALPosition in interface ReplicationQueueStorageserverName - the name of the regionserverqueueId - a String that identifies the queuefileName - name of the WALposition - the current position in the file. Will ignore if less than or equal to 0.lastSeqIds - map with {encodedRegionName, sequenceId} pairs for serial replication.ReplicationExceptionprotected Pair<Long,Integer> getLastSequenceIdWithVersion(String encodedRegionName, String peerId) throws org.apache.zookeeper.KeeperException
org.apache.zookeeper.KeeperExceptionpublic long getLastSequenceId(String encodedRegionName, String peerId) throws ReplicationException
ReplicationQueueStoragegetLastSequenceId in interface ReplicationQueueStorageencodedRegionName - the encoded region namepeerId - peer idReplicationExceptionpublic void setLastSequenceIds(String peerId, Map<String,Long> lastSeqIds) throws ReplicationException
ReplicationQueueStoragesetLastSequenceIds in interface ReplicationQueueStoragepeerId - peer idlastSeqIds - map with {encodedRegionName, sequenceId} pairs for serial replication.ReplicationExceptionpublic void removeLastSequenceIds(String peerId) throws ReplicationException
ReplicationQueueStorageremoveLastSequenceIds in interface ReplicationQueueStoragepeerId - peer idReplicationExceptionpublic void removeLastSequenceIds(String peerId, List<String> encodedRegionNames) throws ReplicationException
ReplicationQueueStorageremoveLastSequenceIds in interface ReplicationQueueStoragepeerId - peer idencodedRegionNames - the encoded region namesReplicationExceptionpublic long getWALPosition(ServerName serverName, String queueId, String fileName) throws ReplicationException
ReplicationQueueStoragegetWALPosition in interface ReplicationQueueStorageserverName - the name of the regionserverqueueId - a String that identifies the queuefileName - name of the WALReplicationExceptionpublic Pair<String,SortedSet<String>> claimQueue(ServerName sourceServerName, String queueId, ServerName destServerName) throws ReplicationException
queuesZNode. The optimistic lock of
the getAllWALs() method is based on the cversion of root queuesZNode.claimQueue in interface ReplicationQueueStoragesourceServerName - the name of the dead region serverqueueId - the id of the queuedestServerName - the name of the target region serverReplicationExceptionto show the usage of the cversion of root {@link #queuesZNode} .public void removeReplicatorIfQueueIsEmpty(ServerName serverName) throws ReplicationException
ReplicationQueueStorageremoveReplicatorIfQueueIsEmpty in interface ReplicationQueueStorageReplicationExceptionprivate List<ServerName> getListOfReplicators0() throws org.apache.zookeeper.KeeperException
org.apache.zookeeper.KeeperExceptionpublic List<ServerName> getListOfReplicators() throws ReplicationException
ReplicationQueueStoragegetListOfReplicators in interface ReplicationQueueStorageReplicationExceptionprivate List<String> getWALsInQueue0(ServerName serverName, String queueId) throws org.apache.zookeeper.KeeperException
org.apache.zookeeper.KeeperExceptionpublic List<String> getWALsInQueue(ServerName serverName, String queueId) throws ReplicationException
ReplicationQueueStoragegetWALsInQueue in interface ReplicationQueueStorageserverName - the server name of the region server that owns the queuequeueId - a String that identifies the queueReplicationExceptionprivate List<String> getAllQueues0(ServerName serverName) throws org.apache.zookeeper.KeeperException
org.apache.zookeeper.KeeperExceptionpublic List<String> getAllQueues(ServerName serverName) throws ReplicationException
ReplicationQueueStoragegetAllQueues in interface ReplicationQueueStorageserverName - the server name of the region server that owns the set of queuesReplicationExceptionprotected int getQueuesZNodeCversion() throws org.apache.zookeeper.KeeperException
org.apache.zookeeper.KeeperExceptionpublic Set<String> getAllWALs() throws ReplicationException
queuesZNode.
Therefore, we must update the cversion of root queuesZNode when migrate wal nodes to
other queues.getAllWALs in interface ReplicationQueueStorageReplicationExceptionas an example of updating root
{@link #queuesZNode} cversion.private String getHFileRefsPeerNode(String peerId)
private String getHFileNode(String peerNode, String fileName)
public void addPeerToHFileRefs(String peerId) throws ReplicationException
ReplicationQueueStorageaddPeerToHFileRefs in interface ReplicationQueueStoragepeerId - peer cluster id to be addedReplicationException - if fails to add a peer id to hfile reference queuepublic void removePeerFromHFileRefs(String peerId) throws ReplicationException
ReplicationQueueStorageremovePeerFromHFileRefs in interface ReplicationQueueStoragepeerId - peer cluster id to be removedReplicationExceptionpublic void addHFileRefs(String peerId, List<Pair<org.apache.hadoop.fs.Path,org.apache.hadoop.fs.Path>> pairs) throws ReplicationException
ReplicationQueueStorageaddHFileRefs in interface ReplicationQueueStoragepeerId - peer cluster id to which the hfiles need to be replicatedpairs - list of pairs of { HFile location in staging dir, HFile path in region dir which
will be added in the queue }ReplicationException - if fails to add a hfile referencepublic void removeHFileRefs(String peerId, List<String> files) throws ReplicationException
ReplicationQueueStorageremoveHFileRefs in interface ReplicationQueueStoragepeerId - peer cluster id from which this hfile references needs to be removedfiles - list of hfile references to be removedReplicationExceptionprivate List<String> getAllPeersFromHFileRefsQueue0() throws org.apache.zookeeper.KeeperException
org.apache.zookeeper.KeeperExceptionpublic List<String> getAllPeersFromHFileRefsQueue() throws ReplicationException
ReplicationQueueStoragegetAllPeersFromHFileRefsQueue in interface ReplicationQueueStorageReplicationExceptionprivate List<String> getReplicableHFiles0(String peerId) throws org.apache.zookeeper.KeeperException
org.apache.zookeeper.KeeperExceptionpublic List<String> getReplicableHFiles(String peerId) throws ReplicationException
ReplicationQueueStoragegetReplicableHFiles in interface ReplicationQueueStoragepeerId - a String that identifies the peerReplicationExceptionprotected int getHFileRefsZNodeCversion() throws ReplicationException
ReplicationExceptionpublic Set<String> getAllHFileRefs() throws ReplicationException
ReplicationQueueStoragegetAllHFileRefs in interface ReplicationQueueStorageReplicationExceptionCopyright © 2007–2020 The Apache Software Foundation. All rights reserved.