hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bus...@apache.org
Subject hbase git commit: HBASE-15481 Add pre/post roll to WALObserver
Date Wed, 13 Apr 2016 06:31:56 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1.3 e2ed4fd75 -> 7e00a562a


HBASE-15481 Add pre/post roll to WALObserver

Signed-off-by: Sean Busbey <busbey@apache.org>

 Conflicts:
	hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/AbstractFSWAL.java


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

Branch: refs/heads/branch-1.3
Commit: 7e00a562abe5c48d099595c960ed6961b0ef12b4
Parents: e2ed4fd
Author: Matteo Bertozzi <matteo.bertozzi@cloudera.com>
Authored: Wed Apr 13 00:43:39 2016 -0500
Committer: Sean Busbey <busbey@apache.org>
Committed: Wed Apr 13 01:13:27 2016 -0500

----------------------------------------------------------------------
 .../hbase/coprocessor/BaseWALObserver.java      |  9 +++
 .../hadoop/hbase/coprocessor/WALObserver.java   | 18 ++++++
 .../hadoop/hbase/regionserver/wal/FSHLog.java   |  4 ++
 .../regionserver/wal/WALCoprocessorHost.java    | 65 +++++++++++++++++++-
 .../coprocessor/SampleRegionWALObserver.java    | 25 ++++++++
 .../hbase/coprocessor/TestWALObserver.java      | 14 +++++
 6 files changed, 134 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/7e00a562/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/BaseWALObserver.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/BaseWALObserver.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/BaseWALObserver.java
index cfddcd4..1d0076a 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/BaseWALObserver.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/BaseWALObserver.java
@@ -20,6 +20,7 @@ package org.apache.hadoop.hbase.coprocessor;
 
 import java.io.IOException;
 
+import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.hbase.classification.InterfaceAudience;
 import org.apache.hadoop.hbase.classification.InterfaceStability;
 import org.apache.hadoop.hbase.CoprocessorEnvironment;
@@ -70,4 +71,12 @@ public class BaseWALObserver implements WALObserver {
       HLogKey logKey, WALEdit logEdit) throws IOException {
     postWALWrite(ctx, info, (WALKey)logKey, logEdit);
   }
+
+  @Override
+  public void preWALRoll(ObserverContext<? extends WALCoprocessorEnvironment> ctx,
+      Path oldPath, Path newPath) throws IOException { }
+
+  @Override
+  public void postWALRoll(ObserverContext<? extends WALCoprocessorEnvironment> ctx,
+      Path oldPath, Path newPath) throws IOException { }
 }

http://git-wip-us.apache.org/repos/asf/hbase/blob/7e00a562/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/WALObserver.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/WALObserver.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/WALObserver.java
index bba83cc..7fd03ce 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/WALObserver.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/WALObserver.java
@@ -19,6 +19,7 @@
 
 package org.apache.hadoop.hbase.coprocessor;
 
+import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.hbase.classification.InterfaceAudience;
 import org.apache.hadoop.hbase.classification.InterfaceStability;
 import org.apache.hadoop.hbase.Coprocessor;
@@ -112,4 +113,21 @@ public interface WALObserver extends Coprocessor {
   @Deprecated
   void postWALWrite(ObserverContext<WALCoprocessorEnvironment> ctx,
       HRegionInfo info, HLogKey logKey, WALEdit logEdit) throws IOException;
+
+  /**
+   * Called before rolling the current WAL
+   * @param oldPath the path of the current wal that we are replacing
+   * @param newPath the path of the wal we are going to create
+   */
+  void preWALRoll(ObserverContext<? extends WALCoprocessorEnvironment> ctx,
+      Path oldPath, Path newPath) throws IOException;
+
+  /**
+   * Called after rolling the current WAL
+   * @param oldPath the path of the wal that we replaced
+   * @param newPath the path of the wal we have created and now is the current
+   */
+  void postWALRoll(ObserverContext<? extends WALCoprocessorEnvironment> ctx,
+      Path oldPath, Path newPath) throws IOException;
 }
