Java Code Examples for org.apache.hadoop.hbase.util.Threads#sleep()

The following examples show how to use org.apache.hadoop.hbase.util.Threads#sleep() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestAdmin1.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testSplitShouldNotHappenIfSplitIsDisabledForTable() throws Exception {
  final TableName tableName = TableName.valueOf(name.getMethodName());
  TableDescriptor htd = TableDescriptorBuilder.newBuilder(tableName)
    .setRegionSplitPolicyClassName(DisabledRegionSplitPolicy.class.getName())
    .setColumnFamily(ColumnFamilyDescriptorBuilder.of("f")).build();
  Table table = TEST_UTIL.createTable(htd, null);
  for (int i = 0; i < 10; i++) {
    Put p = new Put(Bytes.toBytes("row" + i));
    byte[] q1 = Bytes.toBytes("q1");
    byte[] v1 = Bytes.toBytes("v1");
    p.addColumn(Bytes.toBytes("f"), q1, v1);
    table.put(p);
  }
  ADMIN.flush(tableName);
  try {
    ADMIN.split(tableName, Bytes.toBytes("row5"));
    Threads.sleep(10000);
  } catch (Exception e) {
    // Nothing to do.
  }
  // Split should not happen.
  List<RegionInfo> allRegions =
    MetaTableAccessor.getTableRegions(ADMIN.getConnection(), tableName, true);
  assertEquals(1, allRegions.size());
}
 
Example 2
Source File: TestMetaTableLocator.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void startWaitAliveThenWaitItLives(final Thread t, final int ms) {
  t.start();
  UTIL.waitFor(2000, t::isAlive);
  // Wait one second.
  Threads.sleep(ms);
  assertTrue("Assert " + t.getName() + " still waiting", t.isAlive());
}
 
Example 3
Source File: TestSplitOrMergeStatus.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testSplitSwitch() throws Exception {
  final TableName tableName = TableName.valueOf(name.getMethodName());
  Table t = TEST_UTIL.createTable(tableName, FAMILY);
  TEST_UTIL.loadTable(t, FAMILY, false);

  RegionLocator locator = TEST_UTIL.getConnection().getRegionLocator(t.getName());
  int originalCount = locator.getAllRegionLocations().size();

  Admin admin = TEST_UTIL.getAdmin();
  initSwitchStatus(admin);
  assertTrue(admin.splitSwitch(false, false));
  try {
    admin.split(t.getName());
    fail("Shouldn't get here");
  } catch (DoNotRetryIOException dnioe) {
    // Expected
  }
  int count = admin.getRegions(tableName).size();
  assertTrue(originalCount == count);
  assertFalse(admin.splitSwitch(true, false));
  admin.split(t.getName());
  while ((count = admin.getRegions(tableName).size()) == originalCount) {
    Threads.sleep(1);
  }
  count = admin.getRegions(tableName).size();
  assertTrue(originalCount < count);
  admin.close();
}
 
Example 4
Source File: TestThriftServer.java    From hbase with Apache License 2.0 5 votes vote down vote up
public static void doTestIncrements(ThriftHBaseServiceHandler handler) throws Exception {
  List<Mutation> mutations = new ArrayList<>(1);
  mutations.add(new Mutation(false, columnAAname, valueEname, true));
  mutations.add(new Mutation(false, columnAname, valueEname, true));
  handler.mutateRow(tableAname, rowAname, mutations, null);
  handler.mutateRow(tableAname, rowBname, mutations, null);

  List<TIncrement> increments = new ArrayList<>(3);
  increments.add(new TIncrement(tableAname, rowBname, columnAAname, 7));
  increments.add(new TIncrement(tableAname, rowBname, columnAAname, 7));
  increments.add(new TIncrement(tableAname, rowBname, columnAAname, 7));

  int numIncrements = 60000;
  for (int i = 0; i < numIncrements; i++) {
    handler.increment(new TIncrement(tableAname, rowAname, columnAname, 2));
    handler.incrementRows(increments);
  }

  Thread.sleep(1000);
  long lv = handler.get(tableAname, rowAname, columnAname, null).get(0).value.getLong();
  // Wait on all increments being flushed
  while (handler.coalescer.getQueueSize() != 0) {
    Threads.sleep(10);
  }

  assertEquals((100 + (2 * numIncrements)), lv);

  lv = handler.get(tableAname, rowBname, columnAAname, null).get(0).value.getLong();
  assertEquals((100 + (3 * 7 * numIncrements)), lv);

  assertTrue(handler.coalescer.getSuccessfulCoalescings() > 0);

}
 
