Search in sources :

Example 16 with ManualEnvironmentEdge

use of org.apache.hadoop.hbase.util.ManualEnvironmentEdge in project hbase by apache.

the class TestHRegion method testCheckAndRowMutateTimestampsAreMonotonic.

@Test
public void testCheckAndRowMutateTimestampsAreMonotonic() throws IOException {
    HRegion region = initHRegion(tableName, method, CONF, fam1);
    ManualEnvironmentEdge edge = new ManualEnvironmentEdge();
    EnvironmentEdgeManager.injectEdge(edge);
    edge.setValue(10);
    Put p = new Put(row);
    p.setDurability(Durability.SKIP_WAL);
    p.addColumn(fam1, qual1, qual1);
    region.put(p);
    Result result = region.get(new Get(row));
    Cell c = result.getColumnLatestCell(fam1, qual1);
    assertNotNull(c);
    assertEquals(c.getTimestamp(), 10L);
    // clock goes back
    edge.setValue(1);
    p = new Put(row);
    p.setDurability(Durability.SKIP_WAL);
    p.addColumn(fam1, qual1, qual2);
    RowMutations rm = new RowMutations(row);
    rm.add(p);
    assertTrue(region.checkAndRowMutate(row, fam1, qual1, CompareOp.EQUAL, new BinaryComparator(qual1), rm, false));
    result = region.get(new Get(row));
    c = result.getColumnLatestCell(fam1, qual1);
    assertEquals(c.getTimestamp(), 10L);
    LOG.info("c value " + Bytes.toStringBinary(c.getValueArray(), c.getValueOffset(), c.getValueLength()));
    assertTrue(Bytes.equals(c.getValueArray(), c.getValueOffset(), c.getValueLength(), qual2, 0, qual2.length));
}
Also used : Get(org.apache.hadoop.hbase.client.Get) Cell(org.apache.hadoop.hbase.Cell) ManualEnvironmentEdge(org.apache.hadoop.hbase.util.ManualEnvironmentEdge) Put(org.apache.hadoop.hbase.client.Put) BinaryComparator(org.apache.hadoop.hbase.filter.BinaryComparator) Result(org.apache.hadoop.hbase.client.Result) RowMutations(org.apache.hadoop.hbase.client.RowMutations) Test(org.junit.Test)

Example 17 with ManualEnvironmentEdge

use of org.apache.hadoop.hbase.util.ManualEnvironmentEdge in project hbase by apache.

the class TestHRegion method testIncrementTimestampsAreMonotonic.

@Test
public void testIncrementTimestampsAreMonotonic() throws IOException {
    HRegion region = initHRegion(tableName, method, CONF, fam1);
    ManualEnvironmentEdge edge = new ManualEnvironmentEdge();
    EnvironmentEdgeManager.injectEdge(edge);
    edge.setValue(10);
    Increment inc = new Increment(row);
    inc.setDurability(Durability.SKIP_WAL);
    inc.addColumn(fam1, qual1, 1L);
    region.increment(inc);
    Result result = region.get(new Get(row));
    Cell c = result.getColumnLatestCell(fam1, qual1);
    assertNotNull(c);
    assertEquals(c.getTimestamp(), 10L);
    // clock goes back
    edge.setValue(1);
    region.increment(inc);
    result = region.get(new Get(row));
    c = result.getColumnLatestCell(fam1, qual1);
    assertEquals(c.getTimestamp(), 11L);
    assertEquals(Bytes.toLong(c.getValueArray(), c.getValueOffset(), c.getValueLength()), 2L);
}
Also used : Increment(org.apache.hadoop.hbase.client.Increment) Get(org.apache.hadoop.hbase.client.Get) Cell(org.apache.hadoop.hbase.Cell) ManualEnvironmentEdge(org.apache.hadoop.hbase.util.ManualEnvironmentEdge) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Example 18 with ManualEnvironmentEdge

use of org.apache.hadoop.hbase.util.ManualEnvironmentEdge in project hbase by apache.

the class TestServerNonceManager method testWalNonces.

@Test
public void testWalNonces() throws Exception {
    ManualEnvironmentEdge edge = new ManualEnvironmentEdge();
    EnvironmentEdgeManager.injectEdge(edge);
    try {
        ServerNonceManager nm = createManager(6);
        ScheduledChore cleanup = nm.createCleanupScheduledChore(Mockito.mock(Stoppable.class));
        // Add nonces from WAL, including dups.
        edge.setValue(12);
        nm.reportOperationFromWal(NO_NONCE, 1, 8);
        nm.reportOperationFromWal(NO_NONCE, 2, 2);
        nm.reportOperationFromWal(NO_NONCE, 3, 5);
        nm.reportOperationFromWal(NO_NONCE, 3, 6);
        // WAL nonces should prevent cross-server conflicts.
        assertFalse(nm.startOperation(NO_NONCE, 1, createStoppable()));
        // Make sure we ignore very old nonces, but not borderline old nonces.
        assertTrue(nm.startOperation(NO_NONCE, 2, createStoppable()));
        assertFalse(nm.startOperation(NO_NONCE, 3, createStoppable()));
        // Make sure grace period is counted from recovery time.
        edge.setValue(17);
        cleanup.choreForTesting();
        assertFalse(nm.startOperation(NO_NONCE, 1, createStoppable()));
        assertFalse(nm.startOperation(NO_NONCE, 3, createStoppable()));
        edge.setValue(19);
        cleanup.choreForTesting();
        assertTrue(nm.startOperation(NO_NONCE, 1, createStoppable()));
        assertTrue(nm.startOperation(NO_NONCE, 3, createStoppable()));
    } finally {
        EnvironmentEdgeManager.reset();
    }
}
Also used : ScheduledChore(org.apache.hadoop.hbase.ScheduledChore) Stoppable(org.apache.hadoop.hbase.Stoppable) ManualEnvironmentEdge(org.apache.hadoop.hbase.util.ManualEnvironmentEdge) Test(org.junit.Test)

Aggregations

ManualEnvironmentEdge (org.apache.hadoop.hbase.util.ManualEnvironmentEdge)18 Test (org.junit.Test)14 Cell (org.apache.hadoop.hbase.Cell)4 Get (org.apache.hadoop.hbase.client.Get)4 Result (org.apache.hadoop.hbase.client.Result)4 Configuration (org.apache.hadoop.conf.Configuration)2 ScheduledChore (org.apache.hadoop.hbase.ScheduledChore)2 Stoppable (org.apache.hadoop.hbase.Stoppable)2 Put (org.apache.hadoop.hbase.client.Put)2 BinaryComparator (org.apache.hadoop.hbase.filter.BinaryComparator)2 StoreFile (org.apache.hadoop.hbase.regionserver.StoreFile)2 StripeInformationProvider (org.apache.hadoop.hbase.regionserver.compactions.StripeCompactionPolicy.StripeInformationProvider)2 BeforeClass (org.junit.BeforeClass)2 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 ServerName (org.apache.hadoop.hbase.ServerName)1 TableName (org.apache.hadoop.hbase.TableName)1 Append (org.apache.hadoop.hbase.client.Append)1 Increment (org.apache.hadoop.hbase.client.Increment)1 RowMutations (org.apache.hadoop.hbase.client.RowMutations)1