Search in sources :

Example 31 with RegionScanner

use of org.apache.hadoop.hbase.regionserver.RegionScanner in project hbase by apache.

the class TestMigrateAndMirrorMetaLocations method test.

@Test
public void test() throws Exception {
    checkMirrorLocation(2);
    MasterRegion masterRegion = UTIL.getMiniHBaseCluster().getMaster().getMasterRegion();
    try (RegionScanner scanner = masterRegion.getRegionScanner(new Scan().addFamily(HConstants.CATALOG_FAMILY))) {
        List<Cell> cells = new ArrayList<>();
        scanner.next(cells);
        Cell cell = cells.get(0);
        // delete the only row
        masterRegion.update(r -> r.delete(new Delete(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength()).addFamily(HConstants.CATALOG_FAMILY)));
        masterRegion.flush(true);
    }
    // restart the whole cluster, to see if we can migrate the data on zookeeper to master local
    // region
    UTIL.shutdownMiniHBaseCluster();
    UTIL.startMiniHBaseCluster(StartTestingClusterOption.builder().numRegionServers(3).build());
    masterRegion = UTIL.getMiniHBaseCluster().getMaster().getMasterRegion();
    try (RegionScanner scanner = masterRegion.getRegionScanner(new Scan().addFamily(HConstants.CATALOG_FAMILY))) {
        List<Cell> cells = new ArrayList<>();
        boolean moreRows = scanner.next(cells);
        assertFalse(moreRows);
        // should have the migrated data
        assertFalse(cells.isEmpty());
    }
    // wait until all meta regions have been assigned
    UTIL.waitFor(30000, () -> UTIL.getMiniHBaseCluster().getRegions(TableName.META_TABLE_NAME).size() == 2);
    // make sure all the SCPs are finished
    waitUntilNoSCP();
    checkMirrorLocation(2);
    // increase replica count to 3
    HBaseTestingUtil.setReplicas(UTIL.getAdmin(), TableName.META_TABLE_NAME, 3);
    checkMirrorLocation(3);
    byte[] replica2Data = ZKUtil.getData(UTIL.getZooKeeperWatcher(), UTIL.getZooKeeperWatcher().getZNodePaths().getZNodeForReplica(2));
    // decrease replica count to 1
    HBaseTestingUtil.setReplicas(UTIL.getAdmin(), TableName.META_TABLE_NAME, 1);
    checkMirrorLocation(1);
    // restart the whole cluster, put an extra replica znode on zookeeper, to see if we will remove
    // it
    UTIL.shutdownMiniHBaseCluster();
    ZKUtil.createAndFailSilent(UTIL.getZooKeeperWatcher(), UTIL.getZooKeeperWatcher().getZNodePaths().getZNodeForReplica(2), replica2Data);
    UTIL.startMiniHBaseCluster(StartTestingClusterOption.builder().numRegionServers(3).build());
    // should have removed the extra replica znode as it is part of the start up process, when
    // initializing AM
    assertEquals(1, UTIL.getZooKeeperWatcher().getMetaReplicaNodes().size());
    // make sure all the SCPs are finished
    waitUntilNoSCP();
    checkMirrorLocation(1);
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) RegionScanner(org.apache.hadoop.hbase.regionserver.RegionScanner) MasterRegion(org.apache.hadoop.hbase.master.region.MasterRegion) ArrayList(java.util.ArrayList) Scan(org.apache.hadoop.hbase.client.Scan) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.Test)

Example 32 with RegionScanner

use of org.apache.hadoop.hbase.regionserver.RegionScanner in project hbase by apache.

the class TestMigrateAndMirrorMetaLocations method checkMirrorLocation.

private void checkMirrorLocation(int replicaCount) throws Exception {
    MasterRegion masterRegion = UTIL.getMiniHBaseCluster().getMaster().getMasterRegion();
    try (RegionScanner scanner = masterRegion.getRegionScanner(new Scan().addFamily(HConstants.CATALOG_FAMILY))) {
        List<Cell> cells = new ArrayList<>();
        boolean moreRows = scanner.next(cells);
        // should only have one row as we have only one meta region, different replicas will be in the
        // same row
        assertFalse(moreRows);
        assertFalse(cells.isEmpty());
        Result result = Result.create(cells);
        // make sure we publish the correct location to zookeeper too
        assertLocationEquals(result, replicaCount);
    }
}
Also used : RegionScanner(org.apache.hadoop.hbase.regionserver.RegionScanner) MasterRegion(org.apache.hadoop.hbase.master.region.MasterRegion) ArrayList(java.util.ArrayList) Scan(org.apache.hadoop.hbase.client.Scan) Cell(org.apache.hadoop.hbase.Cell) Result(org.apache.hadoop.hbase.client.Result)

Example 33 with RegionScanner

use of org.apache.hadoop.hbase.regionserver.RegionScanner in project hbase by apache.

the class TestMetaRegionReplicaReplication method verifyDeletedReplication.

/**
 * Verify when a Table is deleted from primary, then there are no references in replicas (because
 * they get the delete of the table rows too).
 */