Example 5
Source File: SleepAtFirstRpcCall.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public Result postAppend(final ObserverContext<RegionCoprocessorEnvironment> e,
    final Append append, final Result result) throws IOException {
  if (ct.incrementAndGet() == 1) {
    Threads.sleep(sleepTime.get());
  }
  return result;
}
 
Example 6
Source File: TestAsyncRegionAdminApi2.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testSplitSwitch() throws Exception {
  createTableWithDefaultConf(tableName);
  byte[][] families = {FAMILY};
  final int rows = 10000;
  TestAsyncRegionAdminApi.loadData(tableName, families, rows);

  AsyncTable<AdvancedScanResultConsumer> metaTable = ASYNC_CONN.getTable(META_TABLE_NAME);
  List<HRegionLocation> regionLocations =
      ClientMetaTableAccessor.getTableHRegionLocations(metaTable, tableName).get();
  int originalCount = regionLocations.size();

  initSplitMergeSwitch();
  assertTrue(admin.splitSwitch(false).get());
  try {
    admin.split(tableName, Bytes.toBytes(rows / 2)).join();
  } catch (Exception e) {
    //Expected
  }
  int count = admin.getRegions(tableName).get().size();
  assertTrue(originalCount == count);

  assertFalse(admin.splitSwitch(true).get());
  admin.split(tableName).join();
  while ((count = admin.getRegions(tableName).get().size()) == originalCount) {
    Threads.sleep(100);
  }
  assertTrue(originalCount < count);
}
 
Example 7
Source File: TestEndToEndSplitTransaction.java    From hbase with Apache License 2.0 5 votes vote down vote up
public static void flushAndBlockUntilDone(Admin admin, HRegionServer rs, byte[] regionName)
    throws IOException, InterruptedException {
  log("flushing region: " + Bytes.toStringBinary(regionName));
  admin.flushRegion(regionName);
  log("blocking until flush is complete: " + Bytes.toStringBinary(regionName));
  Threads.sleepWithoutInterrupt(500);
  while (rs.getOnlineRegion(regionName).getMemStoreDataSize() > 0) {
    Threads.sleep(50);
  }
}
 
Example 8
Source File: TestServerBusyException.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void preGetOp(final ObserverContext<RegionCoprocessorEnvironment> e,
    final Get get, final List<Cell> results) throws IOException {
  // After first sleep, all requests are timeout except the last retry. If we handle
  // all the following requests, finally the last request is also timeout. If we drop all
  // timeout requests, we can handle the last request immediately and it will not timeout.
  if (ct.incrementAndGet() <= 1) {
    Threads.sleep(SLEEP_TIME * RPC_RETRY * 2);
  } else {
    Threads.sleep(SLEEP_TIME);
  }
}
 
Example 9
Source File: TestMaster.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testFlushedSequenceIdPersistLoad() throws Exception {
  Configuration conf = TEST_UTIL.getConfiguration();
  int msgInterval = conf.getInt("hbase.regionserver.msginterval", 100);
  // insert some data into META
  TableName tableName = TableName.valueOf("testFlushSeqId");
  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(tableName);

  tableDescriptor.setColumnFamily(
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(Bytes.toBytes("cf")));
  Table table = TEST_UTIL.createTable(tableDescriptor, null);
  // flush META region
  TEST_UTIL.flush(TableName.META_TABLE_NAME);
  // wait for regionserver report
  Threads.sleep(msgInterval * 2);
  // record flush seqid before cluster shutdown
  Map<byte[], Long> regionMapBefore =
      TEST_UTIL.getHBaseCluster().getMaster().getServerManager()
          .getFlushedSequenceIdByRegion();
  // restart hbase cluster which will cause flushed sequence id persist and reload
  TEST_UTIL.getMiniHBaseCluster().shutdown();
  TEST_UTIL.restartHBaseCluster(2);
  TEST_UTIL.waitUntilNoRegionsInTransition();
  // check equality after reloading flushed sequence id map
  Map<byte[], Long> regionMapAfter =
      TEST_UTIL.getHBaseCluster().getMaster().getServerManager()
          .getFlushedSequenceIdByRegion();
  assertTrue(regionMapBefore.equals(regionMapAfter));
}
 
