You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2012/07/12 22:56:29 UTC
svn commit: r1360937 -
/hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java
Author: stack
Date: Thu Jul 12 20:56:29 2012
New Revision: 1360937
URL: http://svn.apache.org/viewvc?rev=1360937&view=rev
Log:
HBASE-6334 TestImprovement for TestHRegion.testWritesWhileGetting
Modified:
hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java
Modified: hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java?rev=1360937&r1=1360936&r2=1360937&view=diff
==============================================================================
--- hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java (original)
+++ hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java Thu Jul 12 20:56:29 2012
@@ -52,6 +52,7 @@ import org.apache.hadoop.hbase.MediumTes
import org.apache.hadoop.hbase.MiniHBaseCluster;
import org.apache.hadoop.hbase.MultithreadedTestUtil;
import org.apache.hadoop.hbase.MultithreadedTestUtil.TestThread;
+import org.apache.hadoop.hbase.MultithreadedTestUtil.RepeatingTestThread;
import org.apache.hadoop.hbase.client.Append;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Get;
@@ -3128,21 +3129,19 @@ public class TestHRegion extends HBaseTe
/**
* Writes very wide records and gets the latest row every time..
- * Flushes and compacts the region every now and then to keep things
- * realistic.
+ * Flushes and compacts the region aggressivly to catch issues.
*
* @throws IOException by flush / scan / compaction
* @throws InterruptedException when joining threads
*/
public void testWritesWhileGetting()
- throws IOException, InterruptedException {
- byte[] tableName = Bytes.toBytes("testWritesWhileScanning");
+ throws Exception {
+ byte[] tableName = Bytes.toBytes("testWritesWhileGetting");
int testCount = 100;
int numRows = 1;
int numFamilies = 10;
int numQualifiers = 100;
- int flushInterval = 10;
- int compactInterval = 10 * flushInterval;
+ int compactInterval = 100;
byte[][] families = new byte[numFamilies][];
for (int i = 0; i < numFamilies; i++) {
families[i] = Bytes.toBytes("family" + i);
@@ -3153,14 +3152,37 @@ public class TestHRegion extends HBaseTe
}
String method = "testWritesWhileGetting";
- this.region = initHRegion(tableName, method, families);
+ Configuration conf = HBaseConfiguration.create();
+ // This test flushes constantly and can cause many files to be created, possibly
+ // extending over the ulimit. Make sure compactions are aggressive in reducing
+ // the number of HFiles created.
+ conf.setInt("hbase.hstore.compaction.min", 1);
+ conf.setInt("hbase.hstore.compaction.max", 1000);
+ this.region = initHRegion(tableName, method, conf, families);
+ PutThread putThread = null;
+ MultithreadedTestUtil.TestContext ctx =
+ new MultithreadedTestUtil.TestContext(HBaseConfiguration.create());
try {
- PutThread putThread = new PutThread(numRows, families, qualifiers);
+ putThread = new PutThread(numRows, families, qualifiers);
putThread.start();
putThread.waitForFirstPut();
- FlushThread flushThread = new FlushThread();
- flushThread.start();
+ // Add a thread that flushes as fast as possible
+ ctx.addThread(new RepeatingTestThread(ctx) {
+ private int flushesSinceCompact = 0;
+ private final int maxFlushesSinceCompact = 20;
+ public void doAnAction() throws Exception {
+ if (region.flushcache()) {
+ ++flushesSinceCompact;
+ }
+ // Compact regularly to avoid creating too many files and exceeding the ulimit.
+ if (flushesSinceCompact == maxFlushesSinceCompact) {
+ region.compactStores(false);
+ flushesSinceCompact = 0;
+ }
+ }
+ });
+ ctx.startThreads();
Get get = new Get(Bytes.toBytes("row0"));
Result result = null;
@@ -3170,15 +3192,6 @@ public class TestHRegion extends HBaseTe
long prevTimestamp = 0L;
for (int i = 0; i < testCount; i++) {
- if (i != 0 && i % compactInterval == 0) {
- region.compactStores(true);
- }
-
- if (i != 0 && i % flushInterval == 0) {
- //System.out.println("iteration = " + i);
- flushThread.flush();
- }
-
boolean previousEmpty = result == null || result.isEmpty();
result = region.get(get, null);
if (!result.isEmpty() || !previousEmpty || i > compactInterval) {
@@ -3206,25 +3219,24 @@ public class TestHRegion extends HBaseTe
", New KV: " +
kv + "(memStoreTS:" + kv.getMemstoreTS() + ")"
);
- assertEquals(previousKV.getValue(), thisValue);
+ assertEquals(0, Bytes.compareTo(previousKV.getValue(), thisValue));
}
}
previousKV = kv;
}
}
}
-
- putThread.done();
+ } finally {
+ if (putThread != null) putThread.done();
region.flushcache();
- putThread.join();
- putThread.checkNoError();
+ if (putThread != null) {
+ putThread.join();
+ putThread.checkNoError();
+ }
- flushThread.done();
- flushThread.join();
- flushThread.checkNoError();
- } finally {
+ ctx.stop();
HRegion.closeHRegion(this.region);
this.region = null;
}