hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From te...@apache.org
Subject hbase git commit: HBASE-18099 FlushSnapshotSubprocedure should wait for concurrent Region#flush() to finish
Date Thu, 25 May 2017 14:56:20 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1 a3c3f1012 -> 109e0d548


HBASE-18099 FlushSnapshotSubprocedure should wait for concurrent Region#flush() to finish


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/109e0d54
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/109e0d54
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/109e0d54

Branch: refs/heads/branch-1
Commit: 109e0d5485af3abf6914c8c782c3700477f47646
Parents: a3c3f10
Author: tedyu <yuzhihong@gmail.com>
Authored: Thu May 25 07:56:13 2017 -0700
Committer: tedyu <yuzhihong@gmail.com>
Committed: Thu May 25 07:56:13 2017 -0700

----------------------------------------------------------------------
 .../hadoop/hbase/regionserver/HRegion.java      | 31 ++++++++++++++++++++
 .../hadoop/hbase/regionserver/Region.java       |  3 ++
 .../snapshot/FlushSnapshotSubprocedure.java     |  8 ++++-
 3 files changed, 41 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/109e0d54/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
----------------------------------------------------------------------
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 4089a2e..ff96822 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
@@ -1678,6 +1678,37 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver,
Regi
     }
   }
 
+  @Override
+  public void waitForFlushes() {
+    synchronized (writestate) {
+      if (this.writestate.readOnly) {
+        // we should not wait for replayed flushed if we are read only (for example in case
the
+        // region is a secondary replica).
+        return;
+      }
+      if (!writestate.flushing) return;
+      long start = System.currentTimeMillis();
+      boolean interrupted = false;
+      try {
+        while (writestate.flushing) {
+          LOG.debug("waiting for cache flush to complete for region " + this);
+          try {
+            writestate.wait();
+          } catch (InterruptedException iex) {
+            // essentially ignore and propagate the interrupt back up
+            LOG.warn("Interrupted while waiting");
+            interrupted = true;
+          }
+        }
+      } finally {
+        if (interrupted) {
+          Thread.currentThread().interrupt();
+        }
+      }
+      long duration = System.currentTimeMillis() - start;
+      LOG.debug("Waited " + duration + " ms for flush to complete");
+    }
+  }
   protected ThreadPoolExecutor getStoreOpenAndCloseThreadPool(
       final String threadNamePrefix) {
     int numStores = Math.max(1, this.htableDescriptor.getFamilies().size());

http://git-wip-us.apache.org/repos/asf/hbase/blob/109e0d54/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/Region.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/Region.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/Region.java
index 35e2b35..d4d971e 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/Region.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/Region.java
@@ -718,4 +718,7 @@ public interface Region extends ConfigurationObserver {
   /** Wait for all current flushes and compactions of the region to complete */
   void waitForFlushesAndCompactions();
 
+  /** Wait for all current flushes of the region to complete
+   */
+  void waitForFlushes();
 }

http://git-wip-us.apache.org/repos/asf/hbase/blob/109e0d54/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/snapshot/FlushSnapshotSubprocedure.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/snapshot/FlushSnapshotSubprocedure.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/snapshot/FlushSnapshotSubprocedure.java
index 619248e..5b82a08 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/snapshot/FlushSnapshotSubprocedure.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/snapshot/FlushSnapshotSubprocedure.java
@@ -31,6 +31,7 @@ import org.apache.hadoop.hbase.procedure.Subprocedure;
 import org.apache.hadoop.hbase.protobuf.generated.SnapshotProtos.SnapshotDescription;
 import org.apache.hadoop.hbase.regionserver.HRegion;
 import org.apache.hadoop.hbase.regionserver.Region;
+import org.apache.hadoop.hbase.regionserver.Region.FlushResult;
 import org.apache.hadoop.hbase.regionserver.snapshot.RegionServerSnapshotManager.SnapshotSubprocedurePool;
 import org.apache.hadoop.hbase.snapshot.ClientSnapshotDescriptionUtils;
 
@@ -95,7 +96,12 @@ public class FlushSnapshotSubprocedure extends Subprocedure {
           LOG.debug("take snapshot without flush memstore first");
         } else {
           LOG.debug("Flush Snapshotting region " + region.toString() + " started...");
-          region.flush(true);
+          FlushResult res = region.flush(true);
+          if (res.getResult() == FlushResult.Result.CANNOT_FLUSH) {
+            // CANNOT_FLUSH may mean that a flush is already on-going
+            // we need to wait for that flush to complete
+            region.waitForFlushes();
+          }
         }
         ((HRegion)region).addRegionToSnapshot(snapshot, monitor);
         if (snapshotSkipFlush) {


Mime
View raw message