Example 10
Source File: TestLoadAndSwitchEncodeOnDisk.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
@Test
public void loadTest() throws Exception {
  Admin admin = TEST_UTIL.getAdmin();

  compression = Compression.Algorithm.GZ; // used for table setup
  super.loadTest();

  ColumnFamilyDescriptor hcd = getColumnDesc(admin);
  System.err.println("\nDisabling encode-on-disk. Old column descriptor: " + hcd + "\n");
  Table t = TEST_UTIL.getConnection().getTable(TABLE);
  assertAllOnLine(t);

  admin.disableTable(TABLE);
  admin.modifyColumnFamily(TABLE, hcd);

  System.err.println("\nRe-enabling table\n");
  admin.enableTable(TABLE);

  System.err.println("\nNew column descriptor: " +
      getColumnDesc(admin) + "\n");

  // The table may not have all regions on line yet.  Assert online before
  // moving to major compact.
  assertAllOnLine(t);

  System.err.println("\nCompacting the table\n");
  admin.majorCompact(TABLE);
  // Wait until compaction completes
  Threads.sleepWithoutInterrupt(5000);
  HRegionServer rs = TEST_UTIL.getMiniHBaseCluster().getRegionServer(0);
  while (rs.compactSplitThread.getCompactionQueueSize() > 0) {
    Threads.sleep(50);
  }

  System.err.println("\nDone with the test, shutting down the cluster\n");
}
 
Example 11
Source File: TestTableStateManager.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testMigration() throws Exception {
  final TableName tableName = TableName.valueOf(name.getMethodName());
  TEST_UTIL.createTable(tableName, HConstants.CATALOG_FAMILY_STR);
  TEST_UTIL.getAdmin().disableTable(tableName);
  // Table is disabled. Now remove the DISABLED column from the hbase:meta for this table's
  // region. We want to see if Master will read the DISABLED from zk and make use of it as
  // though it were reading the zk table state written by a hbase-1.x cluster.
  TableState state = MetaTableAccessor.getTableState(TEST_UTIL.getConnection(), tableName);
  assertTrue("State=" + state, state.getState().equals(TableState.State.DISABLED));
  MetaTableAccessor.deleteTableState(TEST_UTIL.getConnection(), tableName);
  assertTrue(MetaTableAccessor.getTableState(TEST_UTIL.getConnection(), tableName) == null);
  // Now kill Master so a new one can come up and run through the zk migration.
  HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster();
  master.stop("Restarting");
  while (!master.isStopped()) {
    Threads.sleep(1);
  }
  assertTrue(master.isStopped());
  JVMClusterUtil.MasterThread newMasterThread = TEST_UTIL.getMiniHBaseCluster().startMaster();
  master = newMasterThread.getMaster();
  while (!master.isInitialized()) {
    Threads.sleep(1);
  }
  assertTrue(MetaTableAccessor.getTableState(TEST_UTIL.getConnection(),
      tableName).getState().equals(TableState.State.DISABLED));
}
 
Example 12
Source File: TestCatalogJanitorInMemoryStates.java    From hbase with Apache License 2.0 5 votes vote down vote up
private PairOfSameType<RegionInfo> waitOnDaughters(final RegionInfo r)
    throws IOException {
  long start = System.currentTimeMillis();
  PairOfSameType<RegionInfo> pair = null;
  try (Connection conn = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration());
       Table metaTable = conn.getTable(TableName.META_TABLE_NAME)) {
    Result result = null;
    RegionInfo region = null;
    while ((System.currentTimeMillis() - start) < 60000) {
      result = metaTable.get(new Get(r.getRegionName()));
      if (result == null) {
        break;
      }
      region = CatalogFamilyFormat.getRegionInfo(result);
      if (region.isSplitParent()) {
        LOG.debug(region.toString() + " IS a parent!");
        pair = MetaTableAccessor.getDaughterRegions(result);
        break;
      }
      Threads.sleep(100);
    }

    if (pair.getFirst() == null || pair.getSecond() == null) {
      throw new IOException("Failed to get daughters, for parent region: " + r);
    }
    return pair;
  }
}
 
