Skip to content

Commit 259d1bd

Browse files
committed
HBASE-27881 The sleep time in checkQuota of replication WAL reader should be controlled independently
1 parent 22526a6 commit 259d1bd

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSourceManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ private long addTotalBufferUsed(long size) {
11951195
boolean checkBufferQuota(String peerId) {
11961196
// try not to go over total quota
11971197
if (totalBufferUsed.get() > totalBufferLimit) {
1198-
LOG.warn("peer={}, can't read more edits from WAL as buffer usage {}B exceeds limit {}B",
1198+
LOG.debug("peer={}, can't read more edits from WAL as buffer usage {}B exceeds limit {}B",
11991199
peerId, totalBufferUsed.get(), totalBufferLimit);
12001200
return false;
12011201
}

hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSourceWALReader.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.apache.hadoop.hbase.CellUtil;
3131
import org.apache.hadoop.hbase.KeyValue;
3232
import org.apache.hadoop.hbase.replication.WALEntryFilter;
33+
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
3334
import org.apache.hadoop.hbase.util.Pair;
3435
import org.apache.hadoop.hbase.util.Threads;
3536
import org.apache.hadoop.hbase.wal.WAL.Entry;
@@ -69,6 +70,9 @@ class ReplicationSourceWALReader extends Thread {
6970
// position in the WAL to start reading at
7071
private long currentPosition;
7172
private final long sleepForRetries;
73+
private final long sleepForQuotaCheck;
74+
75+
private final long logQuotaThrottleInterval;
7276
private final int maxRetriesMultiplier;
7377

7478
// Indicates whether this particular worker is running
@@ -102,6 +106,10 @@ public ReplicationSourceWALReader(FileSystem fs, Configuration conf,
102106
int batchCount = conf.getInt("replication.source.nb.batches", 1);
103107
// 1 second
104108
this.sleepForRetries = this.conf.getLong("replication.source.sleepforretries", 1000);
109+
// 300ms
110+
this.sleepForQuotaCheck = this.conf.getLong("replication.source.sleepforquotacheck", 300);
111+
this.logQuotaThrottleInterval =
112+
this.conf.getLong("replication.source.logintervalforquotathrottle.ms", 3000);
105113
// 5 minutes @ 1 sec per
106114
this.maxRetriesMultiplier = this.conf.getInt("replication.source.maxretriesmultiplier", 300);
107115
this.entryBatchQueue = new LinkedBlockingQueue<>(batchCount);
@@ -140,9 +148,7 @@ public void run() {
140148
Threads.sleep(sleepForRetries);
141149
continue;
142150
}
143-
if (!checkBufferQuota()) {
144-
continue;
145-
}
151+
blockUntilFreeBufferQuota();
146152
Path currentPath = entryStream.getCurrentPath();
147153
WALEntryStream.HasNext hasNext = entryStream.hasNext();
148154
if (hasNext == WALEntryStream.HasNext.NO) {
@@ -267,13 +273,20 @@ public Path getCurrentPath() {
267273
}
268274

269275
// returns false if we've already exceeded the global quota
270-
private boolean checkBufferQuota() {
276+
private void blockUntilFreeBufferQuota() {
271277
// try not to go over total quota
272-
if (!this.getSourceManager().checkBufferQuota(this.source.getPeerId())) {
273-
Threads.sleep(sleepForRetries);
274-
return false;
278+
long current = EnvironmentEdgeManager.currentTime();
279+
while (
280+
!this.getSourceManager().checkBufferQuota(this.source.getPeerId()) && isReaderRunning()
281+
) {
282+
if (EnvironmentEdgeManager.currentTime() - current >= logQuotaThrottleInterval) {
283+
LOG.warn(
284+
"peer={}, source reader check buffer quota failed, current wal is {}, will sleep {}ms for next retry",
285+
this.source.getPeerId(), this.getCurrentPath(), sleepForQuotaCheck);
286+
}
287+
Threads.sleep(sleepForQuotaCheck);
288+
current = EnvironmentEdgeManager.currentTime();
275289
}
276-
return true;
277290
}
278291

279292
private WALEntryBatch createBatch(WALEntryStream entryStream) {

0 commit comments

Comments
 (0)