From 02c22a449f527d4e24e7b03053efd55037a5229e Mon Sep 17 00:00:00 2001 From: larsh Date: Sat, 6 Apr 2013 03:18:27 +0000 Subject: [PATCH] HBASE-8208 In some situations data is not replicated to slaves when deferredLogSync is enabled (Jeffrey Zhong) git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1465176 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop/hbase/regionserver/HRegion.java | 16 ++++++++++++++-- .../hadoop/hbase/regionserver/wal/FSHLog.java | 10 +++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java index 843f69a9b6e..99d1dad9e69 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -1447,6 +1447,12 @@ public class HRegion implements HeapSize { // , Writable{ status.setStatus(s); LOG.debug(s); + // sync unflushed WAL changes when deferred log sync is enabled + // see HBASE-8208 for details + if (wal != null && isDeferredLogSyncEnabled()) { + wal.sync(); + } + // wait for all in-progress transactions to commit to HLog before // we can start the flush. This prevents // uncommitted transactions from being written into HFiles. @@ -5333,12 +5339,18 @@ public class HRegion implements HeapSize { // , Writable{ * @throws IOException If anything goes wrong with DFS */ private void syncOrDefer(long txid) throws IOException { - if (this.getRegionInfo().isMetaRegion() || - !this.htableDescriptor.isDeferredLogFlush() || this.deferredLogSyncDisabled) { + if (this.getRegionInfo().isMetaRegion() || !isDeferredLogSyncEnabled()) { this.log.sync(txid); } } + /** + * check if current region is deferred sync enabled. + */ + private boolean isDeferredLogSyncEnabled() { + return (this.htableDescriptor.isDeferredLogFlush() && !this.deferredLogSyncDisabled); + } + /** * A mocked list implementaion - discards all updates. */ 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 dd7d37dcba7..a375c8b8a0b 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 @@ -1071,6 +1071,11 @@ class FSHLog implements HLog, Syncable { // sync all transactions upto the specified txid private void syncer(long txid) throws IOException { + // if the transaction that we are interested in is already + // synced, then return immediately. + if (txid <= this.syncedTillHere) { + return; + } Writer tempWriter; synchronized (this.updateLock) { if (this.closed) return; @@ -1080,11 +1085,6 @@ class FSHLog implements HLog, Syncable { // See HBASE-4387, HBASE-5623, HBASE-7329. tempWriter = this.writer; } - // if the transaction that we are interested in is already - // synced, then return immediately. - if (txid <= this.syncedTillHere) { - return; - } try { long doneUpto; long now = EnvironmentEdgeManager.currentTimeMillis();