Example 13
Source File: TestCompactingToCellFlatMapMemStore.java    From hbase with Apache License 2.0 4 votes vote down vote up
private void testTimeRange(boolean isCompaction) throws IOException {
  final long initTs = 100;
  long currentTs = initTs;
  byte[] row = Bytes.toBytes("row");
  byte[] family = Bytes.toBytes("family");
  byte[] qf1 = Bytes.toBytes("qf1");

  // first segment in pipeline
  this.memstore.add(new KeyValue(row, family, qf1, ++currentTs, (byte[])null), null);
  long minTs = currentTs;
  this.memstore.add(new KeyValue(row, family, qf1, ++currentTs, (byte[])null), null);

  long numberOfCell = 2;
  assertEquals(numberOfCell, memstore.getSegments().stream().mapToInt(Segment::getCellsCount).sum());
  assertEquals(minTs, memstore.getSegments().stream().mapToLong(
      m -> m.getTimeRangeTracker().getMin()).min().getAsLong());
  assertEquals(currentTs, memstore.getSegments().stream().mapToLong(
      m -> m.getTimeRangeTracker().getMax()).max().getAsLong());

  ((CompactingMemStore) memstore).flushInMemory();

  while (((CompactingMemStore) memstore).isMemStoreFlushingInMemory()) {
    Threads.sleep(10);
  }
  if (isCompaction) {
    // max version = 1, so one cell will be dropped.
    numberOfCell = 1;
    minTs = currentTs;
  }
  // second segment in pipeline
  this.memstore.add(new KeyValue(row, family, qf1, ++currentTs, (byte[])null), null);
  this.memstore.add(new KeyValue(row, family, qf1, ++currentTs, (byte[])null), null);
  numberOfCell += 2;
  assertEquals(numberOfCell, memstore.getSegments().stream().mapToInt(Segment::getCellsCount).sum());
  assertEquals(minTs, memstore.getSegments().stream().mapToLong(
      m -> m.getTimeRangeTracker().getMin()).min().getAsLong());
  assertEquals(currentTs, memstore.getSegments().stream().mapToLong(
      m -> m.getTimeRangeTracker().getMax()).max().getAsLong());

  ((CompactingMemStore) memstore).flushInMemory(); // trigger the merge

  while (((CompactingMemStore) memstore).isMemStoreFlushingInMemory()) {
    Threads.sleep(10);
  }
  if (isCompaction) {
    // max version = 1, so one cell will be dropped.
    numberOfCell = 1;
    minTs = currentTs;
  }

  assertEquals(numberOfCell, memstore.getSegments().stream().mapToInt(Segment::getCellsCount).sum());
  assertEquals(minTs, memstore.getSegments().stream().mapToLong(
      m -> m.getTimeRangeTracker().getMin()).min().getAsLong());
  assertEquals(currentTs, memstore.getSegments().stream().mapToLong(
      m -> m.getTimeRangeTracker().getMax()).max().getAsLong());
}
 
