Class TableReplicationQueueStorage
java.lang.Object
org.apache.hadoop.hbase.replication.TableReplicationQueueStorage
- All Implemented Interfaces:
ReplicationQueueStorage
@Private
public class TableReplicationQueueStorage
extends Object
implements ReplicationQueueStorage
HBase table based replication queue storage.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Connectionstatic final byte[]static final byte[]static final byte[]private final TableName -
Constructor Summary
Constructors -
Method Summary
Modifier 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 voidaddLastSeqIdsPut(org.apache.hadoop.hbase.shaded.protobuf.generated.MultiRowMutationProtos.MutateRowsRequest.Builder builder, String peerId, Map<String, Long> lastSeqIds, AsyncTable<?> table) voidbatchUpdateHFileRefs(String peerId, List<String> hfileRefs) Add the given hfile refs to the given peer.voidbatchUpdateLastSequenceIds(List<ZKReplicationQueueStorageForMigration.ZkLastPushedSeqId> lastPushedSeqIds) Update last pushed sequence id for the given regions and peers.voidbatchUpdateQueues(ServerName serverName, List<ReplicationQueueData> datas) Update the replication queue datas for a given region server.claimQueue(ReplicationQueueId queueId, ServerName targetServerName) Change ownership for the queue identified by queueId and belongs to a dead region server.Load all hfile references in all replication queues.Get list of all peers from hfile reference queue.longgetLastSequenceId(String encodedRegionName, String peerId) Read the max sequence id of the specific region for a given peer.getOffsets(ReplicationQueueId queueId) Get the current offset of all the WAL groups for a queueprivate Map<String,ReplicationGroupOffset> getOffsets0(Table table, ReplicationQueueId queueId) getReplicableHFiles(String peerId) Get a list of all hfile references in the given peer.booleanhasData()Whether the replication queue table exists.listAllQueueIds(String peerId) Get a list of all queues for the specific peer.listAllQueueIds(String peerId, ServerName serverName) Get a list of all queues for the specific region server and the specific peerprivate voidlistAllQueueIds(Table table, String peerId, ServerName serverName, List<ReplicationQueueId> queueIds) private voidlistAllQueueIds(Table table, Scan scan, List<ReplicationQueueId> queueIds) listAllQueueIds(ServerName serverName) Get a list of all queues for the specific region server.Get a list of all queues and the offsets.Get a list of all region servers that have outstanding replication queues.private org.apache.hbase.thirdparty.com.google.common.collect.ImmutableMap<String,ReplicationGroupOffset> parseOffsets(Result result) voidremoveAllQueues(String peerId) Remove all the replication queues for the given peer.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.voidRemove all the last sequence ids and hfile references data which are written before the given timestamp.voidremovePeerFromHFileRefs(String peerId) Remove a peer from hfile reference queue.voidremoveQueue(ReplicationQueueId queueId) Remove a replication queueprivate <T extends Collection<String>>
TscanHFiles(Scan scan, Supplier<T> creator) voidsetLastSequenceIds(String peerId, Map<String, Long> lastSeqIds) Set the max sequence id of a bunch of regions for a given peer.voidsetOffset(ReplicationQueueId queueId, String walGroup, ReplicationGroupOffset offset, Map<String, Long> lastSeqIds) Set the current offset for a specific WAL group in a given queue.
-
Field Details
-
QUEUE_FAMILY
-
LAST_SEQUENCE_ID_FAMILY
-
HFILE_REF_FAMILY
-
conn
-
tableName
-
-
Constructor Details
-
TableReplicationQueueStorage
-
-
Method Details
-
addLastSeqIdsPut
private void addLastSeqIdsPut(org.apache.hadoop.hbase.shaded.protobuf.generated.MultiRowMutationProtos.MutateRowsRequest.Builder builder, String peerId, Map<String, Long> lastSeqIds, AsyncTable<?> table) throws IOException- Throws:
IOException
-
setOffset
public void setOffset(ReplicationQueueId queueId, String walGroup, ReplicationGroupOffset offset, Map<String, Long> lastSeqIds) throws ReplicationExceptionDescription copied from interface:ReplicationQueueStorageSet the current offset for a specific WAL group in a given queue.- Specified by:
setOffsetin interfaceReplicationQueueStorage- Parameters:
queueId- the id of the queuewalGroup- the group of the WAL, can be empty if multi wal is not enabledoffset- the current offset of replication progresslastSeqIds- map with {encodedRegionName, sequenceId} pairs for serial replication.- Throws:
ReplicationException
-
parseOffsets
private org.apache.hbase.thirdparty.com.google.common.collect.ImmutableMap<String,ReplicationGroupOffset> parseOffsets(Result result) -
getOffsets0
private Map<String,ReplicationGroupOffset> getOffsets0(Table table, ReplicationQueueId queueId) throws IOException - Throws:
IOException
-
getOffsets
public Map<String,ReplicationGroupOffset> getOffsets(ReplicationQueueId queueId) throws ReplicationException Description copied from interface:ReplicationQueueStorageGet the current offset of all the WAL groups for a queue- Specified by:
getOffsetsin interfaceReplicationQueueStorage- Parameters:
queueId- the id of the queue- Returns:
- a map of all offsets of the WAL groups. The key the is WAL group and the value is the position.
- Throws:
ReplicationException
-
listAllQueueIds
private void listAllQueueIds(Table table, Scan scan, List<ReplicationQueueId> queueIds) throws IOException - Throws:
IOException
-
listAllQueueIds
private void listAllQueueIds(Table table, String peerId, ServerName serverName, List<ReplicationQueueId> queueIds) throws IOException - Throws:
IOException
-
listAllQueueIds
Description copied from interface:ReplicationQueueStorageGet a list of all queues for the specific peer.- Specified by:
listAllQueueIdsin interfaceReplicationQueueStorage- Parameters:
peerId- the id of the peer- Returns:
- a list of queueIds
- Throws:
ReplicationException
-
listAllQueueIds
Description copied from interface:ReplicationQueueStorageGet a list of all queues for the specific region server.- Specified by:
listAllQueueIdsin interfaceReplicationQueueStorage- Parameters:
serverName- the server name of the region server that owns the set of queues- Returns:
- a list of queueIds
- Throws:
ReplicationException
-
listAllQueueIds
public List<ReplicationQueueId> listAllQueueIds(String peerId, ServerName serverName) throws ReplicationException Description copied from interface:ReplicationQueueStorageGet a list of all queues for the specific region server and the specific peer- Specified by:
listAllQueueIdsin interfaceReplicationQueueStorage- Parameters:
peerId- the id of the peerserverName- the server name of the region server that owns the set of queues- Returns:
- a list of queueIds
- Throws:
ReplicationException
-
listAllQueues
Description copied from interface:ReplicationQueueStorageGet a list of all queues and the offsets.- Specified by:
listAllQueuesin interfaceReplicationQueueStorage- Throws:
ReplicationException
-
listAllReplicators
Description 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:
listAllReplicatorsin interfaceReplicationQueueStorage- Returns:
- a list of server names
- Throws:
ReplicationException
-
claimQueue
public Map<String,ReplicationGroupOffset> claimQueue(ReplicationQueueId queueId, ServerName targetServerName) throws ReplicationException Description copied from interface:ReplicationQueueStorageChange ownership for the queue identified by queueId and belongs to a dead region server.- Specified by:
claimQueuein interfaceReplicationQueueStorage- Parameters:
queueId- the id of the queuetargetServerName- the name of the target region server- Returns:
- the new PeerId and A SortedSet of WALs in its queue
- Throws:
ReplicationException
-
removeQueue
Description copied from interface:ReplicationQueueStorageRemove a replication queue- Specified by:
removeQueuein interfaceReplicationQueueStorage- Parameters:
queueId- the id of the queue to remove- Throws:
ReplicationException
-
removeAllQueues
Description copied from interface:ReplicationQueueStorageRemove all the replication queues for the given peer. Usually used when removing a peer.- Specified by:
removeAllQueuesin interfaceReplicationQueueStorage- Parameters:
peerId- the id of the peer- Throws:
ReplicationException
-
getLastSequenceId
Description 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 interfaceReplicationQueueStorage- Parameters:
encodedRegionName- the encoded region namepeerId- peer id- Returns:
- the max sequence id of the specific region for a given peer.
- Throws:
ReplicationException
-
setLastSequenceIds
public 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 interfaceReplicationQueueStorage- Parameters:
peerId- peer idlastSeqIds- map with {encodedRegionName, sequenceId} pairs for serial replication.- Throws:
ReplicationException
-
removeLastSequenceIds
Description copied from interface:ReplicationQueueStorageRemove all the max sequence id record for the given peer.- Specified by:
removeLastSequenceIdsin interfaceReplicationQueueStorage- Parameters:
peerId- peer id- Throws:
ReplicationException
-
removeLastSequenceIds
public 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 interfaceReplicationQueueStorage- Parameters:
peerId- peer idencodedRegionNames- the encoded region names- Throws:
ReplicationException
-
removePeerFromHFileRefs
Description copied from interface:ReplicationQueueStorageRemove a peer from hfile reference queue.- Specified by:
removePeerFromHFileRefsin interfaceReplicationQueueStorage- Parameters:
peerId- peer cluster id to be removed- Throws:
ReplicationException
-
addHFileRefs
public 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 interfaceReplicationQueueStorage- Parameters:
peerId- 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 }- Throws:
ReplicationException- if fails to add a hfile reference
-
removeHFileRefs
Description copied from interface:ReplicationQueueStorageRemove hfile references from the queue.- Specified by:
removeHFileRefsin interfaceReplicationQueueStorage- Parameters:
peerId- peer cluster id from which this hfile references needs to be removedfiles- list of hfile references to be removed- Throws:
ReplicationException
-
getAllPeersFromHFileRefsQueue
Description copied from interface:ReplicationQueueStorageGet list of all peers from hfile reference queue.- Specified by:
getAllPeersFromHFileRefsQueuein interfaceReplicationQueueStorage- Returns:
- a list of peer ids
- Throws:
ReplicationException
-
scanHFiles
private <T extends Collection<String>> T scanHFiles(Scan scan, Supplier<T> creator) throws IOException - Throws:
IOException
-
getReplicableHFiles
Description copied from interface:ReplicationQueueStorageGet a list of all hfile references in the given peer.- Specified by:
getReplicableHFilesin interfaceReplicationQueueStorage- Parameters:
peerId- a String that identifies the peer- Returns:
- a list of hfile references
- Throws:
ReplicationException
-
getAllHFileRefs
Description 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 interfaceReplicationQueueStorage- Throws:
ReplicationException
-
hasData
Description copied from interface:ReplicationQueueStorageWhether the replication queue table exists.- Specified by:
hasDatain interfaceReplicationQueueStorage- Returns:
- Whether the replication queue table exists
- Throws:
ReplicationException
-
batchUpdateQueues
public void batchUpdateQueues(ServerName serverName, List<ReplicationQueueData> datas) throws ReplicationException Description copied from interface:ReplicationQueueStorageUpdate the replication queue datas for a given region server.- Specified by:
batchUpdateQueuesin interfaceReplicationQueueStorage- Throws:
ReplicationException
-
batchUpdateLastSequenceIds
public void batchUpdateLastSequenceIds(List<ZKReplicationQueueStorageForMigration.ZkLastPushedSeqId> lastPushedSeqIds) throws ReplicationException Description copied from interface:ReplicationQueueStorageUpdate last pushed sequence id for the given regions and peers.- Specified by:
batchUpdateLastSequenceIdsin interfaceReplicationQueueStorage- Throws:
ReplicationException
-
batchUpdateHFileRefs
Description copied from interface:ReplicationQueueStorageAdd the given hfile refs to the given peer.- Specified by:
batchUpdateHFileRefsin interfaceReplicationQueueStorage- Throws:
ReplicationException
-
removeLastSequenceIdsAndHFileRefsBefore
Description copied from interface:ReplicationQueueStorageRemove all the last sequence ids and hfile references data which are written before the given timestamp. The data of these two types are not used by replication directly. For last sequence ids, we will check it in serial replication, to make sure that we will replicate all edits in order, so if there are stale data, the worst case is that we will stop replicating as we think we still need to finish previous ranges first, although actually we have already replicated them out. For hfile references, it is just used by hfile cleaner to not remove these hfiles before we replicate them out, so if there are stale data, the worst case is that we can not remove these hfiles, although actually they have already been replicated out. So it is OK for us to just bring up the cluster first, and then use this method to delete the stale data, i.e, the data which are written before a specific timestamp.- Specified by:
removeLastSequenceIdsAndHFileRefsBeforein interfaceReplicationQueueStorage- Throws:
ReplicationException
-