diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java index bc059ed..54447d8 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java @@ -1323,9 +1323,8 @@ class FSHLog implements HLog, Syncable { syncCount += releaseSyncFuture(takeSyncFuture, currentSequence, t); // Can we release other syncs? syncCount += releaseSyncFutures(currentSequence, t); - if (t != null) { - requestLogRoll(); - } else checkLogRoll(); + if (t != null) requestLogRoll(); + else checkLogRoll(); } postSync(System.nanoTime() - start, syncCount); } catch (InterruptedException e) { @@ -1339,16 +1338,30 @@ class FSHLog implements HLog, Syncable { } /** + * Last time we ran the check for low replica count. + */ + private long lastCheckForLowReplication = 0; + // Every second + private static int INTERVAL = 1000000 * 1000; + + /** * Schedule a log roll if needed. */ void checkLogRoll() { - // Will return immediately if we are in the middle of a WAL log roll currently. - if (!rollWriterLock.tryLock()) return; - boolean lowReplication; - try { - lowReplication = checkLowReplication(); - } finally { - rollWriterLock.unlock(); + boolean lowReplication = false; + // Only check for low replica count every second or so because it costs especially when + // high contention where threads pile up on the synchronized getCurrentBlockReplication in + // DFSOutputStream. Nano time is a bit dodgy but should be fine for this coarse a measurement. + long now = System.nanoTime(); + if ((this.lastCheckForLowReplication + INTERVAL) < now) { + this.lastCheckForLowReplication = now; + // Will return immediately if we are in the middle of a WAL log roll currently. + if (!rollWriterLock.tryLock()) return; + try { + lowReplication = checkLowReplication(); + } finally { + rollWriterLock.unlock(); + } } try { if (lowReplication || writer != null && writer.getLength() > logrollsize) requestLogRoll();