private void verifyDeletedReplication(TableName tableName, int regionReplication, final TableName deletedTableName) {
    final Region[] regions = getAllRegions(tableName, regionReplication);
    // Start count at '1' so we skip default, primary replica and only look at secondaries.
    for (int i = 1; i < regionReplication; i++) {
        final Region region = regions[i];
        // wait until all the data is replicated to all secondary regions
        Waiter.waitFor(HTU.getConfiguration(), 30000, 1000, new Waiter.Predicate<Exception>() {

            @Override
            public boolean evaluate() throws Exception {
                LOG.info("Verifying replication for region replica {}", region.getRegionInfo());
                try (RegionScanner rs = region.getScanner(new Scan())) {
                    List<Cell> cells = new ArrayList<>();
                    while (rs.next(cells)) {
                        continue;
                    }
                    return doesNotContain(cells, deletedTableName);
                } catch (Throwable ex) {
                    LOG.warn("Verification from secondary region is not complete yet", ex);
                    // still wait
                    return false;
                }
            }
        });
    }
}
Also used : RegionScanner(org.apache.hadoop.hbase.regionserver.RegionScanner) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) Region(org.apache.hadoop.hbase.regionserver.Region) Scan(org.apache.hadoop.hbase.client.Scan) ArrayList(java.util.ArrayList) List(java.util.List) Waiter(org.apache.hadoop.hbase.Waiter) IOException(java.io.IOException)

Example 34 with RegionScanner

use of org.apache.hadoop.hbase.regionserver.RegionScanner in project hbase by apache.

the class TestMetaRegionReplicaReplication method verifyReplication.

/**
 * Verify Replicas have results (exactly).
 */
private void verifyReplication(TableName tableName, int regionReplication, List<Result> contains) {
    final Region[] regions = getAllRegions(tableName, regionReplication);
    // Start count at '1' so we skip default, primary replica and only look at secondaries.
    for (int i = 1; i < regionReplication; i++) {
        final Region region = regions[i];
        // wait until all the data is replicated to all secondary regions
        Waiter.waitFor(HTU.getConfiguration(), 30000, 1000, new Waiter.Predicate<Exception>() {

            @Override
            public boolean evaluate() throws Exception {
                LOG.info("Verifying replication for region replica {}", region.getRegionInfo());
                try (RegionScanner rs = region.getScanner(new Scan())) {
                    List<Cell> cells = new ArrayList<>();
                    while (rs.next(cells)) {
                        continue;
                    }
                    return contains(contains, cells);
                } catch (Throwable ex) {
                    LOG.warn("Verification from secondary region is not complete yet", ex);
                    // still wait
                    return false;
                }
            }
        });
    }
}
Also used : RegionScanner(org.apache.hadoop.hbase.regionserver.RegionScanner) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) Region(org.apache.hadoop.hbase.regionserver.Region) Scan(org.apache.hadoop.hbase.client.Scan) ArrayList(java.util.ArrayList) List(java.util.List) Waiter(org.apache.hadoop.hbase.Waiter) IOException(java.io.IOException)

Example 35 with RegionScanner

use of org.apache.hadoop.hbase.regionserver.RegionScanner in project hbase by apache.

the class HBaseTestingUtil method getClosestRowBefore.

public Result getClosestRowBefore(Region r, byte[] row, byte[] family) throws IOException {
    Scan scan = new Scan().withStartRow(row);
    scan.setReadType(ReadType.PREAD);
    scan.setCaching(1);
    scan.setReversed(true);
    scan.addFamily(family);
    try (RegionScanner scanner = r.getScanner(scan)) {
        List<Cell> cells = new ArrayList<>(1);
        scanner.next(cells);
        if (r.getRegionInfo().isMetaRegion() && !isTargetTable(row, cells.get(0))) {
            return null;
        }
        return Result.create(cells);
    }
}
Also used : RegionScanner(org.apache.hadoop.hbase.regionserver.RegionScanner) ArrayList(java.util.ArrayList) Scan(org.apache.hadoop.hbase.client.Scan)

Aggregations

RegionScanner (org.apache.hadoop.hbase.regionserver.RegionScanner)97 Scan (org.apache.hadoop.hbase.client.Scan)75 Cell (org.apache.hadoop.hbase.Cell)59 ArrayList (java.util.ArrayList)35 Test (org.junit.Test)35 Put (org.apache.hadoop.hbase.client.Put)33 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)25 Region (org.apache.hadoop.hbase.regionserver.Region)20 List (java.util.List)18 TableId (co.cask.cdap.data2.util.TableId)17 IOException (java.io.IOException)14 Delete (org.apache.hadoop.hbase.client.Delete)14 RegionCoprocessorEnvironment (org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment)12 ImmutableBytesPtr (org.apache.phoenix.hbase.index.util.ImmutableBytesPtr)12 KeyValue (org.apache.hadoop.hbase.KeyValue)11 Configuration (org.apache.hadoop.conf.Configuration)9 ColumnReference (org.apache.phoenix.hbase.index.covered.update.ColumnReference)9 PMetaDataEntity (org.apache.phoenix.schema.PMetaDataEntity)9 InvocationOnMock (org.mockito.invocation.InvocationOnMock)8 Result (org.apache.hadoop.hbase.client.Result)6