Example 14
Source File: TestAccessController.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testRemoteLocks() throws Exception {
  String namespace = "preQueueNs";
  final TableName tableName = TableName.valueOf(namespace, name.getMethodName());
  RegionInfo[] regionInfos = new RegionInfo[] { RegionInfoBuilder.newBuilder(tableName).build() };

  // Setup Users
  // User will be granted ADMIN and CREATE on namespace. Should be denied before grant.
  User namespaceUser = User.createUserForTesting(conf, "qLNSUser", new String[0]);
  // User will be granted ADMIN and CREATE on table. Should be denied before grant.
  User tableACUser = User.createUserForTesting(conf, "qLTableACUser", new String[0]);
  // User will be granted READ, WRITE, EXECUTE on table. Should be denied.
  User tableRWXUser = User.createUserForTesting(conf, "qLTableRWXUser", new String[0]);
  grantOnTable(TEST_UTIL, tableRWXUser.getShortName(), tableName, null, null,
      Action.READ, Action.WRITE, Action.EXEC);
  // User with global READ, WRITE, EXECUTE should be denied lock access.
  User globalRWXUser = User.createUserForTesting(conf, "qLGlobalRWXUser", new String[0]);
  grantGlobal(TEST_UTIL, globalRWXUser.getShortName(), Action.READ, Action.WRITE, Action.EXEC);

  AccessTestAction namespaceLockAction = new AccessTestAction() {
    @Override public Object run() throws Exception {
      ACCESS_CONTROLLER.preRequestLock(ObserverContextImpl.createAndPrepare(CP_ENV), namespace,
          null, null, null);
      return null;
    }
  };
  verifyAllowed(namespaceLockAction, SUPERUSER, USER_ADMIN);
  verifyDenied(namespaceLockAction, globalRWXUser, tableACUser, namespaceUser, tableRWXUser);
  grantOnNamespace(TEST_UTIL, namespaceUser.getShortName(), namespace, Action.ADMIN);
  // Why I need this pause? I don't need it elsewhere.
  Threads.sleep(1000);
  verifyAllowed(namespaceLockAction, namespaceUser);

  AccessTestAction tableLockAction = new AccessTestAction() {
    @Override public Object run() throws Exception {
      ACCESS_CONTROLLER.preRequestLock(ObserverContextImpl.createAndPrepare(CP_ENV),
          null, tableName, null, null);
      return null;
    }
  };
  verifyAllowed(tableLockAction, SUPERUSER, USER_ADMIN, namespaceUser);
  verifyDenied(tableLockAction, globalRWXUser, tableACUser, tableRWXUser);
  grantOnTable(TEST_UTIL, tableACUser.getShortName(), tableName, null, null,
      Action.ADMIN, Action.CREATE);
  // See if this can fail (flakie) because grant hasn't propagated yet.
  for (int i = 0; i < 10; i++) {
    try {
      verifyAllowed(tableLockAction, tableACUser);
    } catch (AssertionError e) {
      LOG.warn("Retrying assertion error", e);
      Threads.sleep(1000);
      continue;
    }
  }

  AccessTestAction regionsLockAction = new AccessTestAction() {
    @Override public Object run() throws Exception {
      ACCESS_CONTROLLER.preRequestLock(ObserverContextImpl.createAndPrepare(CP_ENV),
          null, null, regionInfos, null);
      return null;
    }
  };
  verifyAllowed(regionsLockAction, SUPERUSER, USER_ADMIN, namespaceUser, tableACUser);
  verifyDenied(regionsLockAction, globalRWXUser, tableRWXUser);

  // Test heartbeats
  // Create a lock procedure and try sending heartbeat to it. It doesn't matter how the lock
  // was created, we just need namespace from the lock's tablename.
  LockProcedure proc = new LockProcedure(conf, tableName, LockType.EXCLUSIVE, "test", null);
  AccessTestAction regionLockHeartbeatAction = new AccessTestAction() {
    @Override public Object run() throws Exception {
      ACCESS_CONTROLLER.preLockHeartbeat(ObserverContextImpl.createAndPrepare(CP_ENV),
          proc.getTableName(), proc.getDescription());
      return null;
    }
  };
  verifyAllowed(regionLockHeartbeatAction, SUPERUSER, USER_ADMIN, namespaceUser, tableACUser);
  verifyDenied(regionLockHeartbeatAction, globalRWXUser, tableRWXUser);
}
 
