Index: src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestHLog.java =================================================================== --- src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestHLog.java (revision 1154588) +++ src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestHLog.java (working copy) @@ -593,7 +593,7 @@ 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(); @@ -691,7 +691,7 @@ } } - static class DumbWALObserver implements WALObserver { + static class DumbWALActionsListener implements WALActionsListener { int increments = 0; @Override Index: src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestWALActionsListener.java =================================================================== --- src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestWALActionsListener.java (revision 0) +++ src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestWALActionsListener.java (revision 0) @@ -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 list = new ArrayList(); + 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 Index: src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestWALObserver.java =================================================================== --- src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestWALObserver.java (revision 1154588) +++ src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestWALObserver.java (working copy) @@ -1,151 +0,0 @@ -/** - * Copyright 2010 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 TestWALObserver { - protected static final Log LOG = LogFactory.getLog(TestWALObserver.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 { - DummyWALObserver observer = new DummyWALObserver(); - List list = new ArrayList(); - list.add(observer); - DummyWALObserver laterobserver = new DummyWALObserver(); - 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 DummyWALObserver implements WALObserver { - 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 Index: src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceManager.java =================================================================== --- src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceManager.java (revision 1154588) +++ src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceManager.java (working copy) @@ -43,7 +43,7 @@ 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 @@ WALEdit edit = new WALEdit(); edit.add(kv); - List listeners = new ArrayList(); + List listeners = new ArrayList(); listeners.add(replication); HLog hlog = new HLog(fs, logDir, oldLogDir, conf, listeners, URLEncoder.encode("regionserver:60020", "UTF8")); Index: src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java (revision 1154588) +++ src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java (working copy) @@ -117,7 +117,7 @@ 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 @@ /** * 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 getWALActionListeners() { - List listeners = new ArrayList(); + protected List getWALActionListeners() { + List listeners = new ArrayList(); // Log roller. this.hlogRoller = new LogRoller(this, this); listeners.add(this.hlogRoller); Index: src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java (revision 1154588) +++ src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java (working copy) @@ -26,7 +26,7 @@ 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 @@ * 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); Index: src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java (revision 1154588) +++ src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java (working copy) @@ -119,8 +119,8 @@ private final Path dir; private final Configuration conf; // Listeners that are called on WAL events. - private List listeners = - new CopyOnWriteArrayList(); + private List listeners = + new CopyOnWriteArrayList(); private final long optionalFlushInterval; private final long blocksize; private final String prefix; @@ -295,7 +295,7 @@ * @throws IOException */ public HLog(final FileSystem fs, final Path dir, final Path oldLogDir, - final Configuration conf, final List listeners, + final Configuration conf, final List listeners, final String prefix) throws IOException { this(fs, dir, oldLogDir, conf, listeners, true, prefix); } @@ -321,7 +321,7 @@ * @throws IOException */ public HLog(final FileSystem fs, final Path dir, final Path oldLogDir, - final Configuration conf, final List listeners, + final Configuration conf, final List listeners, final boolean failIfLogDirExists, final String prefix) throws IOException { super(); @@ -329,7 +329,7 @@ this.dir = dir; this.conf = conf; if (listeners != null) { - for (WALObserver i: listeners) { + for (WALActionsListener i: listeners) { registerWALActionsListener(i); } } @@ -404,11 +404,11 @@ 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 @@ } // 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 @@ 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 @@ private void requestLogRoll() { if (!this.listeners.isEmpty()) { - for (WALObserver i: this.listeners) { + for (WALActionsListener i: this.listeners) { i.logRollRequested(); } } @@ -1066,7 +1066,7 @@ return; } if (!this.listeners.isEmpty()) { - for (WALObserver i: this.listeners) { + for (WALActionsListener i: this.listeners) { i.visitLogEntryBeforeWrite(htd, logKey, logEdit); } } Index: src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALActionsListener.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALActionsListener.java (revision 0) +++ src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALActionsListener.java (revision 0) @@ -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); + +} Index: src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALObserver.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALObserver.java (revision 1154588) +++ src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALObserver.java (working copy) @@ -1,65 +0,0 @@ -/* - * Copyright 2010 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 WALObserver { - /** - * 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); - -} Index: src/main/java/org/apache/hadoop/hbase/replication/regionserver/Replication.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/replication/regionserver/Replication.java (revision 1154588) +++ src/main/java/org/apache/hadoop/hbase/replication/regionserver/Replication.java (working copy) @@ -34,7 +34,7 @@ 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 @@ /** * 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);