+

http://git-wip-us.apache.org/repos/asf/hbase/blob/7e00a562/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java
----------------------------------------------------------------------
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 c01cc1c..070ba3b 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
@@ -630,6 +630,8 @@ public class FSHLog implements WAL {
    */
   private void tellListenersAboutPreLogRoll(final Path oldPath, final Path newPath)
   throws IOException {
+    coprocessorHost.preWALRoll(oldPath, newPath);
+
     if (!this.listeners.isEmpty()) {
       for (WALActionsListener i : this.listeners) {
         i.preLogRoll(oldPath, newPath);
@@ -648,6 +650,8 @@ public class FSHLog implements WAL {
         i.postLogRoll(oldPath, newPath);
       }
     }
+
+    coprocessorHost.postWALRoll(oldPath, newPath);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/hbase/blob/7e00a562/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALCoprocessorHost.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALCoprocessorHost.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALCoprocessorHost.java
index 71cbe57..87019e8 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALCoprocessorHost.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALCoprocessorHost.java
@@ -23,6 +23,7 @@ package org.apache.hadoop.hbase.regionserver.wal;
 import java.io.IOException;
 import java.util.List;
 
+import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.hbase.Coprocessor;
 import org.apache.hadoop.hbase.HRegionInfo;
 import org.apache.hadoop.hbase.coprocessor.*;
@@ -38,7 +39,7 @@ import org.apache.hadoop.hbase.wal.WALKey;
 @InterfaceAudience.Private
 public class WALCoprocessorHost
     extends CoprocessorHost<WALCoprocessorHost.WALEnvironment> {
-  
+
   /**
    * Encapsulation of the environment of each coprocessor
    */
@@ -195,4 +196,66 @@ public class WALCoprocessorHost
       }
     }
   }
+
+  /**
+   * Called before rolling the current WAL
+   * @param oldPath the path of the current wal that we are replacing
+   * @param newPath the path of the wal we are going to create
+   */
+  public void preWALRoll(Path oldPath, Path newPath) throws IOException {
+    if (this.coprocessors == null || this.coprocessors.isEmpty()) return;
+    ObserverContext<WALCoprocessorEnvironment> ctx = null;
+    List<WALEnvironment> envs = coprocessors.get();
+    for (int i = 0; i < envs.size(); i++) {
+      WALEnvironment env = envs.get(i);
+      if (env.getInstance() instanceof WALObserver) {
+        final WALObserver observer = (WALObserver)env.getInstance();
+        ctx = ObserverContext.createAndPrepare(env, ctx);
+        Thread currentThread = Thread.currentThread();
+        ClassLoader cl = currentThread.getContextClassLoader();
+        try {
+          currentThread.setContextClassLoader(env.getClassLoader());
+          observer.preWALRoll(ctx, oldPath, newPath);
+        } catch (Throwable e) {
+          handleCoprocessorThrowable(env, e);
+        } finally {
+          currentThread.setContextClassLoader(cl);
+        }
+        if (ctx.shouldComplete()) {
+          break;
+        }
+      }
+    }
+  }
+
+  /**
+   * Called after rolling the current WAL
+   * @param oldPath the path of the wal that we replaced
+   * @param newPath the path of the wal we have created and now is the current
+   */
+  public void postWALRoll(Path oldPath, Path newPath) throws IOException {
+    if (this.coprocessors == null || this.coprocessors.isEmpty()) return;
+    ObserverContext<WALCoprocessorEnvironment> ctx = null;
+    List<WALEnvironment> envs = coprocessors.get();
+    for (int i = 0; i < envs.size(); i++) {
+      WALEnvironment env = envs.get(i);
+      if (env.getInstance() instanceof WALObserver) {
+        final WALObserver observer = (WALObserver)env.getInstance();
+        ctx = ObserverContext.createAndPrepare(env, ctx);
+        Thread currentThread = Thread.currentThread();
+        ClassLoader cl = currentThread.getContextClassLoader();
+        try {
+          currentThread.setContextClassLoader(env.getClassLoader());
+          observer.postWALRoll(ctx, oldPath, newPath);
+        } catch (Throwable e) {
+          handleCoprocessorThrowable(env, e);
+        } finally {
+          currentThread.setContextClassLoader(cl);
+        }
+        if (ctx.shouldComplete()) {
+          break;
+        }
+      }
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/hbase/blob/7e00a562/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/SampleRegionWALObserver.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/SampleRegionWALObserver.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/SampleRegionWALObserver.java
index d7852f1..da262ee 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/SampleRegionWALObserver.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/SampleRegionWALObserver.java
@@ -23,6 +23,7 @@ import java.io.IOException;
 import java.util.List;
 import java.util.Arrays;
 
+import org.apache.hadoop.fs.Path;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -60,6 +61,8 @@ implements WALObserver {
   private boolean postWALWriteCalled = false;
   private boolean preWALRestoreCalled = false;
   private boolean postWALRestoreCalled = false;
+  private boolean preWALRollCalled = false;
+  private boolean postWALRollCalled = false;
 
   // Deprecated versions
   private boolean preWALWriteDeprecatedCalled = false;
@@ -89,6 +92,8 @@ implements WALObserver {
     postWALWriteDeprecatedCalled = false;
     preWALRestoreDeprecatedCalled = false;
     postWALRestoreDeprecatedCalled = false;
+    preWALRollCalled = false;
+    postWALRollCalled = false;
   }
 
   @Override
@@ -167,6 +172,18 @@ implements WALObserver {
     preWALRestore(env, info, (WALKey)logKey, logEdit);
   }
 
+  @Override
+  public void preWALRoll(ObserverContext<? extends WALCoprocessorEnvironment> ctx,
+      Path oldPath, Path newPath) throws IOException {
+    preWALRollCalled = true;
+  }
+
+  @Override
+  public void postWALRoll(ObserverContext<? extends WALCoprocessorEnvironment> ctx,
+      Path oldPath, Path newPath) throws IOException {
+    postWALRollCalled = true;
+  }
+
   /**
    * Triggered after {@link org.apache.hadoop.hbase.regionserver.HRegion} when WAL is
    * Restoreed.
@@ -220,6 +237,14 @@ implements WALObserver {
     return postWALRestoreDeprecatedCalled;
   }
 
+  public boolean isPreWALRollCalled() {
+    return preWALRollCalled;
+  }
+
+  public boolean isPostWALRollCalled() {
+    return postWALRollCalled;
+  }
+
   /**
    * This class should trigger our legacy support since it does not directly implement the
    * newer API methods.

http://git-wip-us.apache.org/repos/asf/hbase/blob/7e00a562/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestWALObserver.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestWALObserver.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestWALObserver.java
index 95e77a4..c7a6a0c 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestWALObserver.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestWALObserver.java
@@ -450,6 +450,20 @@ public class TestWALObserver {
     assertNotNull(getCoprocessor(log, SampleRegionWALObserver.class));
   }
 
+  @Test
+  public void testWALObserverRoll() throws Exception {
+    final WAL wal = wals.getWAL(UNSPECIFIED_REGION, null);
+    final SampleRegionWALObserver cp = getCoprocessor(wal, SampleRegionWALObserver.class);
+    cp.setTestValues(TEST_TABLE, null, null, null, null, null, null, null);
+
+    assertFalse(cp.isPreWALRollCalled());
+    assertFalse(cp.isPostWALRollCalled());
+
+    wal.rollWriter(true);
+    assertTrue(cp.isPreWALRollCalled());
+    assertTrue(cp.isPostWALRollCalled());
+  }
+
   private SampleRegionWALObserver getCoprocessor(WAL wal,
       Class<? extends SampleRegionWALObserver> clazz) throws Exception {
     WALCoprocessorHost host = wal.getCoprocessorHost();


Mime
View raw message