Example 15
Source File: TestHBCKSCP.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void test() throws Exception {
  // we are about to do one for it?
  MiniHBaseCluster cluster = this.util.getHBaseCluster();

  // Assert that we have three RegionServers. Test depends on there being multiple.
  assertEquals(RS_COUNT, cluster.getLiveRegionServerThreads().size());

  int count;
  try (Table table = createTable(TableName.valueOf(this.name.getMethodName()))) {
    // Load the table with a bit of data so some logs to split and some edits in each region.
    this.util.loadTable(table, HBaseTestingUtility.COLUMNS[0]);
    count = util.countRows(table);
  }
  assertTrue("expected some rows", count > 0);

  // Make the test easier by not working on server hosting meta...
  // Find another RS. Purge it from Master memory w/o running SCP (if
  // SCP runs, it will clear entries from hbase:meta which frustrates
  // our attempt at manufacturing 'Unknown Servers' condition).
  int metaIndex = this.util.getMiniHBaseCluster().getServerWithMeta();
  int rsIndex = (metaIndex + 1) % RS_COUNT;
  ServerName rsServerName = cluster.getRegionServer(rsIndex).getServerName();
  HMaster master = cluster.getMaster();
  // Get a Region that is on the server.
  RegionInfo rsRI = master.getAssignmentManager().getRegionsOnServer(rsServerName).get(0);
  Result r = MetaTableAccessor.getRegionResult(master.getConnection(), rsRI.getRegionName());
  // Assert region is OPEN.
  assertEquals(RegionState.State.OPEN.toString(),
      Bytes.toString(r.getValue(HConstants.CATALOG_FAMILY, HConstants.STATE_QUALIFIER)));
  ServerName serverName = CatalogFamilyFormat.getServerName(r, 0);
  assertEquals(rsServerName, serverName);
  // moveFrom adds to dead servers and adds it to processing list only we will
  // not be processing this server 'normally'. Remove it from processing by
  // calling 'finish' and then remove it from dead servers so rsServerName
  // becomes an 'Unknown Server' even though it is still around.
  master.getServerManager().moveFromOnlineToDeadServers(rsServerName);
  master.getServerManager().getDeadServers().finish(rsServerName);
  master.getServerManager().getDeadServers().removeDeadServer(rsServerName);
  master.getAssignmentManager().getRegionStates().removeServer(rsServerName);
  // Kill the server. Nothing should happen since an 'Unknown Server' as far
  // as the Master is concerned; i.e. no SCP.
  LOG.info("Killing {}", rsServerName);
  HRegionServer hrs = cluster.getRegionServer(rsServerName);
  hrs.abort("KILLED");
  while (!hrs.isStopped()) {
    Threads.sleep(10);
  }
  LOG.info("Dead {}", rsServerName);
  // Now assert still references in hbase:meta to the 'dead' server -- they haven't been
  // cleaned up by an SCP or by anything else.
  assertTrue(searchMeta(master, rsServerName));
  // Assert region is OPEN on dead server still.
  r = MetaTableAccessor.getRegionResult(master.getConnection(), rsRI.getRegionName());
  assertEquals(RegionState.State.OPEN.toString(),
      Bytes.toString(r.getValue(HConstants.CATALOG_FAMILY, HConstants.STATE_QUALIFIER)));
  serverName = CatalogFamilyFormat.getServerName(r, 0);
  assertNotNull(cluster.getRegionServer(serverName));
  assertEquals(rsServerName, serverName);

  // I now have 'Unknown Server' references in hbase:meta; i.e. Server references
  // with no corresponding SCP. Queue one.
  MasterProtos.ScheduleServerCrashProcedureResponse response =
      master.getMasterRpcServices().scheduleServerCrashProcedure(null,
          MasterProtos.ScheduleServerCrashProcedureRequest.newBuilder().
              addServerName(ProtobufUtil.toServerName(rsServerName)).build());
  assertEquals(1, response.getPidCount());
  long pid = response.getPid(0);
  assertNotEquals(Procedure.NO_PROC_ID, pid);
  while (master.getMasterProcedureExecutor().getActiveProcIds().contains(pid)) {
    Threads.sleep(10);
  }
  // After SCP, assert region is OPEN on new server.
  r = MetaTableAccessor.getRegionResult(master.getConnection(), rsRI.getRegionName());
  assertEquals(RegionState.State.OPEN.toString(),
      Bytes.toString(r.getValue(HConstants.CATALOG_FAMILY, HConstants.STATE_QUALIFIER)));
  serverName = CatalogFamilyFormat.getServerName(r, 0);
  assertNotNull(cluster.getRegionServer(serverName));
  assertNotEquals(rsServerName, serverName);
  // Make sure no mention of old server post SCP.
  assertFalse(searchMeta(master, rsServerName));
}
 
