@Test
  public void testPreWALRestoreSkip() throws Exception {
    LOG.info(TestRegionObserverInterface.class.getName() + ".testPreWALRestoreSkip");
    TableName tableName = TableName.valueOf(SimpleRegionObserver.TABLE_SKIPPED);
    HTable table = util.createTable(tableName, new byte[][] {A, B, C});

    JVMClusterUtil.RegionServerThread rs1 = cluster.startRegionServer();
    ServerName sn2 = rs1.getRegionServer().getServerName();
    String regEN = table.getRegionLocations().firstEntry().getKey().getEncodedName();

    util.getHBaseAdmin().move(regEN.getBytes(), sn2.getServerName().getBytes());
    while (!sn2.equals(table.getRegionLocations().firstEntry().getValue())) {
      Thread.sleep(100);
    }

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

    cluster.killRegionServer(rs1.getRegionServer().getServerName());
    Threads.sleep(20000); // just to be sure that the kill has fully started.
    util.waitUntilAllRegionsAssigned(tableName);

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

    util.deleteTable(tableName);
    table.close();
  }
  private static void waitForAllRegionsOnline() throws Exception {
    // Wait for regions to come back on line again.

    boolean done = false;
    while (!done) {
      Thread.sleep(1);

      // Nothing in ZK RIT for a start
      ZKAssign.blockUntilNoRIT(TEST_UTIL.getZooKeeperWatcher());

      // Then we want all the regions to be marked as available...
      if (!isAllRegionsOnline()) continue;

      // And without any work in progress on the master side
      if (TEST_UTIL
          .getMiniHBaseCluster()
          .getMaster()
          .getAssignmentManager()
          .getRegionStates()
          .isRegionsInTransition()) continue;

      // nor on the region server side
      done = true;
      for (JVMClusterUtil.RegionServerThread rs :
          TEST_UTIL.getMiniHBaseCluster().getLiveRegionServerThreads()) {
        if (!rs.getRegionServer().getRegionsInTransitionInRS().isEmpty()) {
          done = false;
        }
      }
    }
  }
Ejemplo n.º 3
0
 private List<HRegionServer> getOnlineRegionServers() {
   List<HRegionServer> list = new ArrayList<HRegionServer>();
   for (JVMClusterUtil.RegionServerThread rst : cluster.getRegionServerThreads()) {
     if (rst.getRegionServer().isOnline()) {
       list.add(rst.getRegionServer());
     }
   }
   return list;
 }
  @Test
  public void testRecovery() throws Exception {
    LOG.info(TestRegionObserverInterface.class.getName() + ".testRecovery");
    TableName tableName = TableName.valueOf(TEST_TABLE.getNameAsString() + ".testRecovery");
    HTable table = util.createTable(tableName, new byte[][] {A, B, C});
    try {
      JVMClusterUtil.RegionServerThread rs1 = cluster.startRegionServer();
      ServerName sn2 = rs1.getRegionServer().getServerName();
      String regEN = table.getRegionLocations().firstEntry().getKey().getEncodedName();

      util.getHBaseAdmin().move(regEN.getBytes(), sn2.getServerName().getBytes());
      while (!sn2.equals(table.getRegionLocations().firstEntry().getValue())) {
        Thread.sleep(100);
      }

      Put put = new Put(ROW);
      put.add(A, A, A);
      put.add(B, B, B);
      put.add(C, C, C);
      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[] {"getCtPreWALRestore", "getCtPostWALRestore", "getCtPrePut", "getCtPostPut"},
          tableName,
          new Integer[] {0, 0, 1, 1});

      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[] {"getCtPrePut", "getCtPostPut"},
          tableName,
          new Integer[] {0, 0});
    } finally {
      util.deleteTable(tableName);
      table.close();
    }
  }
 /**
  * @return List of running servers (Some servers may have been killed or aborted during lifetime
  *     of cluster; these servers are not included in this list).
  */
 public List<JVMClusterUtil.RegionServerThread> getLiveRegionServers() {
   List<JVMClusterUtil.RegionServerThread> liveServers =
       new ArrayList<JVMClusterUtil.RegionServerThread>();
   List<RegionServerThread> list = getRegionServers();
   for (JVMClusterUtil.RegionServerThread rst : list) {
     if (rst.isAlive()) liveServers.add(rst);
     else LOG.info("Not alive " + rst.getName());
   }
   return liveServers;
 }
 /**
  * Wait for the specified region server to stop Removes this thread from list of running threads.
  *
  * @param serverNumber
  * @return Name of region server that just went down.
  */
 public String waitOnRegionServer(int serverNumber) {
   JVMClusterUtil.RegionServerThread regionServerThread = this.regionThreads.remove(serverNumber);
   while (regionServerThread.isAlive()) {
     try {
       LOG.info("Waiting on " + regionServerThread.getRegionServer().toString());
       regionServerThread.join();
     } catch (InterruptedException e) {
       e.printStackTrace();
     }
   }
   return regionServerThread.getName();
 }
 /**
  * Wait for the specified region server to stop Removes this thread from list of running threads.
  *
  * @param rst
  * @return Name of region server that just went down.
  */
 public String waitOnRegionServer(JVMClusterUtil.RegionServerThread rst) {
   while (rst.isAlive()) {
     try {
       LOG.info("Waiting on " + rst.getRegionServer().toString());
       rst.join();
     } catch (InterruptedException e) {
       e.printStackTrace();
     }
   }
   for (int i = 0; i < regionThreads.size(); i++) {
     if (regionThreads.get(i) == rst) {
       regionThreads.remove(i);
       break;
     }
   }
   return rst.getName();
 }
  // check each region whether the coprocessor upcalls are called or not.
  private void verifyMethodResult(
      Class<?> c, String methodName[], TableName tableName, Object value[]) throws IOException {
    try {
      for (JVMClusterUtil.RegionServerThread t : cluster.getRegionServerThreads()) {
        if (!t.isAlive() || t.getRegionServer().isAborted() || t.getRegionServer().isStopping()) {
          continue;
        }
        for (HRegionInfo r : ProtobufUtil.getOnlineRegions(t.getRegionServer())) {
          if (!r.getTable().equals(tableName)) {
            continue;
          }
          RegionCoprocessorHost cph =
              t.getRegionServer().getOnlineRegion(r.getRegionName()).getCoprocessorHost();

          Coprocessor cp = cph.findCoprocessor(c.getName());
          assertNotNull(cp);
          for (int i = 0; i < methodName.length; ++i) {
            Method m = c.getMethod(methodName[i]);
            Object o = m.invoke(cp);
            assertTrue(
                "Result of "
                    + c.getName()
                    + "."
                    + methodName[i]
                    + " is expected to be "
                    + value[i].toString()
                    + ", while we get "
                    + o.toString(),
                o.equals(value[i]));
          }
        }
      }
    } catch (Exception e) {
      throw new IOException(e.toString());
    }
  }
