hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From te...@apache.org
Subject svn commit: r1155202 - in /hbase/trunk: ./ src/main/java/org/apache/hadoop/hbase/regionserver/ src/main/java/org/apache/hadoop/hbase/regionserver/wal/ src/main/java/org/apache/hadoop/hbase/replication/regionserver/ src/test/java/org/apache/hadoop/hbase...
Date Tue, 09 Aug 2011 04:39:35 GMT
Author: tedyu
Date: Tue Aug  9 04:39:34 2011
New Revision: 1155202

URL: http://svn.apache.org/viewvc?rev=1155202&view=rev
Log:
HBASE-4152 Rename o.a.h.h.regionserver.wal.WALObserver to o.a.h.h.regionserver.wal.WALActionsListener

Added:
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALActionsListener.java
    hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestWALActionsListener.java
Removed:
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALObserver.java
    hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestWALObserver.java
Modified:
    hbase/trunk/CHANGES.txt
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/replication/regionserver/Replication.java
    hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestHLog.java
    hbase/trunk/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceManager.java

Modified: hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hbase/trunk/CHANGES.txt?rev=1155202&r1=1155201&r2=1155202&view=diff
==============================================================================
--- hbase/trunk/CHANGES.txt (original)
+++ hbase/trunk/CHANGES.txt Tue Aug  9 04:39:34 2011
@@ -378,6 +378,8 @@ Release 0.91.0 - Unreleased
    HBASE-4025  Server startup fails during startup due to failure in loading
                all table descriptors. (Subbu Iyer via Ted Yu)
    HBASE-4017  BlockCache interface should be truly modular (Li Pi)
