@InterfaceAudience.Private class SerialReplicationChecker extends Object
Helper class to determine whether we can push a given WAL entry without breaking the replication
order. The class is designed to per ReplicationSourceWALReader
, so not thread safe.
We record all the open sequence number for a region in a special family in meta, which is called 'rep_barrier', so there will be a sequence of open sequence number (b1, b2, b3, ...). We call [bn, bn+1) a range, and it is obvious that a region will always be on the same RS within a range.
When split and merge, we will also record the parent for the generated region(s) in the special family in meta. And also, we will write an extra 'open sequence number' for the parent region(s), which is the max sequence id of the region plus one.
For each peer, we record the last pushed sequence id for each region. It is managed by the replication storage.
The algorithm works like this:
And for performance reason, we do not want to check meta for every WAL entry, so we introduce two in memory maps. The idea is simple:
canPushUnder
map.canPushUnder
map. If
the sequence id of WAL entry is less the one stored in canPushUnder
map, then we are safe
to push.pushed
map.pushed
map plus
one. If so, we are safe to push, and also update the pushed
map with the sequence id of
the WAL entry.Modifier and Type | Field and Description |
---|---|
private org.apache.hbase.thirdparty.com.google.common.cache.Cache<String,Long> |
canPushUnder |
private Connection |
conn |
private static org.slf4j.Logger |
LOG |
private String |
peerId |
private org.apache.hbase.thirdparty.com.google.common.cache.LoadingCache<String,org.apache.commons.lang3.mutable.MutableLong> |
pushed |
static long |
REPLICATION_SERIALLY_WAITING_DEFAULT |
static String |
REPLICATION_SERIALLY_WAITING_KEY |
private ReplicationQueueStorage |
storage |
private long |
waitTimeMs |
Constructor and Description |
---|
SerialReplicationChecker(org.apache.hadoop.conf.Configuration conf,
ReplicationSource source) |
Modifier and Type | Method and Description |
---|---|
private boolean |
canPush(WAL.Entry entry,
byte[] row) |
boolean |
canPush(WAL.Entry entry,
Cell firstCellInEdit) |
private boolean |
isLastRangeAndOpening(MetaTableAccessor.ReplicationBarrierResult barrierResult,
int index) |
private boolean |
isParentFinished(byte[] regionName) |
private boolean |
isRangeFinished(long endBarrier,
String encodedRegionName) |
private void |
recordCanPush(String encodedNameAsString,
long seqId,
long[] barriers,
int index) |
void |
waitUntilCanPush(WAL.Entry entry,
Cell firstCellInEdit) |
private static final org.slf4j.Logger LOG
public static final String REPLICATION_SERIALLY_WAITING_KEY
public static final long REPLICATION_SERIALLY_WAITING_DEFAULT
private final ReplicationQueueStorage storage
private final Connection conn
private final long waitTimeMs
private final org.apache.hbase.thirdparty.com.google.common.cache.LoadingCache<String,org.apache.commons.lang3.mutable.MutableLong> pushed
private final org.apache.hbase.thirdparty.com.google.common.cache.Cache<String,Long> canPushUnder
public SerialReplicationChecker(org.apache.hadoop.conf.Configuration conf, ReplicationSource source)
private boolean isRangeFinished(long endBarrier, String encodedRegionName) throws IOException
IOException
private boolean isParentFinished(byte[] regionName) throws IOException
IOException
private boolean isLastRangeAndOpening(MetaTableAccessor.ReplicationBarrierResult barrierResult, int index)
private void recordCanPush(String encodedNameAsString, long seqId, long[] barriers, int index)
private boolean canPush(WAL.Entry entry, byte[] row) throws IOException
IOException
public boolean canPush(WAL.Entry entry, Cell firstCellInEdit) throws IOException
IOException
public void waitUntilCanPush(WAL.Entry entry, Cell firstCellInEdit) throws IOException, InterruptedException
IOException
InterruptedException
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.