diff --git a/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java index 9b2996c..191ca86 100644 --- a/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ b/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -2214,10 +2214,8 @@ public class HRegion implements HeapSize { // , Writable{ // ------------------------- // STEP 7. Sync wal. // ------------------------- - if (walEdit.size() > 0 && - (this.regionInfo.isMetaRegion() || - !this.htableDescriptor.isDeferredLogFlush())) { - this.log.sync(txid); + if (walEdit.size() > 0) { + syncOrDefer(txid); } walSyncSuccessful = true; // ------------------------------------------------------------------ @@ -4306,10 +4304,8 @@ public class HRegion implements HeapSize { // , Writable{ } // 9. sync WAL if required - if (walEdit.size() > 0 && - (this.regionInfo.isMetaRegion() || - !this.htableDescriptor.isDeferredLogFlush())) { - this.log.sync(txid); + if (walEdit.size() > 0) { + syncOrDefer(txid); } walSyncSuccessful = true; @@ -4507,7 +4503,7 @@ public class HRegion implements HeapSize { // , Writable{ releaseRowLock(lid); } if (writeToWAL) { - this.log.sync(txid); // sync the transaction log outside the rowlock + syncOrDefer(txid); // sync the transaction log outside the rowlock } } finally { closeRegionOperation(); @@ -4628,7 +4624,7 @@ public class HRegion implements HeapSize { // , Writable{ releaseRowLock(lid); } if (writeToWAL) { - this.log.sync(txid); // sync the transaction log outside the rowlock + syncOrDefer(txid); // sync the transaction log outside the rowlock } } finally { closeRegionOperation(); @@ -4725,7 +4721,7 @@ public class HRegion implements HeapSize { // , Writable{ releaseRowLock(lid); } if (writeToWAL) { - this.log.sync(txid); // sync the transaction log outside the rowlock + syncOrDefer(txid); // sync the transaction log outside the rowlock } } finally { closeRegionOperation(); @@ -5138,6 +5134,19 @@ public class HRegion implements HeapSize { // , Writable{ } /** + * Calls sync with the given transaction ID if the region's table is not + * deferring it. + * @param txid should sync up to which transaction + * @throws IOException If anything goes wrong with DFS + */ + private void syncOrDefer(long txid) throws IOException { + if (this.regionInfo.isMetaRegion() || + !this.htableDescriptor.isDeferredLogFlush()) { + this.log.sync(txid); + } + } + + /** * A mocked list implementaion - discards all updates. */ private static final List MOCKED_LIST = new AbstractList() { diff --git a/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java b/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java index f308e6d..dad7f6c 100644 --- a/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java +++ b/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java @@ -1187,10 +1187,14 @@ public class HLog implements Syncable { } /** - * This thread is responsible to call syncFs and buffer up the writers while - * it happens. + * This class is responsible to old the HLog's appended Entry list + * and to sync them according to a configurable interval. + * + * Deferred log flushing works first by piggy backing on this process by + * simply not sync'ing the appended Entry. It can also be sync'd by other + * non-deferred log flushed entries outside of this thread. */ - class LogSyncer extends HasThread { + class LogSyncer extends HasThread { private final long optionalFlushInterval; @@ -1221,6 +1225,9 @@ public class HLog implements Syncable { closeLogSyncer.wait(this.optionalFlushInterval); } } + // Calling sync since we waited or had unflushed entries. + // Entries appended but not sync'd are taken care of here AKA + // deferred log flush sync(); } catch (IOException e) { LOG.error("Error while syncing, requesting close of hlog ", e);