Search in sources :

Example 1 with MetricsWALSource

use of org.apache.hadoop.hbase.regionserver.wal.MetricsWALSource in project hbase by apache.

the class TestHRegion method testBatchPut_whileMultipleRowLocksHeld.

@Test
public void testBatchPut_whileMultipleRowLocksHeld() throws Exception {
    byte[] cf = Bytes.toBytes(COLUMN_FAMILY);
    byte[] qual = Bytes.toBytes("qual");
    byte[] val = Bytes.toBytes("val");
    this.region = initHRegion(tableName, method, CONF, cf);
    MetricsWALSource source = CompatibilitySingletonFactory.getInstance(MetricsWALSource.class);
    try {
        long syncs = metricsAssertHelper.getCounter("syncTimeNumOps", source);
        metricsAssertHelper.assertCounter("syncTimeNumOps", syncs, source);
        final Put[] puts = new Put[10];
        for (int i = 0; i < 10; i++) {
            puts[i] = new Put(Bytes.toBytes("row_" + i));
            puts[i].addColumn(cf, qual, val);
        }
        puts[5].addColumn(Bytes.toBytes("BAD_CF"), qual, val);
        LOG.info("batchPut will have to break into four batches to avoid row locks");
        RowLock rowLock1 = region.getRowLock(Bytes.toBytes("row_2"));
        RowLock rowLock2 = region.getRowLock(Bytes.toBytes("row_1"));
        RowLock rowLock3 = region.getRowLock(Bytes.toBytes("row_3"));
        RowLock rowLock4 = region.getRowLock(Bytes.toBytes("row_3"), true);
        MultithreadedTestUtil.TestContext ctx = new MultithreadedTestUtil.TestContext(CONF);
        final AtomicReference<OperationStatus[]> retFromThread = new AtomicReference<>();
        final CountDownLatch startingPuts = new CountDownLatch(1);
        final CountDownLatch startingClose = new CountDownLatch(1);
        TestThread putter = new TestThread(ctx) {

            @Override
            public void doWork() throws IOException {
                startingPuts.countDown();
                retFromThread.set(region.batchMutate(puts));
            }
        };
        LOG.info("...starting put thread while holding locks");
        ctx.addThread(putter);
        ctx.startThreads();
        // Now attempt to close the region from another thread.  Prior to HBASE-12565
        // this would cause the in-progress batchMutate operation to to fail with
        // exception because it use to release and re-acquire the close-guard lock
        // between batches.  Caller then didn't get status indicating which writes succeeded.
        // We now expect this thread to block until the batchMutate call finishes.
        Thread regionCloseThread = new TestThread(ctx) {

            @Override
            public void doWork() {
                try {
                    startingPuts.await();
                    // Give some time for the batch mutate to get in.
                    // We don't want to race with the mutate
                    Thread.sleep(10);
                    startingClose.countDown();
                    HBaseTestingUtility.closeRegionAndWAL(region);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        };
        regionCloseThread.start();
        startingClose.await();
        startingPuts.await();
        Thread.sleep(100);
        LOG.info("...releasing row lock 1, which should let put thread continue");
        rowLock1.release();
        rowLock2.release();
        rowLock3.release();
        waitForCounter(source, "syncTimeNumOps", syncs + 1);
        LOG.info("...joining on put thread");
        ctx.stop();
        regionCloseThread.join();
        OperationStatus[] codes = retFromThread.get();
        for (int i = 0; i < codes.length; i++) {
            assertEquals((i == 5) ? OperationStatusCode.BAD_FAMILY : OperationStatusCode.SUCCESS, codes[i].getOperationStatusCode());
        }
        rowLock4.release();
    } finally {
        HBaseTestingUtility.closeRegionAndWAL(this.region);
        this.region = null;
    }
}
Also used : RepeatingTestThread(org.apache.hadoop.hbase.MultithreadedTestUtil.RepeatingTestThread) TestThread(org.apache.hadoop.hbase.MultithreadedTestUtil.TestThread) AtomicReference(java.util.concurrent.atomic.AtomicReference) MetricsWALSource(org.apache.hadoop.hbase.regionserver.wal.MetricsWALSource) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) Put(org.apache.hadoop.hbase.client.Put) RepeatingTestThread(org.apache.hadoop.hbase.MultithreadedTestUtil.RepeatingTestThread) TestThread(org.apache.hadoop.hbase.MultithreadedTestUtil.TestThread) MultithreadedTestUtil(org.apache.hadoop.hbase.MultithreadedTestUtil) RowLock(org.apache.hadoop.hbase.regionserver.Region.RowLock) Test(org.junit.Test)

Example 2 with MetricsWALSource

use of org.apache.hadoop.hbase.regionserver.wal.MetricsWALSource in project hbase by apache.

the class TestHRegion method testBatchPut_whileNoRowLocksHeld.

@Test
public void testBatchPut_whileNoRowLocksHeld() throws IOException {
    byte[] cf = Bytes.toBytes(COLUMN_FAMILY);
    byte[] qual = Bytes.toBytes("qual");
    byte[] val = Bytes.toBytes("val");
    this.region = initHRegion(tableName, method, CONF, cf);
    MetricsWALSource source = CompatibilitySingletonFactory.getInstance(MetricsWALSource.class);
    try {
        long syncs = metricsAssertHelper.getCounter("syncTimeNumOps", source);
        metricsAssertHelper.assertCounter("syncTimeNumOps", syncs, source);
        LOG.info("First a batch put with all valid puts");
        final Put[] puts = new Put[10];
        for (int i = 0; i < 10; i++) {
            puts[i] = new Put(Bytes.toBytes("row_" + i));
            puts[i].addColumn(cf, qual, val);
        }
        OperationStatus[] codes = this.region.batchMutate(puts);
        assertEquals(10, codes.length);
        for (int i = 0; i < 10; i++) {
            assertEquals(OperationStatusCode.SUCCESS, codes[i].getOperationStatusCode());
        }
        metricsAssertHelper.assertCounter("syncTimeNumOps", syncs + 1, source);
        LOG.info("Next a batch put with one invalid family");
        puts[5].addColumn(Bytes.toBytes("BAD_CF"), qual, val);
        codes = this.region.batchMutate(puts);
        assertEquals(10, codes.length);
        for (int i = 0; i < 10; i++) {
            assertEquals((i == 5) ? OperationStatusCode.BAD_FAMILY : OperationStatusCode.SUCCESS, codes[i].getOperationStatusCode());
        }
        metricsAssertHelper.assertCounter("syncTimeNumOps", syncs + 2, source);
    } finally {
        HBaseTestingUtility.closeRegionAndWAL(this.region);
        this.region = null;
    }
}
Also used : MetricsWALSource(org.apache.hadoop.hbase.regionserver.wal.MetricsWALSource) Put(org.apache.hadoop.hbase.client.Put) Test(org.junit.Test)

Example 3 with MetricsWALSource

use of org.apache.hadoop.hbase.regionserver.wal.MetricsWALSource in project hbase by apache.

the class TestHRegion method testBatchPutWithTsSlop.

@Test
public void testBatchPutWithTsSlop() throws Exception {
    byte[] cf = Bytes.toBytes(COLUMN_FAMILY);
    byte[] qual = Bytes.toBytes("qual");
    byte[] val = Bytes.toBytes("val");
    // add data with a timestamp that is too recent for range. Ensure assert
    CONF.setInt("hbase.hregion.keyvalue.timestamp.slop.millisecs", 1000);
    this.region = initHRegion(tableName, method, CONF, cf);
    try {
        MetricsWALSource source = CompatibilitySingletonFactory.getInstance(MetricsWALSource.class);
        long syncs = metricsAssertHelper.getCounter("syncTimeNumOps", source);
        metricsAssertHelper.assertCounter("syncTimeNumOps", syncs, source);
        final Put[] puts = new Put[10];
        for (int i = 0; i < 10; i++) {
            puts[i] = new Put(Bytes.toBytes("row_" + i), Long.MAX_VALUE - 100);
            puts[i].addColumn(cf, qual, val);
        }
        OperationStatus[] codes = this.region.batchMutate(puts);
        assertEquals(10, codes.length);
        for (int i = 0; i < 10; i++) {
            assertEquals(OperationStatusCode.SANITY_CHECK_FAILURE, codes[i].getOperationStatusCode());
        }
        metricsAssertHelper.assertCounter("syncTimeNumOps", syncs, source);
    } finally {
        HBaseTestingUtility.closeRegionAndWAL(this.region);
        this.region = null;
    }
}
Also used : MetricsWALSource(org.apache.hadoop.hbase.regionserver.wal.MetricsWALSource) Put(org.apache.hadoop.hbase.client.Put) Test(org.junit.Test)

Aggregations

Put (org.apache.hadoop.hbase.client.Put)3 MetricsWALSource (org.apache.hadoop.hbase.regionserver.wal.MetricsWALSource)3 Test (org.junit.Test)3 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 MultithreadedTestUtil (org.apache.hadoop.hbase.MultithreadedTestUtil)1 RepeatingTestThread (org.apache.hadoop.hbase.MultithreadedTestUtil.RepeatingTestThread)1 TestThread (org.apache.hadoop.hbase.MultithreadedTestUtil.TestThread)1 RowLock (org.apache.hadoop.hbase.regionserver.Region.RowLock)1