Example 16
Source File: TestRegionObserverInterface.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testRecovery() throws Exception {
  LOG.info(TestRegionObserverInterface.class.getName() + "." + name.getMethodName());
  final TableName tableName = TableName.valueOf(TEST_TABLE.getNameAsString() + "." + name.getMethodName());
  Table table = util.createTable(tableName, new byte[][] { A, B, C });
  try (RegionLocator locator = util.getConnection().getRegionLocator(tableName)) {

    JVMClusterUtil.RegionServerThread rs1 = cluster.startRegionServer();
    ServerName sn2 = rs1.getRegionServer().getServerName();
    String regEN = locator.getAllRegionLocations().get(0).getRegion().getEncodedName();

    util.getAdmin().move(Bytes.toBytes(regEN), sn2);
    while (!sn2.equals(locator.getAllRegionLocations().get(0).getServerName())) {
      Thread.sleep(100);
    }

    Put put = new Put(ROW);
    put.addColumn(A, A, A);
    put.addColumn(B, B, B);
    put.addColumn(C, C, C);
    table.put(put);

    // put two times
    table.put(put);

    verifyMethodResult(SimpleRegionObserver.class,
      new String[] { "hadPreGet", "hadPostGet", "hadPrePut", "hadPostPut", "hadPreBatchMutate",
          "hadPostBatchMutate", "hadDelete" },
      tableName, new Boolean[] { false, false, true, true, true, true, false });

    verifyMethodResult(SimpleRegionObserver.class,
      new String[] { "getCtPreReplayWALs", "getCtPostReplayWALs", "getCtPreWALRestore",
          "getCtPostWALRestore", "getCtPrePut", "getCtPostPut" },
      tableName, new Integer[] { 0, 0, 0, 0, 2, 2 });

    cluster.killRegionServer(rs1.getRegionServer().getServerName());
    Threads.sleep(1000); // Let the kill soak in.
    util.waitUntilAllRegionsAssigned(tableName);
    LOG.info("All regions assigned");

    verifyMethodResult(SimpleRegionObserver.class,
      new String[] { "getCtPreReplayWALs", "getCtPostReplayWALs", "getCtPreWALRestore",
          "getCtPostWALRestore", "getCtPrePut", "getCtPostPut" },
      tableName, new Integer[] { 1, 1, 2, 2, 0, 0 });
  } finally {
    util.deleteTable(tableName);
    table.close();
  }
}
 
Example 17
Source File: TestSnapshotScannerHDFSAclController.java    From hbase with Apache License 2.0 4 votes vote down vote up
private void snapshotAndWait(final String snapShotName, final TableName tableName)
  throws Exception{
  admin.snapshot(snapShotName, tableName);
  LOG.info("Sleep for three seconds, waiting for HDFS Acl setup");
  Threads.sleep(3000);
}
 
Example 18
Source File: TestSplitOrMergeStatus.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Ignore @Test
public void testMergeSwitch() throws Exception {
  final TableName tableName = TableName.valueOf(name.getMethodName());
  Table t = TEST_UTIL.createTable(tableName, FAMILY);
  TEST_UTIL.loadTable(t, FAMILY, false);

  Admin admin = TEST_UTIL.getAdmin();
  int originalCount = admin.getRegions(tableName).size();
  initSwitchStatus(admin);
  admin.split(t.getName());
  int postSplitCount = -1;
  while ((postSplitCount = admin.getRegions(tableName).size()) == originalCount) {
    Threads.sleep(1);
  }
  assertTrue("originalCount=" + originalCount + ", newCount=" + postSplitCount,
      originalCount != postSplitCount);

  // Merge switch is off so merge should NOT succeed.
  boolean result = admin.mergeSwitch(false, false);
  assertTrue(result);
  List<RegionInfo> regions = admin.getRegions(t.getName());
  assertTrue(regions.size() > 1);
  Future<?> f = admin.mergeRegionsAsync(regions.get(0).getEncodedNameAsBytes(),
    regions.get(1).getEncodedNameAsBytes(), true);
  try {
    f.get(10, TimeUnit.SECONDS);
    fail("Should not get here.");
  } catch (ExecutionException ee) {
    // Expected.
  }
  int count = admin.getRegions(tableName).size();
  assertTrue("newCount=" + postSplitCount + ", count=" + count, postSplitCount == count);

  result = admin.mergeSwitch(true, false);
  regions = admin.getRegions(t.getName());
  assertFalse(result);
  f = admin.mergeRegionsAsync(regions.get(0).getEncodedNameAsBytes(),
    regions.get(1).getEncodedNameAsBytes(), true);
  f.get(10, TimeUnit.SECONDS);
  count = admin.getRegions(tableName).size();
  assertTrue((postSplitCount / 2 /*Merge*/) == count);
  admin.close();
}
 
Example 19
Source File: TestClientOperationInterrupt.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
public void preGetOp(final ObserverContext<RegionCoprocessorEnvironment> e,
                     final Get get, final List<Cell> results) throws IOException {
  Threads.sleep(2500);
}
 
Example 20
Source File: AbstractTestCITimeout.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
public Result preIncrement(final ObserverContext<RegionCoprocessorEnvironment> e,
    final Increment increment) throws IOException {
  Threads.sleep(SLEEP_TIME);
  return null;
}