+   HBASE-4152  Rename o.a.h.h.regionserver.wal.WALObserver to
+               o.a.h.h.regionserver.wal.WALActionsListener
 
   NEW FEATURES
    HBASE-2001  Coprocessors: Colocate user code with regions (Mingjie Lai via

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java?rev=1155202&r1=1155201&r2=1155202&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java Tue
Aug  9 04:39:34 2011
@@ -117,7 +117,7 @@ import org.apache.hadoop.hbase.regionser
 import org.apache.hadoop.hbase.regionserver.handler.OpenRootHandler;
 import org.apache.hadoop.hbase.regionserver.metrics.RegionServerMetrics;
 import org.apache.hadoop.hbase.regionserver.wal.HLog;
-import org.apache.hadoop.hbase.regionserver.wal.WALObserver;
+import org.apache.hadoop.hbase.regionserver.wal.WALActionsListener;
 import org.apache.hadoop.hbase.regionserver.RegionOpeningState;
 import org.apache.hadoop.hbase.replication.regionserver.Replication;
 import org.apache.hadoop.hbase.security.User;
@@ -1167,12 +1167,12 @@ public class HRegionServer implements HR
 
   /**
    * Called by {@link #instantiateHLog(Path, Path)} setting up WAL instance.
-   * Add any {@link WALObserver}s you want inserted before WAL startup.
+   * Add any {@link WALActionsListener}s you want inserted before WAL startup.
    * @return List of WALActionsListener that will be passed in to
    * {@link HLog} on construction.
    */
-  protected List<WALObserver> getWALActionListeners() {
-    List<WALObserver> listeners = new ArrayList<WALObserver>();
+  protected List<WALActionsListener> getWALActionListeners() {
+    List<WALActionsListener> listeners = new ArrayList<WALActionsListener>();
     // Log roller.
     this.hlogRoller = new LogRoller(this, this);
     listeners.add(this.hlogRoller);

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java?rev=1155202&r1=1155201&r2=1155202&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java Tue Aug
 9 04:39:34 2011
@@ -26,7 +26,7 @@ import org.apache.hadoop.hbase.*;
 import org.apache.hadoop.hbase.regionserver.wal.FailedLogCloseException;
 import org.apache.hadoop.hbase.regionserver.wal.HLogKey;
 import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
-import org.apache.hadoop.hbase.regionserver.wal.WALObserver;
+import org.apache.hadoop.hbase.regionserver.wal.WALActionsListener;
 import org.apache.hadoop.hbase.util.Bytes;
 
 import java.io.IOException;
@@ -40,7 +40,7 @@ import java.util.concurrent.locks.Reentr
  * can be interrupted when there is something to do, rather than the Chore
  * sleep time which is invariant.
  */
-class LogRoller extends Thread implements WALObserver {
+class LogRoller extends Thread implements WALActionsListener {
   static final Log LOG = LogFactory.getLog(LogRoller.class);
   private final ReentrantLock rollLock = new ReentrantLock();
   private final AtomicBoolean rollLog = new AtomicBoolean(false);

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java?rev=1155202&r1=1155201&r2=1155202&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java Tue Aug 
9 04:39:34 2011
@@ -119,8 +119,8 @@ public class HLog implements Syncable {
   private final Path dir;
   private final Configuration conf;
   // Listeners that are called on WAL events.
-  private List<WALObserver> listeners =
-    new CopyOnWriteArrayList<WALObserver>();
+  private List<WALActionsListener> listeners =
+    new CopyOnWriteArrayList<WALActionsListener>();
   private final long optionalFlushInterval;
   private final long blocksize;
   private final String prefix;
@@ -295,7 +295,7 @@ public class HLog implements Syncable {
    * @throws IOException
    */
   public HLog(final FileSystem fs, final Path dir, final Path oldLogDir,
-      final Configuration conf, final List<WALObserver> listeners,
+      final Configuration conf, final List<WALActionsListener> listeners,
       final String prefix) throws IOException {
     this(fs, dir, oldLogDir, conf, listeners, true, prefix);
   }
@@ -321,7 +321,7 @@ public class HLog implements Syncable {
    * @throws IOException
    */
   public HLog(final FileSystem fs, final Path dir, final Path oldLogDir,
-      final Configuration conf, final List<WALObserver> listeners,
+      final Configuration conf, final List<WALActionsListener> listeners,
       final boolean failIfLogDirExists, final String prefix)
  throws IOException {
     super();
@@ -329,7 +329,7 @@ public class HLog implements Syncable {
     this.dir = dir;
     this.conf = conf;
     if (listeners != null) {
-      for (WALObserver i: listeners) {
+      for (WALActionsListener i: listeners) {
         registerWALActionsListener(i);
       }
     }
@@ -404,11 +404,11 @@ public class HLog implements Syncable {
     return m;
   }
 
-  public void registerWALActionsListener (final WALObserver listener) {
+  public void registerWALActionsListener(final WALActionsListener listener) {
     this.listeners.add(listener);
   }
 
-  public boolean unregisterWALActionsListener(final WALObserver listener) {
+  public boolean unregisterWALActionsListener(final WALActionsListener listener) {
     return this.listeners.remove(listener);
   }
 
@@ -501,7 +501,7 @@ public class HLog implements Syncable {
       }
       // Tell our listeners that a new log was created
       if (!this.listeners.isEmpty()) {
-        for (WALObserver i : this.listeners) {
+        for (WALActionsListener i : this.listeners) {
           i.logRolled(newPath);
         }
       }
@@ -813,7 +813,7 @@ public class HLog implements Syncable {
     try {
       // Tell our listeners that the log is closing
       if (!this.listeners.isEmpty()) {
-        for (WALObserver i : this.listeners) {
+        for (WALActionsListener i : this.listeners) {
           i.logCloseRequested();
         }
       }
@@ -1053,7 +1053,7 @@ public class HLog implements Syncable {
 
   private void requestLogRoll() {
     if (!this.listeners.isEmpty()) {
-      for (WALObserver i: this.listeners) {
+      for (WALActionsListener i: this.listeners) {
         i.logRollRequested();
       }
     }
@@ -1066,7 +1066,7 @@ public class HLog implements Syncable {
       return;
     }
     if (!this.listeners.isEmpty()) {
-      for (WALObserver i: this.listeners) {
+      for (WALActionsListener i: this.listeners) {
         i.visitLogEntryBeforeWrite(htd, logKey, logEdit);
       }
     }

Added: hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALActionsListener.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALActionsListener.java?rev=1155202&view=auto
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALActionsListener.java
(added)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALActionsListener.java
Tue Aug  9 04:39:34 2011
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2011 The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.regionserver.wal;
+
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hbase.HRegionInfo;
+import org.apache.hadoop.hbase.HTableDescriptor;
+
+/**
+ * Get notification of {@link HLog}/WAL log events. The invocations are inline
+ * so make sure your implementation is fast else you'll slow hbase.
+ */
+public interface WALActionsListener {
+  /**
+   * The WAL was rolled.
+   * @param newFile the path to the new hlog
+   */
+  public void logRolled(Path newFile);
+
+  /**
+   * A request was made that the WAL be rolled.
+   */
+  public void logRollRequested();
+
+  /**
+   * The WAL is about to close.
+   */
+  public void logCloseRequested();
+
+  /**
+  * Called before each write.
+  * @param info
+  * @param logKey
+  * @param logEdit
+  */
+ public void visitLogEntryBeforeWrite(HRegionInfo info, HLogKey logKey,
+   WALEdit logEdit);
+
+  /**
+   *
+   * @param htd
+   * @param logKey
+   * @param logEdit
+   */
+ public void visitLogEntryBeforeWrite(HTableDescriptor htd, HLogKey logKey,
+   WALEdit logEdit);
+
+}

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/replication/regionserver/Replication.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/replication/regionserver/Replication.java?rev=1155202&r1=1155201&r2=1155202&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/replication/regionserver/Replication.java
(original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/replication/regionserver/Replication.java
Tue Aug  9 04:39:34 2011
@@ -34,7 +34,7 @@ import org.apache.hadoop.hbase.Server;
 import org.apache.hadoop.hbase.regionserver.wal.HLog;
 import org.apache.hadoop.hbase.regionserver.wal.HLogKey;
 import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
-import org.apache.hadoop.hbase.regionserver.wal.WALObserver;
+import org.apache.hadoop.hbase.regionserver.wal.WALActionsListener;
 import org.apache.hadoop.hbase.replication.ReplicationZookeeper;
 import org.apache.hadoop.hbase.replication.master.ReplicationLogCleaner;
 import org.apache.hadoop.hbase.util.Bytes;
@@ -47,7 +47,7 @@ import static org.apache.hadoop.hbase.HC
 /**
  * Gateway to Replication.  Used by {@link org.apache.hadoop.hbase.regionserver.HRegionServer}.
  */
-public class Replication implements WALObserver {
+public class Replication implements WALActionsListener {
   private final boolean replication;
   private final ReplicationSourceManager replicationManager;
   private final AtomicBoolean replicating = new AtomicBoolean(true);

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestHLog.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestHLog.java?rev=1155202&r1=1155201&r2=1155202&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestHLog.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestHLog.java Tue Aug
 9 04:39:34 2011
@@ -594,7 +594,7 @@ public class TestHLog  {
     final byte [] tableName = Bytes.toBytes("tablename");
     final byte [] row = Bytes.toBytes("row");
     HLog log = new HLog(fs, dir, oldLogDir, conf);
-    DumbWALObserver visitor = new DumbWALObserver();
+    DumbWALActionsListener visitor = new DumbWALActionsListener();
     log.registerWALActionsListener(visitor);
     long timestamp = System.currentTimeMillis();
     HTableDescriptor htd = new HTableDescriptor();
@@ -692,7 +692,7 @@ public class TestHLog  {
     }
   }
 
-  static class DumbWALObserver implements WALObserver {
+  static class DumbWALActionsListener implements WALActionsListener {
     int increments = 0;
 
     @Override

Added: hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestWALActionsListener.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestWALActionsListener.java?rev=1155202&view=auto
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestWALActionsListener.java
(added)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestWALActionsListener.java
Tue Aug  9 04:39:34 2011
@@ -0,0 +1,151 @@
+/**
+ * Copyright 2011 The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.regionserver.wal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hbase.*;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ * Test that the actions are called while playing with an HLog
+ */
+public class TestWALActionsListener {
+  protected static final Log LOG = LogFactory.getLog(TestWALActionsListener.class);
+
+  private final static HBaseTestingUtility TEST_UTIL =
+      new HBaseTestingUtility();
+
+  private final static byte[] SOME_BYTES =  Bytes.toBytes("t");
+  private static FileSystem fs;
+  private static Path oldLogDir;
+  private static Path logDir;
+  private static Configuration conf;
+
+  @BeforeClass
+  public static void setUpBeforeClass() throws Exception {
+    conf = TEST_UTIL.getConfiguration();
+    conf.setInt("hbase.regionserver.maxlogs", 5);
+    fs = FileSystem.get(conf);
+    oldLogDir = new Path(HBaseTestingUtility.getTestDir(),
+        HConstants.HREGION_OLDLOGDIR_NAME);
+    logDir = new Path(HBaseTestingUtility.getTestDir(),
+        HConstants.HREGION_LOGDIR_NAME);
+  }
+
+  @Before
+  public void setUp() throws Exception {
+    fs.delete(logDir, true);
+    fs.delete(oldLogDir, true);
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    setUp();
+  }
+
+  /**
+   * Add a bunch of dummy data and roll the logs every two insert. We
+   * should end up with 10 rolled files (plus the roll called in
+   * the constructor). Also test adding a listener while it's running.
+   */
+  @Test
+  public void testActionListener() throws Exception {
+    DummyWALActionsListener observer = new DummyWALActionsListener();
+    List<WALActionsListener> list = new ArrayList<WALActionsListener>();
+    list.add(observer);
+    DummyWALActionsListener laterobserver = new DummyWALActionsListener();
+    HLog hlog = new HLog(fs, logDir, oldLogDir, conf, list, null);
+    HRegionInfo hri = new HRegionInfo(SOME_BYTES,
+             SOME_BYTES, SOME_BYTES, false);
+
+    for (int i = 0; i < 20; i++) {
+      byte[] b = Bytes.toBytes(i+"");
+      KeyValue kv = new KeyValue(b,b,b);
+      WALEdit edit = new WALEdit();
+      edit.add(kv);
+      HTableDescriptor htd = new HTableDescriptor();
+      htd.addFamily(new HColumnDescriptor(b));
+
+      HLogKey key = new HLogKey(b,b, 0, 0);
+      hlog.append(hri, key, edit, htd);
+      if (i == 10) {
+        hlog.registerWALActionsListener(laterobserver);
+      }
+      if (i % 2 == 0) {
+        hlog.rollWriter();
+      }
+    }
+
+    hlog.close();
+    hlog.closeAndDelete();
+
+    assertEquals(11, observer.logRollCounter);
+    assertEquals(5, laterobserver.logRollCounter);
+    assertEquals(2, observer.closedCount);
+  }
+
+
+  /**
+   * Just counts when methods are called
+   */
+  static class DummyWALActionsListener implements WALActionsListener {
+    public int logRollCounter = 0;
+    public int closedCount = 0;
+
+    @Override
+    public void logRolled(Path newFile) {
+      logRollCounter++;
+    }
+
+    @Override
+    public void logRollRequested() {
+      // Not interested
+    }
+
+    @Override
+    public void visitLogEntryBeforeWrite(HRegionInfo info, HLogKey logKey,
+        WALEdit logEdit) {
+      // Not interested
+
+    }
+
+    @Override
+    public void logCloseRequested() {
+      closedCount++;
+    }
+
+    public void visitLogEntryBeforeWrite(HTableDescriptor htd, HLogKey logKey, WALEdit logEdit)
{
+      //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+  }
+}
\ No newline at end of file

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceManager.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceManager.java?rev=1155202&r1=1155201&r2=1155202&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceManager.java
(original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceManager.java
Tue Aug  9 04:39:34 2011
@@ -43,7 +43,7 @@ import org.apache.hadoop.hbase.catalog.C
 import org.apache.hadoop.hbase.regionserver.wal.HLog;
 import org.apache.hadoop.hbase.regionserver.wal.HLogKey;
 import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
-import org.apache.hadoop.hbase.regionserver.wal.WALObserver;
+import org.apache.hadoop.hbase.regionserver.wal.WALActionsListener;
 import org.apache.hadoop.hbase.replication.ReplicationSourceDummy;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.zookeeper.ZKUtil;
@@ -156,7 +156,7 @@ public class TestReplicationSourceManage
     WALEdit edit = new WALEdit();
     edit.add(kv);
 
-    List<WALObserver> listeners = new ArrayList<WALObserver>();
+    List<WALActionsListener> listeners = new ArrayList<WALActionsListener>();
     listeners.add(replication);
     HLog hlog = new HLog(fs, logDir, oldLogDir, conf, listeners,
       URLEncoder.encode("regionserver:60020", "UTF8"));



Mime
View raw message