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);
}
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);
}
}
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;
}
}
});
}
}
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;
}
}
});
}
}
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);
}
}
Aggregations