Ejemplo n.º 9
0
  @Test(timeout = 60000)
  public void testAssignmentListener() throws IOException, InterruptedException {
    AssignmentManager am = TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager();
    Admin admin = TEST_UTIL.getHBaseAdmin();

    DummyAssignmentListener listener = new DummyAssignmentListener();
    am.registerListener(listener);
    try {
      final String TABLE_NAME_STR = "testtb";
      final TableName TABLE_NAME = TableName.valueOf(TABLE_NAME_STR);
      final byte[] FAMILY = Bytes.toBytes("cf");

      // Create a new table, with a single region
      LOG.info("Create Table");
      TEST_UTIL.createTable(TABLE_NAME, FAMILY);
      listener.awaitModifications(1);
      assertEquals(1, listener.getLoadCount());
      assertEquals(0, listener.getCloseCount());

      // Add some data
      HTable table = new HTable(TEST_UTIL.getConfiguration(), TABLE_NAME);
      try {
        for (int i = 0; i < 10; ++i) {
          byte[] key = Bytes.toBytes("row-" + i);
          Put put = new Put(key);
          put.add(FAMILY, null, key);
          table.put(put);
        }
      } finally {
        table.close();
      }

      // Split the table in two
      LOG.info("Split Table");
      listener.reset();
      admin.split(TABLE_NAME_STR, "row-3");
      listener.awaitModifications(3);
      assertEquals(2, listener.getLoadCount()); // daughters added
      assertEquals(1, listener.getCloseCount()); // parent removed

      // Wait for the Regions to be mergeable
      MiniHBaseCluster miniCluster = TEST_UTIL.getMiniHBaseCluster();
      int mergeable = 0;
      while (mergeable < 2) {
        Thread.sleep(100);
        admin.majorCompact(TABLE_NAME_STR);
        mergeable = 0;
        for (JVMClusterUtil.RegionServerThread regionThread :
            miniCluster.getRegionServerThreads()) {
          for (HRegion region : regionThread.getRegionServer().getOnlineRegions(TABLE_NAME)) {
            mergeable += region.isMergeable() ? 1 : 0;
          }
        }
      }

      // Merge the two regions
      LOG.info("Merge Regions");
      listener.reset();
      List<HRegionInfo> regions = admin.getTableRegions(TABLE_NAME);
      assertEquals(2, regions.size());
      admin.mergeRegions(
          regions.get(0).getEncodedNameAsBytes(), regions.get(1).getEncodedNameAsBytes(), true);
      listener.awaitModifications(3);
      assertEquals(1, admin.getTableRegions(TABLE_NAME).size());
      assertEquals(1, listener.getLoadCount()); // new merged region added
      assertEquals(2, listener.getCloseCount()); // daughters removed

      // Delete the table
      LOG.info("Drop Table");
      listener.reset();
      TEST_UTIL.deleteTable(TABLE_NAME);
      listener.awaitModifications(1);
      assertEquals(0, listener.getLoadCount());
      assertEquals(1, listener.getCloseCount());
    } finally {
      am.unregisterListener(listener);
    }
  }
Ejemplo n.º 10
0
 private static void closeAllRegionServerThreads(
     List<JVMClusterUtil.RegionServerThread> regionservers) {
   for (JVMClusterUtil.RegionServerThread t : regionservers) {
     t.getRegionServer().stop("HMaster Aborted; Bringing down regions servers");
   }
 }