HBASE-12655 WALPerformanceEvaluation should only add stat gathering listener once per WAL.

This commit is contained in:
Sean Busbey 2014-12-08 10:12:27 -06:00
parent 2372739e46
commit d2d6945e89
3 changed files with 64 additions and 27 deletions

View File

@ -41,6 +41,9 @@ import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
/**
* A Write Ahead Log (WAL) provides service for reading, writing waledits. This interface provides
* APIs for WAL users (such as RegionServer) to use the WAL (do append, sync, etc).
*
* Note that some internals, such as log rolling and performance evaluation tools, will use
* WAL.equals to determine if they have already seen a given WAL.
*/
@InterfaceAudience.Private
@InterfaceStability.Evolving

View File

@ -19,9 +19,14 @@
package org.apache.hadoop.hbase.wal;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.commons.logging.Log;
@ -329,4 +334,26 @@ public class TestDefaultWALProvider {
new String [] {"-threads", "3", "-verify", "-noclosefs", "-iterations", "3000"});
assertEquals(0, errCode);
}
/**
* Ensure that we can use Set.add to deduplicate WALs
*/
@Test
public void setMembershipDedups() throws IOException {
final Configuration localConf = new Configuration(conf);
localConf.set(WALFactory.WAL_PROVIDER, DefaultWALProvider.class.getName());
final WALFactory wals = new WALFactory(localConf, null, currentTest.getMethodName());
try {
final Set<WAL> seen = new HashSet<WAL>(1);
final Random random = new Random();
assertTrue("first attempt to add WAL from default provider should work.",
seen.add(wals.getWAL(Bytes.toBytes(random.nextInt()))));
for (int i = 0; i < 1000; i++) {
assertFalse("default wal provider is only supposed to return a single wal, which should " +
"compare as .equals itself.", seen.add(wals.getWAL(Bytes.toBytes(random.nextInt()))));
}
} finally {
wals.close();
}
}
}

View File

@ -21,9 +21,11 @@ package org.apache.hadoop.hbase.wal;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
@ -460,12 +462,16 @@ public final class WALPerformanceEvaluation extends Configured implements Tool {
System.exit(1);
}
private final Set<WAL> walsListenedTo = new HashSet<WAL>();
private HRegion openRegion(final FileSystem fs, final Path dir, final HTableDescriptor htd,
final WALFactory wals, final long whenToRoll) throws IOException {
// Initialize HRegion
HRegionInfo regionInfo = new HRegionInfo(htd.getTableName());
// Initialize WAL
final WAL wal = wals.getWAL(regionInfo.getEncodedNameAsBytes());
// If we haven't already, attach a listener to this wal to handle rolls and metrics.
if (walsListenedTo.add(wal)) {
wal.registerWALActionsListener(new WALActionsListener.Base() {
private int appends = 0;
@ -497,6 +503,7 @@ public final class WALPerformanceEvaluation extends Configured implements Tool {
}
});
wal.rollWriter();
}
return HRegion.createHRegion(regionInfo, dir, getConf(), htd, wal);
}