Java 类org.apache.hadoop.hbase.CoordinatedStateManagerFactory 实例源码

项目:ditb    文件:HRegionServerCommandLine.java   
private int start() throws Exception {
  Configuration conf = getConf();
  HRegionServer.loadWinterConf(conf, null);
  CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(conf);
  try {
    // If 'local', don't start a region server here. Defer to
    // LocalHBaseCluster. It manages 'local' clusters.
    if (LocalHBaseCluster.isLocal(conf)) {
      LOG.warn("Not starting a distinct region server because " + HConstants.CLUSTER_DISTRIBUTED
          + " is false");
    } else {
      logProcessInfo(getConf());
      HRegionServer hrs = HRegionServer.constructRegionServer(regionServerClass, conf, cp);
      hrs.start();
      hrs.join();
      if (hrs.isAborted()) {
        throw new RuntimeException("HRegionServer Aborted");
      }
    }
  } catch (Throwable t) {
    LOG.error("Region server exiting", t);
    return 1;
  }
  return 0;
}
项目:ditb    文件:TestClusterId.java   
@Test
public void testClusterId() throws Exception  {
  TEST_UTIL.startMiniZKCluster();
  TEST_UTIL.startMiniDFSCluster(1);

  Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
  CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(conf);
  //start region server, needs to be separate
  //so we get an unset clusterId
  rst = JVMClusterUtil.createRegionServerThread(conf,cp,
      HRegionServer.class, 0);
  rst.start();
  //Make sure RS is in blocking state
  Thread.sleep(10000);

  TEST_UTIL.startMiniHBaseCluster(1, 1);

  rst.waitForServerOnline();

  String clusterId = ZKClusterId.readClusterIdZNode(TEST_UTIL.getZooKeeperWatcher());
  assertNotNull(clusterId);
  assertEquals(clusterId, rst.getRegionServer().getClusterId());
}
项目:pbase    文件:HRegionServerCommandLine.java   
private int start() throws Exception {
  Configuration conf = getConf();
  CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(conf);
  try {
    // If 'local', don't start a region server here. Defer to
    // LocalHBaseCluster. It manages 'local' clusters.
    if (LocalHBaseCluster.isLocal(conf)) {
      LOG.warn("Not starting a distinct region server because "
          + HConstants.CLUSTER_DISTRIBUTED + " is false");
    } else {
      logProcessInfo(getConf());
      HRegionServer hrs = HRegionServer.constructRegionServer(regionServerClass, conf, cp);
      hrs.start();
      hrs.join();
      if (hrs.isAborted()) {
        throw new RuntimeException("HRegionServer Aborted");
      }
    }
  } catch (Throwable t) {
    LOG.error("Region server exiting", t);
    return 1;
  }
  return 0;
}
项目:pbase    文件:TestClusterId.java   
@Test
public void testClusterId() throws Exception  {
  TEST_UTIL.startMiniZKCluster();
  TEST_UTIL.startMiniDFSCluster(1);

  Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
  CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(conf);
  //start region server, needs to be separate
  //so we get an unset clusterId
  rst = JVMClusterUtil.createRegionServerThread(conf,cp,
      HRegionServer.class, 0);
  rst.start();
  //Make sure RS is in blocking state
  Thread.sleep(10000);

  TEST_UTIL.startMiniHBaseCluster(1, 1);

  rst.waitForServerOnline();

  String clusterId = ZKClusterId.readClusterIdZNode(TEST_UTIL.getZooKeeperWatcher());
  assertNotNull(clusterId);
  assertEquals(clusterId, rst.getRegionServer().getClusterId());
}
项目:PyroDB    文件:HRegionServerCommandLine.java   
private int start() throws Exception {
  Configuration conf = getConf();
  CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(conf);
  try {
    // If 'local', don't start a region server here. Defer to
    // LocalHBaseCluster. It manages 'local' clusters.
    if (LocalHBaseCluster.isLocal(conf)) {
      LOG.warn("Not starting a distinct region server because "
          + HConstants.CLUSTER_DISTRIBUTED + " is false");
    } else {
      logProcessInfo(getConf());
      HRegionServer hrs = HRegionServer.constructRegionServer(regionServerClass, conf, cp);
      hrs.start();
      hrs.join();
      if (hrs.isAborted()) {
        throw new RuntimeException("HRegionServer Aborted");
      }
    }
  } catch (Throwable t) {
    LOG.error("Region server exiting", t);
    return 1;
  }
  return 0;
}
项目:PyroDB    文件:TestAssignmentManager.java   
/**
 * Test verifies whether stale znodes of unknown tables as for the hbase:meta will be removed or
 * not.
 * @throws KeeperException
 * @throws IOException
 * @throws Exception
 */
@Test
public void testMasterRestartShouldRemoveStaleZnodesOfUnknownTableAsForMeta()
    throws Exception {
  List<ServerName> destServers = new ArrayList<ServerName>(1);
  destServers.add(SERVERNAME_A);
  Mockito.when(this.serverManager.createDestinationServersList()).thenReturn(destServers);
  Mockito.when(this.serverManager.isServerOnline(SERVERNAME_A)).thenReturn(true);
  HTU.getConfiguration().setInt(HConstants.MASTER_PORT, 0);
  CoordinatedStateManager csm = CoordinatedStateManagerFactory.getCoordinatedStateManager(
    HTU.getConfiguration());
  Server server = new HMaster(HTU.getConfiguration(), csm);
  Whitebox.setInternalState(server, "serverManager", this.serverManager);
  AssignmentManagerWithExtrasForTesting am = setUpMockedAssignmentManager(server,
      this.serverManager);
  try {
    TableName tableName = TableName.valueOf("dummyTable");
    // set table in enabling state.
    am.getTableStateManager().setTableState(tableName,
      Table.State.ENABLING);
    am.joinCluster();
    assertFalse("Table should not be present in zookeeper.",
      am.getTableStateManager().isTablePresent(tableName));
  } finally {
  }
}
项目:PyroDB    文件:TestClusterId.java   
@Test
public void testClusterId() throws Exception  {
  TEST_UTIL.startMiniZKCluster();
  TEST_UTIL.startMiniDFSCluster(1);

  Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
  CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(conf);
  //start region server, needs to be separate
  //so we get an unset clusterId
  rst = JVMClusterUtil.createRegionServerThread(conf,cp,
      HRegionServer.class, 0);
  rst.start();
  //Make sure RS is in blocking state
  Thread.sleep(10000);

  TEST_UTIL.startMiniHBaseCluster(1, 0);

  rst.waitForServerOnline();

  String clusterId = ZKClusterId.readClusterIdZNode(TEST_UTIL.getZooKeeperWatcher());
  assertNotNull(clusterId);
  assertEquals(clusterId, rst.getRegionServer().getClusterId());
}
项目:ditb    文件:TestMasterNoCluster.java   
/**
 * Test starting master then stopping it before its fully up.
 * @throws IOException
 * @throws KeeperException
 * @throws InterruptedException
 */
@Test (timeout=30000)
public void testStopDuringStart()
throws IOException, KeeperException, InterruptedException {
  CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(
    TESTUTIL.getConfiguration());
  HMaster master = new HMaster(TESTUTIL.getConfiguration(), cp);
  master.start();
  // Immediately have it stop.  We used hang in assigning meta.
  master.stopMaster();
  master.join();
}
项目:ditb    文件:TestMasterPriorityRpc.java   
@Before
public void setup() {
  Configuration conf = HBaseConfiguration.create();
  conf.setBoolean("hbase.testing.nocluster", true); // No need to do ZK
  CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(conf);
  master = HMaster.constructMaster(HMaster.class, conf, cp);
  priority = master.getMasterRpcServices().getPriority();
  user = User.createUserForTesting(conf, "someuser", new String[]{"somegroup"});
}
项目:ditb    文件:TestHMasterRPCException.java   
@Before
public void setUp() throws Exception {
  Configuration conf = testUtil.getConfiguration();
  conf.set(HConstants.MASTER_PORT, "0");
  conf.setInt(HConstants.ZK_SESSION_TIMEOUT, 2000);
  testUtil.startMiniZKCluster();

  CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(conf);
  ZooKeeperWatcher watcher = testUtil.getZooKeeperWatcher();
  ZKUtil.createWithParents(watcher, watcher.getMasterAddressZNode(), Bytes.toBytes("fake:123"));
  master = new HMaster(conf, cp);
  rpcClient = RpcClientFactory.createClient(conf, HConstants.CLUSTER_ID_DEFAULT);
}
项目:ditb    文件:TestRegionMergeTransaction.java   
@Test
public void testFailAfterPONR() throws IOException, KeeperException, InterruptedException {
  final int rowCountOfRegionA = loadRegion(this.region_a, CF, true);
  final int rowCountOfRegionB = loadRegion(this.region_b, CF, true);
  assertTrue(rowCountOfRegionA > 0 && rowCountOfRegionB > 0);
  assertEquals(rowCountOfRegionA, countRows(this.region_a));
  assertEquals(rowCountOfRegionB, countRows(this.region_b));

  // Start transaction.
  RegionMergeTransactionImpl mt = prepareOnGoodRegions();
  Mockito.doThrow(new MockedFailedMergedRegionOpen())
      .when(mt)
      .openMergedRegion((Server) Mockito.anyObject(),
          (RegionServerServices) Mockito.anyObject(),
          (HRegion) Mockito.anyObject());

  // Run the execute. Look at what it returns.
  boolean expectedException = false;
  TEST_UTIL.getConfiguration().setInt(HConstants.REGIONSERVER_PORT, 0);
  CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(
    TEST_UTIL.getConfiguration());
  Server mockServer = new HRegionServer(TEST_UTIL.getConfiguration(), cp);
  try {
    mt.execute(mockServer, null);
  } catch (MockedFailedMergedRegionOpen e) {
    expectedException = true;
  }
  assertTrue(expectedException);
  // Run rollback returns false that we should restart.
  assertFalse(mt.rollback(null, null));
  // Make sure that merged region is still in the filesystem, that
  // they have not been removed; this is supposed to be the case if we go
  // past point of no return.
  Path tableDir = this.region_a.getRegionFileSystem().getRegionDir()
      .getParent();
  Path mergedRegionDir = new Path(tableDir, mt.getMergedRegionInfo()
      .getEncodedName());
  assertTrue(TEST_UTIL.getTestFileSystem().exists(mergedRegionDir));
}
项目:ditb    文件:TestPriorityRpc.java   
@Before
public void setup() {
  Configuration conf = HBaseConfiguration.create();
  conf.setBoolean("hbase.testing.nocluster", true); // No need to do ZK
  CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(conf);
  regionServer = HRegionServer.constructRegionServer(HRegionServer.class, conf, cp);
  priority = regionServer.rpcServices.getPriority();
}
项目:pbase    文件:TestMasterNoCluster.java   
/**
 * Test starting master then stopping it before its fully up.
 * @throws IOException
 * @throws KeeperException
 * @throws InterruptedException
 */
@Test (timeout=30000)
public void testStopDuringStart()
throws IOException, KeeperException, InterruptedException {
  CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(
    TESTUTIL.getConfiguration());
  HMaster master = new HMaster(TESTUTIL.getConfiguration(), cp);
  master.start();
  // Immediately have it stop.  We used hang in assigning meta.
  master.stopMaster();
  master.join();
}
项目:pbase    文件:TestAssignmentManager.java   
/**
 * Test verifies whether stale znodes of unknown tables as for the hbase:meta will be removed or
 * not.
 * @throws KeeperException
 * @throws IOException
 * @throws Exception
 */
@Test (timeout=180000)
public void testMasterRestartShouldRemoveStaleZnodesOfUnknownTableAsForMeta()
    throws Exception {
  List<ServerName> destServers = new ArrayList<ServerName>(1);
  destServers.add(SERVERNAME_A);
  Mockito.when(this.serverManager.createDestinationServersList()).thenReturn(destServers);
  Mockito.when(this.serverManager.isServerOnline(SERVERNAME_A)).thenReturn(true);
  HTU.getConfiguration().setInt(HConstants.MASTER_PORT, 0);
  CoordinatedStateManager csm = CoordinatedStateManagerFactory.getCoordinatedStateManager(
    HTU.getConfiguration());
  Server server = new HMaster(HTU.getConfiguration(), csm);
  Whitebox.setInternalState(server, "serverManager", this.serverManager);
  AssignmentManagerWithExtrasForTesting am = setUpMockedAssignmentManager(server,
      this.serverManager);

  Whitebox.setInternalState(server, "metaTableLocator", Mockito.mock(MetaTableLocator.class));

  // Make it so we can get a catalogtracker from servermanager.. .needed
  // down in guts of server shutdown handler.
  Whitebox.setInternalState(server, "clusterConnection", am.getConnection());

  try {
    TableName tableName = TableName.valueOf("dummyTable");
    // set table in enabling state.
    am.getTableStateManager().setTableState(tableName,
      Table.State.ENABLING);
    am.joinCluster();
    assertFalse("Table should not be present in zookeeper.",
      am.getTableStateManager().isTablePresent(tableName));
  } finally {
    am.shutdown();
  }
}
项目:pbase    文件:TestRegionMergeTransaction.java   
@Test
public void testFailAfterPONR() throws IOException, KeeperException, InterruptedException {
  final int rowCountOfRegionA = loadRegion(this.region_a, CF, true);
  final int rowCountOfRegionB = loadRegion(this.region_b, CF, true);
  assertTrue(rowCountOfRegionA > 0 && rowCountOfRegionB > 0);
  assertEquals(rowCountOfRegionA, countRows(this.region_a));
  assertEquals(rowCountOfRegionB, countRows(this.region_b));

  // Start transaction.
  RegionMergeTransaction mt = prepareOnGoodRegions();
  Mockito.doThrow(new MockedFailedMergedRegionOpen())
      .when(mt)
      .openMergedRegion((Server) Mockito.anyObject(),
          (RegionServerServices) Mockito.anyObject(),
          (HRegion) Mockito.anyObject());

  // Run the execute. Look at what it returns.
  boolean expectedException = false;
  TEST_UTIL.getConfiguration().setInt(HConstants.REGIONSERVER_PORT, 0);
  CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(
    TEST_UTIL.getConfiguration());
  Server mockServer = new HRegionServer(TEST_UTIL.getConfiguration(), cp);
  try {
    mt.execute(mockServer, null);
  } catch (MockedFailedMergedRegionOpen e) {
    expectedException = true;
  }
  assertTrue(expectedException);
  // Run rollback returns false that we should restart.
  assertFalse(mt.rollback(null, null));
  // Make sure that merged region is still in the filesystem, that
  // they have not been removed; this is supposed to be the case if we go
  // past point of no return.
  Path tableDir = this.region_a.getRegionFileSystem().getRegionDir()
      .getParent();
  Path mergedRegionDir = new Path(tableDir, mt.getMergedRegionInfo()
      .getEncodedName());
  assertTrue(TEST_UTIL.getTestFileSystem().exists(mergedRegionDir));
}
项目:pbase    文件:TestPriorityRpc.java   
@Before
public void setup() {
  Configuration conf = HBaseConfiguration.create();
  conf.setBoolean("hbase.testing.nocluster", true); // No need to do ZK
  CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(conf);
  regionServer = HRegionServer.constructRegionServer(HRegionServer.class, conf, cp);
  priority = regionServer.rpcServices.getPriority();
}
项目:PyroDB    文件:TestMasterNoCluster.java   
/**
 * Test starting master then stopping it before its fully up.
 * @throws IOException
 * @throws KeeperException
 * @throws InterruptedException
 */
@Test (timeout=30000)
public void testStopDuringStart()
throws IOException, KeeperException, InterruptedException {
  CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(
    TESTUTIL.getConfiguration());
  HMaster master = new HMaster(TESTUTIL.getConfiguration(), cp);
  master.start();
  // Immediately have it stop.  We used hang in assigning meta.
  master.stopMaster();
  master.join();
}
项目:PyroDB    文件:TestAssignmentManager.java   
/**
 * Test verifies whether all the enabling table regions assigned only once during master startup.
 *
 * @throws KeeperException
 * @throws IOException
 * @throws Exception
 */
@Test
public void testMasterRestartWhenTableInEnabling() throws KeeperException, IOException, Exception {
  enabling = true;
  List<ServerName> destServers = new ArrayList<ServerName>(1);
  destServers.add(SERVERNAME_A);
  Mockito.when(this.serverManager.createDestinationServersList()).thenReturn(destServers);
  Mockito.when(this.serverManager.isServerOnline(SERVERNAME_A)).thenReturn(true);
  HTU.getConfiguration().setInt(HConstants.MASTER_PORT, 0);
  CoordinatedStateManager csm = CoordinatedStateManagerFactory.getCoordinatedStateManager(
    HTU.getConfiguration());
  Server server = new HMaster(HTU.getConfiguration(), csm);
  Whitebox.setInternalState(server, "serverManager", this.serverManager);
  AssignmentManagerWithExtrasForTesting am = setUpMockedAssignmentManager(server,
      this.serverManager);
  try {
    // set table in enabling state.
    am.getTableStateManager().setTableState(REGIONINFO.getTable(),
      Table.State.ENABLING);
    new EnableTableHandler(server, REGIONINFO.getTable(),
        am.getCatalogTracker(), am, new NullTableLockManager(), true).prepare()
        .process();
    assertEquals("Number of assignments should be 1.", 1, assignmentCount);
    assertTrue("Table should be enabled.",
        am.getTableStateManager().isTableState(REGIONINFO.getTable(),
          Table.State.ENABLED));
  } finally {
    enabling = false;
    assignmentCount = 0;
    am.getTableStateManager().setTableState(REGIONINFO.getTable(),
      Table.State.ENABLED);
    am.shutdown();
    ZKAssign.deleteAllNodes(this.watcher);
  }
}
项目:PyroDB    文件:TestRegionMergeTransaction.java   
@Test
public void testFailAfterPONR() throws IOException, KeeperException, InterruptedException {
  final int rowCountOfRegionA = loadRegion(this.region_a, CF, true);
  final int rowCountOfRegionB = loadRegion(this.region_b, CF, true);
  assertTrue(rowCountOfRegionA > 0 && rowCountOfRegionB > 0);
  assertEquals(rowCountOfRegionA, countRows(this.region_a));
  assertEquals(rowCountOfRegionB, countRows(this.region_b));

  // Start transaction.
  RegionMergeTransaction mt = prepareOnGoodRegions();
  Mockito.doThrow(new MockedFailedMergedRegionOpen())
      .when(mt)
      .openMergedRegion((Server) Mockito.anyObject(),
          (RegionServerServices) Mockito.anyObject(),
          (HRegion) Mockito.anyObject());

  // Run the execute. Look at what it returns.
  boolean expectedException = false;
  TEST_UTIL.getConfiguration().setInt(HConstants.REGIONSERVER_PORT, 0);
  CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(
    TEST_UTIL.getConfiguration());
  Server mockServer = new HRegionServer(TEST_UTIL.getConfiguration(), cp);
  try {
    mt.execute(mockServer, null);
  } catch (MockedFailedMergedRegionOpen e) {
    expectedException = true;
  }
  assertTrue(expectedException);
  // Run rollback returns false that we should restart.
  assertFalse(mt.rollback(null, null));
  // Make sure that merged region is still in the filesystem, that
  // they have not been removed; this is supposed to be the case if we go
  // past point of no return.
  Path tableDir = this.region_a.getRegionFileSystem().getRegionDir()
      .getParent();
  Path mergedRegionDir = new Path(tableDir, mt.getMergedRegionInfo()
      .getEncodedName());
  assertTrue(TEST_UTIL.getTestFileSystem().exists(mergedRegionDir));
}
项目:PyroDB    文件:TestPriorityRpc.java   
@Before
public void setup() {
  Configuration conf = HBaseConfiguration.create();
  conf.setBoolean("hbase.testing.nocluster", true); // No need to do ZK
  CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(conf);
  regionServer = HRegionServer.constructRegionServer(HRegionServer.class, conf, cp);
  priority = regionServer.rpcServices.getPriority();
}
项目:ditb    文件:TestMasterNoCluster.java   
@Test
public void testNotPullingDeadRegionServerFromZK()
    throws IOException, KeeperException, InterruptedException {
  final Configuration conf = TESTUTIL.getConfiguration();
  final ServerName newServer = ServerName.valueOf("test.sample", 1, 101);
  final ServerName deadServer = ServerName.valueOf("test.sample", 1, 100);
  final MockRegionServer rs0 = new MockRegionServer(conf, newServer);

  CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(
    TESTUTIL.getConfiguration());
  HMaster master = new HMaster(conf, cp) {
    @Override
    void assignMeta(MonitoredTask status, Set<ServerName> previouslyFailedMeatRSs, int replicaId)
    { }

    @Override
    void initializeZKBasedSystemTrackers() throws IOException,
    InterruptedException, KeeperException, CoordinatedStateException {
      super.initializeZKBasedSystemTrackers();
      // Record a newer server in server manager at first
      serverManager.recordNewServerWithLock(newServer, ServerLoad.EMPTY_SERVERLOAD);

      List<ServerName> onlineServers = new ArrayList<ServerName>();
      onlineServers.add(deadServer);
      onlineServers.add(newServer);
      // Mock the region server tracker to pull the dead server from zk
      regionServerTracker = Mockito.spy(regionServerTracker);
      Mockito.doReturn(onlineServers).when(
        regionServerTracker).getOnlineServers();
    }

    @Override
    public ClusterConnection getConnection() {
      // Insert a mock for the connection, use TESTUTIL.getConfiguration rather than
      // the conf from the master; the conf will already have an HConnection
      // associate so the below mocking of a connection will fail.
      try {
        return HConnectionTestingUtility.getMockedConnectionAndDecorate(
          TESTUTIL.getConfiguration(), rs0, rs0, rs0.getServerName(),
          HRegionInfo.FIRST_META_REGIONINFO);
      } catch (IOException e) {
        return null;
      }
    }

    @Override
    void initNamespace() {
    }
  };
  master.start();

  try {
    // Wait till master is initialized.
    while (!master.isInitialized()) Threads.sleep(10);
    LOG.info("Master is initialized");

    assertFalse("The dead server should not be pulled in",
      master.serverManager.isServerOnline(deadServer));
  } finally {
    master.stopMaster();
    master.join();
  }
}
项目:ditb    文件:TestSplitLogManager.java   
public DummyServer(ZooKeeperWatcher zkw, Configuration conf) {
  this.zkw = zkw;
  this.conf = conf;
  cm = CoordinatedStateManagerFactory.getCoordinatedStateManager(conf);
  cm.initialize(this);
}
项目:ditb    文件:TestSplitLogWorker.java   
public DummyServer(ZooKeeperWatcher zkw, Configuration conf) {
  this.zkw = zkw;
  this.conf = conf;
  cm = CoordinatedStateManagerFactory.getCoordinatedStateManager(conf);
  cm.initialize(this);
}
项目:ditb    文件:TestRegionMergeTransaction.java   
@Test
public void testWholesomeMerge() throws IOException, InterruptedException {
  final int rowCountOfRegionA = loadRegion(this.region_a, CF, true);
  final int rowCountOfRegionB = loadRegion(this.region_b, CF, true);
  assertTrue(rowCountOfRegionA > 0 && rowCountOfRegionB > 0);
  assertEquals(rowCountOfRegionA, countRows(this.region_a));
  assertEquals(rowCountOfRegionB, countRows(this.region_b));

  // Start transaction.
  RegionMergeTransactionImpl mt = prepareOnGoodRegions();

  // Run the execute. Look at what it returns.
  TEST_UTIL.getConfiguration().setInt(HConstants.REGIONSERVER_PORT, 0);
  CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(
    TEST_UTIL.getConfiguration());
  Server mockServer = new HRegionServer(TEST_UTIL.getConfiguration(), cp);
  HRegion mergedRegion = (HRegion)mt.execute(mockServer, null);
  // Do some assertions about execution.
  assertTrue(this.fs.exists(mt.getMergesDir()));
  // Assert region_a and region_b is closed.
  assertTrue(region_a.isClosed());
  assertTrue(region_b.isClosed());

  // Assert mergedir is empty -- because its content will have been moved out
  // to be under the merged region dirs.
  assertEquals(0, this.fs.listStatus(mt.getMergesDir()).length);
  // Check merged region have correct key span.
  assertTrue(Bytes.equals(this.region_a.getRegionInfo().getStartKey(),
      mergedRegion.getRegionInfo().getStartKey()));
  assertTrue(Bytes.equals(this.region_b.getRegionInfo().getEndKey(),
      mergedRegion.getRegionInfo().getEndKey()));
  // Count rows. merged region are already open
  try {
    int mergedRegionRowCount = countRows(mergedRegion);
    assertEquals((rowCountOfRegionA + rowCountOfRegionB),
        mergedRegionRowCount);
  } finally {
    HRegion.closeHRegion(mergedRegion);
  }
  // Assert the write lock is no longer held on region_a and region_b
  assertTrue(!this.region_a.lock.writeLock().isHeldByCurrentThread());
  assertTrue(!this.region_b.lock.writeLock().isHeldByCurrentThread());
}
项目:ditb    文件:TestRegionMergeTransaction.java   
@Test
public void testRollback() throws IOException, InterruptedException {
  final int rowCountOfRegionA = loadRegion(this.region_a, CF, true);
  final int rowCountOfRegionB = loadRegion(this.region_b, CF, true);
  assertTrue(rowCountOfRegionA > 0 && rowCountOfRegionB > 0);
  assertEquals(rowCountOfRegionA, countRows(this.region_a));
  assertEquals(rowCountOfRegionB, countRows(this.region_b));

  // Start transaction.
  RegionMergeTransactionImpl mt = prepareOnGoodRegions();

  when(mt.createMergedRegionFromMerges(region_a, region_b,
      mt.getMergedRegionInfo())).thenThrow(
      new MockedFailedMergedRegionCreation());

  // Run the execute. Look at what it returns.
  boolean expectedException = false;
  TEST_UTIL.getConfiguration().setInt(HConstants.REGIONSERVER_PORT, 0);
  CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(
    TEST_UTIL.getConfiguration());
  Server mockServer = new HRegionServer(TEST_UTIL.getConfiguration(), cp);
  try {
    mt.execute(mockServer, null);
  } catch (MockedFailedMergedRegionCreation e) {
    expectedException = true;
  }
  assertTrue(expectedException);
  // Run rollback
  assertTrue(mt.rollback(null, null));

  // Assert I can scan region_a and region_b.
  int rowCountOfRegionA2 = countRows(this.region_a);
  assertEquals(rowCountOfRegionA, rowCountOfRegionA2);
  int rowCountOfRegionB2 = countRows(this.region_b);
  assertEquals(rowCountOfRegionB, rowCountOfRegionB2);

  // Assert rollback cleaned up stuff in fs
  assertTrue(!this.fs.exists(HRegion.getRegionDir(this.testdir,
      mt.getMergedRegionInfo())));

  assertTrue(!this.region_a.lock.writeLock().isHeldByCurrentThread());
  assertTrue(!this.region_b.lock.writeLock().isHeldByCurrentThread());

  // Now retry the merge but do not throw an exception this time.
  assertTrue(mt.prepare(null));
  HRegion mergedRegion = (HRegion)mt.execute(mockServer, null);
  // Count rows. daughters are already open
  // Count rows. merged region are already open
  try {
    int mergedRegionRowCount = countRows(mergedRegion);
    assertEquals((rowCountOfRegionA + rowCountOfRegionB),
        mergedRegionRowCount);
  } finally {
    HRegion.closeHRegion(mergedRegion);
  }
  // Assert the write lock is no longer held on region_a and region_b
  assertTrue(!this.region_a.lock.writeLock().isHeldByCurrentThread());
  assertTrue(!this.region_b.lock.writeLock().isHeldByCurrentThread());
}
项目:pbase    文件:HMasterCommandLine.java   
private int startMaster() {
    Configuration conf = getConf();
    try {
        // If 'local', defer to LocalHBaseCluster instance.  Starts master
        // and regionserver both in the one JVM.
        if (LocalHBaseCluster.isLocal(conf)) {
            DefaultMetricsSystem.setMiniClusterMode(true);
            final MiniZooKeeperCluster zooKeeperCluster = new MiniZooKeeperCluster(conf);
            File zkDataPath = new File(conf.get(HConstants.ZOOKEEPER_DATA_DIR));
            int zkClientPort = conf.getInt(HConstants.ZOOKEEPER_CLIENT_PORT, 0);
            if (zkClientPort == 0) {
                throw new IOException("No config value for "
                        + HConstants.ZOOKEEPER_CLIENT_PORT);
            }
            zooKeeperCluster.setDefaultClientPort(zkClientPort);

            // login the zookeeper server principal (if using security)
            ZKUtil.loginServer(conf, "hbase.zookeeper.server.keytab.file",
                    "hbase.zookeeper.server.kerberos.principal", null);
            int localZKClusterSessionTimeout =
                    conf.getInt(HConstants.ZK_SESSION_TIMEOUT + ".localHBaseCluster", 10 * 1000);
            conf.setInt(HConstants.ZK_SESSION_TIMEOUT, localZKClusterSessionTimeout);
            LOG.info("Starting a zookeeper cluster");
            int clientPort = zooKeeperCluster.startup(zkDataPath);
            if (clientPort != zkClientPort) {
                String errorMsg = "Could not start ZK at requested port of " +
                        zkClientPort + ".  ZK was started at port: " + clientPort +
                        ".  Aborting as clients (e.g. shell) will not be able to find " +
                        "this ZK quorum.";
                System.err.println(errorMsg);
                throw new IOException(errorMsg);
            }
            conf.set(HConstants.ZOOKEEPER_CLIENT_PORT, Integer.toString(clientPort));
            // Need to have the zk cluster shutdown when master is shutdown.
            // Run a subclass that does the zk cluster shutdown on its way out.
            int mastersCount = conf.getInt("hbase.masters", 1);
            int regionServersCount = conf.getInt("hbase.regionservers", 1);
            LOG.info("Starting up instance of localHBaseCluster; master=" + mastersCount +
                    ", regionserversCount=" + regionServersCount);
            LocalHBaseCluster cluster = new LocalHBaseCluster(conf, mastersCount, regionServersCount,
                    LocalHMaster.class, HRegionServer.class);
            ((LocalHMaster) cluster.getMaster(0)).setZKCluster(zooKeeperCluster);
            cluster.startup();
            waitOnMasterThreads(cluster);
        } else {
            logProcessInfo(getConf());//将系统的运行配置参数以及JVM的状态存到日志中
            CoordinatedStateManager csm =
                    CoordinatedStateManagerFactory.getCoordinatedStateManager(conf);
            HMaster master = HMaster.constructMaster(masterClass, conf, csm);
            if (master.isStopped()) {
                LOG.info("Won't bring the Master up as a shutdown is requested");
                return 1;
            }
            master.start();
            master.join();
            if (master.isAborted())
                throw new RuntimeException("HMaster Aborted");
        }
    } catch (Throwable t) {
        LOG.error("Master exiting", t);
        return 1;
    }
    return 0;
}
项目:pbase    文件:TestMasterNoCluster.java   
@Test
public void testNotPullingDeadRegionServerFromZK()
    throws IOException, KeeperException, InterruptedException {
  final Configuration conf = TESTUTIL.getConfiguration();
  final ServerName newServer = ServerName.valueOf("test.sample", 1, 101);
  final ServerName deadServer = ServerName.valueOf("test.sample", 1, 100);
  final MockRegionServer rs0 = new MockRegionServer(conf, newServer);

  CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(
    TESTUTIL.getConfiguration());
  HMaster master = new HMaster(conf, cp) {
    @Override
    void assignMeta(MonitoredTask status, Set<ServerName> previouslyFailedMeatRSs) {
    }

    @Override
    void initializeZKBasedSystemTrackers() throws IOException,
    InterruptedException, KeeperException, CoordinatedStateException {
      super.initializeZKBasedSystemTrackers();
      // Record a newer server in server manager at first
      serverManager.recordNewServerWithLock(newServer, ServerLoad.EMPTY_SERVERLOAD);

      List<ServerName> onlineServers = new ArrayList<ServerName>();
      onlineServers.add(deadServer);
      onlineServers.add(newServer);
      // Mock the region server tracker to pull the dead server from zk
      regionServerTracker = Mockito.spy(regionServerTracker);
      Mockito.doReturn(onlineServers).when(
        regionServerTracker).getOnlineServers();
    }

    @Override
    public ClusterConnection getConnection() {
      // Insert a mock for the connection, use TESTUTIL.getConfiguration rather than
      // the conf from the master; the conf will already have an HConnection
      // associate so the below mocking of a connection will fail.
      try {
        return HConnectionTestingUtility.getMockedConnectionAndDecorate(
          TESTUTIL.getConfiguration(), rs0, rs0, rs0.getServerName(),
          HRegionInfo.FIRST_META_REGIONINFO);
      } catch (IOException e) {
        return null;
      }
    }

    @Override
    void initNamespace() {
    }
  };
  master.start();

  try {
    // Wait till master is initialized.
    while (!master.initialized) Threads.sleep(10);
    LOG.info("Master is initialized");

    assertFalse("The dead server should not be pulled in",
      master.serverManager.isServerOnline(deadServer));
  } finally {
    master.stopMaster();
    master.join();
  }
}
项目:pbase    文件:TestSplitLogManager.java   
public DummyServer(ZooKeeperWatcher zkw, Configuration conf) {
  this.zkw = zkw;
  this.conf = conf;
  cm = CoordinatedStateManagerFactory.getCoordinatedStateManager(conf);
  cm.initialize(this);
}
项目:pbase    文件:TestAssignmentManager.java   
/**
 * Test verifies whether all the enabling table regions assigned only once during master startup.
 *
 * @throws KeeperException
 * @throws IOException
 * @throws Exception
 */
@Test (timeout=180000)
public void testMasterRestartWhenTableInEnabling() throws KeeperException, IOException, Exception {
  enabling = true;
  List<ServerName> destServers = new ArrayList<ServerName>(1);
  destServers.add(SERVERNAME_A);
  Mockito.when(this.serverManager.createDestinationServersList()).thenReturn(destServers);
  Mockito.when(this.serverManager.isServerOnline(SERVERNAME_A)).thenReturn(true);
  HTU.getConfiguration().setInt(HConstants.MASTER_PORT, 0);
  CoordinatedStateManager csm = CoordinatedStateManagerFactory.getCoordinatedStateManager(
    HTU.getConfiguration());
  Server server = new HMaster(HTU.getConfiguration(), csm);
  Whitebox.setInternalState(server, "serverManager", this.serverManager);
  AssignmentManagerWithExtrasForTesting am = setUpMockedAssignmentManager(server,
      this.serverManager);

  Whitebox.setInternalState(server, "metaTableLocator", Mockito.mock(MetaTableLocator.class));

  // Make it so we can get a catalogtracker from servermanager.. .needed
  // down in guts of server shutdown handler.
  Whitebox.setInternalState(server, "clusterConnection", am.getConnection());

  try {
    // set table in enabling state.
    am.getTableStateManager().setTableState(REGIONINFO.getTable(),
      Table.State.ENABLING);
    new EnableTableHandler(server, REGIONINFO.getTable(),
        am, new NullTableLockManager(), true).prepare()
        .process();
    assertEquals("Number of assignments should be 1.", 1, assignmentCount);
    assertTrue("Table should be enabled.",
        am.getTableStateManager().isTableState(REGIONINFO.getTable(),
          Table.State.ENABLED));
  } finally {
    enabling = false;
    assignmentCount = 0;
    am.getTableStateManager().setTableState(REGIONINFO.getTable(),
      Table.State.ENABLED);
    am.shutdown();
    ZKAssign.deleteAllNodes(this.watcher);
  }
}
项目:pbase    文件:TestHMasterRPCException.java   
@Test
public void testRPCException() throws Exception {
  HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
  TEST_UTIL.startMiniZKCluster();
  Configuration conf = TEST_UTIL.getConfiguration();
  conf.set(HConstants.MASTER_PORT, "0");
  CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(conf);
  HMaster hm = new HMaster(conf, cp);
  ServerName sm = hm.getServerName();
  RpcClient rpcClient = RpcClientFactory.createClient(conf, HConstants.CLUSTER_ID_DEFAULT);
  try {
    int i = 0;
    //retry the RPC a few times; we have seen SocketTimeoutExceptions if we
    //try to connect too soon. Retry on SocketTimeoutException.
    while (i < 20) {
      try {
        BlockingRpcChannel channel =
          rpcClient.createBlockingRpcChannel(sm, User.getCurrent(), 0);
        MasterProtos.MasterService.BlockingInterface stub =
          MasterProtos.MasterService.newBlockingStub(channel);
        stub.isMasterRunning(null, IsMasterRunningRequest.getDefaultInstance());
        fail();
      } catch (ServiceException ex) {
        IOException ie = ProtobufUtil.getRemoteException(ex);
        if (!(ie instanceof SocketTimeoutException)) {
          if (ie.getMessage().startsWith("org.apache.hadoop.hbase.ipc." +
              "ServerNotRunningYetException: Server is not running yet")) {
            // Done.  Got the exception we wanted.
            System.out.println("Expected exception: " + ie.getMessage());
            return;
          } else {
            throw ex;
          }
        } else {
          System.err.println("Got SocketTimeoutException. Will retry. ");
        }
      } catch (Throwable t) {
        fail("Unexpected throwable: " + t);
      }
      Thread.sleep(100);
      i++;
    }
    fail();
  } finally {
    rpcClient.close();
  }
}
项目:pbase    文件:TestSplitLogWorker.java   
public DummyServer(ZooKeeperWatcher zkw, Configuration conf) {
  this.zkw = zkw;
  this.conf = conf;
  cm = CoordinatedStateManagerFactory.getCoordinatedStateManager(conf);
  cm.initialize(this);
}
项目:pbase    文件:TestRegionMergeTransaction.java   
@Test
public void testWholesomeMerge() throws IOException, InterruptedException {
  final int rowCountOfRegionA = loadRegion(this.region_a, CF, true);
  final int rowCountOfRegionB = loadRegion(this.region_b, CF, true);
  assertTrue(rowCountOfRegionA > 0 && rowCountOfRegionB > 0);
  assertEquals(rowCountOfRegionA, countRows(this.region_a));
  assertEquals(rowCountOfRegionB, countRows(this.region_b));

  // Start transaction.
  RegionMergeTransaction mt = prepareOnGoodRegions();

  // Run the execute. Look at what it returns.
  TEST_UTIL.getConfiguration().setInt(HConstants.REGIONSERVER_PORT, 0);
  CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(
    TEST_UTIL.getConfiguration());
  Server mockServer = new HRegionServer(TEST_UTIL.getConfiguration(), cp);
  HRegion mergedRegion = mt.execute(mockServer, null);
  // Do some assertions about execution.
  assertTrue(this.fs.exists(mt.getMergesDir()));
  // Assert region_a and region_b is closed.
  assertTrue(region_a.isClosed());
  assertTrue(region_b.isClosed());

  // Assert mergedir is empty -- because its content will have been moved out
  // to be under the merged region dirs.
  assertEquals(0, this.fs.listStatus(mt.getMergesDir()).length);
  // Check merged region have correct key span.
  assertTrue(Bytes.equals(this.region_a.getStartKey(),
      mergedRegion.getStartKey()));
  assertTrue(Bytes.equals(this.region_b.getEndKey(),
      mergedRegion.getEndKey()));
  // Count rows. merged region are already open
  try {
    int mergedRegionRowCount = countRows(mergedRegion);
    assertEquals((rowCountOfRegionA + rowCountOfRegionB),
        mergedRegionRowCount);
  } finally {
    HRegion.closeHRegion(mergedRegion);
  }
  // Assert the write lock is no longer held on region_a and region_b
  assertTrue(!this.region_a.lock.writeLock().isHeldByCurrentThread());
  assertTrue(!this.region_b.lock.writeLock().isHeldByCurrentThread());
}
项目:pbase    文件:TestRegionMergeTransaction.java   
@Test
public void testRollback() throws IOException, InterruptedException {
  final int rowCountOfRegionA = loadRegion(this.region_a, CF, true);
  final int rowCountOfRegionB = loadRegion(this.region_b, CF, true);
  assertTrue(rowCountOfRegionA > 0 && rowCountOfRegionB > 0);
  assertEquals(rowCountOfRegionA, countRows(this.region_a));
  assertEquals(rowCountOfRegionB, countRows(this.region_b));

  // Start transaction.
  RegionMergeTransaction mt = prepareOnGoodRegions();

  when(mt.createMergedRegionFromMerges(region_a, region_b,
      mt.getMergedRegionInfo())).thenThrow(
      new MockedFailedMergedRegionCreation());

  // Run the execute. Look at what it returns.
  boolean expectedException = false;
  TEST_UTIL.getConfiguration().setInt(HConstants.REGIONSERVER_PORT, 0);
  CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(
    TEST_UTIL.getConfiguration());
  Server mockServer = new HRegionServer(TEST_UTIL.getConfiguration(), cp);
  try {
    mt.execute(mockServer, null);
  } catch (MockedFailedMergedRegionCreation e) {
    expectedException = true;
  }
  assertTrue(expectedException);
  // Run rollback
  assertTrue(mt.rollback(null, null));

  // Assert I can scan region_a and region_b.
  int rowCountOfRegionA2 = countRows(this.region_a);
  assertEquals(rowCountOfRegionA, rowCountOfRegionA2);
  int rowCountOfRegionB2 = countRows(this.region_b);
  assertEquals(rowCountOfRegionB, rowCountOfRegionB2);

  // Assert rollback cleaned up stuff in fs
  assertTrue(!this.fs.exists(HRegion.getRegionDir(this.testdir,
      mt.getMergedRegionInfo())));

  assertTrue(!this.region_a.lock.writeLock().isHeldByCurrentThread());
  assertTrue(!this.region_b.lock.writeLock().isHeldByCurrentThread());

  // Now retry the merge but do not throw an exception this time.
  assertTrue(mt.prepare(null));
  HRegion mergedRegion = mt.execute(mockServer, null);
  // Count rows. daughters are already open
  // Count rows. merged region are already open
  try {
    int mergedRegionRowCount = countRows(mergedRegion);
    assertEquals((rowCountOfRegionA + rowCountOfRegionB),
        mergedRegionRowCount);
  } finally {
    HRegion.closeHRegion(mergedRegion);
  }
  // Assert the write lock is no longer held on region_a and region_b
  assertTrue(!this.region_a.lock.writeLock().isHeldByCurrentThread());
  assertTrue(!this.region_b.lock.writeLock().isHeldByCurrentThread());
}
项目:PyroDB    文件:HMasterCommandLine.java   
private int startMaster() {
  Configuration conf = getConf();
  try {
    // If 'local', defer to LocalHBaseCluster instance.  Starts master
    // and regionserver both in the one JVM.
    if (LocalHBaseCluster.isLocal(conf)) {
      DefaultMetricsSystem.setMiniClusterMode(true);
      conf.setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, 1);
      final MiniZooKeeperCluster zooKeeperCluster = new MiniZooKeeperCluster(conf);
      File zkDataPath = new File(conf.get(HConstants.ZOOKEEPER_DATA_DIR));
      int zkClientPort = conf.getInt(HConstants.ZOOKEEPER_CLIENT_PORT, 0);
      if (zkClientPort == 0) {
        throw new IOException("No config value for "
            + HConstants.ZOOKEEPER_CLIENT_PORT);
      }
      zooKeeperCluster.setDefaultClientPort(zkClientPort);

      // login the zookeeper server principal (if using security)
      ZKUtil.loginServer(conf, "hbase.zookeeper.server.keytab.file",
        "hbase.zookeeper.server.kerberos.principal", null);

      int clientPort = zooKeeperCluster.startup(zkDataPath);
      if (clientPort != zkClientPort) {
        String errorMsg = "Could not start ZK at requested port of " +
          zkClientPort + ".  ZK was started at port: " + clientPort +
          ".  Aborting as clients (e.g. shell) will not be able to find " +
          "this ZK quorum.";
        System.err.println(errorMsg);
        throw new IOException(errorMsg);
      }
      conf.set(HConstants.ZOOKEEPER_CLIENT_PORT,
               Integer.toString(clientPort));
      // Need to have the zk cluster shutdown when master is shutdown.
      // Run a subclass that does the zk cluster shutdown on its way out.
      LocalHBaseCluster cluster = new LocalHBaseCluster(conf, conf.getInt("hbase.masters", 1),
        conf.getInt("hbase.regionservers", 0), LocalHMaster.class, HRegionServer.class);
      ((LocalHMaster)cluster.getMaster(0)).setZKCluster(zooKeeperCluster);
      cluster.startup();
      waitOnMasterThreads(cluster);
    } else {
      logProcessInfo(getConf());
      CoordinatedStateManager csm =
        CoordinatedStateManagerFactory.getCoordinatedStateManager(conf);
      HMaster master = HMaster.constructMaster(masterClass, conf, csm);
      if (master.isStopped()) {
        LOG.info("Won't bring the Master up as a shutdown is requested");
        return 1;
      }
      master.start();
      master.join();
      if(master.isAborted())
        throw new RuntimeException("HMaster Aborted");
    }
  } catch (Throwable t) {
    LOG.error("Master exiting", t);
    return 1;
  }
  return 0;
}
项目:PyroDB    文件:TestMasterNoCluster.java   
@Test
public void testNotPullingDeadRegionServerFromZK()
    throws IOException, KeeperException, InterruptedException {
  final Configuration conf = TESTUTIL.getConfiguration();
  final ServerName newServer = ServerName.valueOf("test.sample", 1, 101);
  final ServerName deadServer = ServerName.valueOf("test.sample", 1, 100);
  final MockRegionServer rs0 = new MockRegionServer(conf, newServer);

  CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(
    TESTUTIL.getConfiguration());
  HMaster master = new HMaster(conf, cp) {
    @Override
    void assignMeta(MonitoredTask status, Set<ServerName> previouslyFailedMeatRSs) {
    }

    @Override
    void initializeZKBasedSystemTrackers() throws IOException,
    InterruptedException, KeeperException, CoordinatedStateException {
      super.initializeZKBasedSystemTrackers();
      // Record a newer server in server manager at first
      serverManager.recordNewServerWithLock(newServer, ServerLoad.EMPTY_SERVERLOAD);

      List<ServerName> onlineServers = new ArrayList<ServerName>();
      onlineServers.add(deadServer);
      onlineServers.add(newServer);
      // Mock the region server tracker to pull the dead server from zk
      regionServerTracker = Mockito.spy(regionServerTracker);
      Mockito.doReturn(onlineServers).when(
        regionServerTracker).getOnlineServers();
    }

    @Override
    protected CatalogTracker createCatalogTracker() throws IOException {
      // Insert a mock for the connection used by the CatalogTracker.  Any
      // regionserver should do.  Use TESTUTIL.getConfiguration rather than
      // the conf from the master; the conf will already have an HConnection
      // associate so the below mocking of a connection will fail.
      HConnection connection =
        HConnectionTestingUtility.getMockedConnectionAndDecorate(TESTUTIL.getConfiguration(),
          rs0, rs0, rs0.getServerName(), HRegionInfo.FIRST_META_REGIONINFO);
      return new CatalogTracker(getZooKeeper(), getConfiguration(), connection, this);
    }

    @Override
    void initNamespace() {
    }
  };
  master.start();

  try {
    // Wait till master is initialized.
    while (!master.initialized) Threads.sleep(10);
    LOG.info("Master is initialized");

    assertFalse("The dead server should not be pulled in",
      master.serverManager.isServerOnline(deadServer));
  } finally {
    master.stopMaster();
    master.join();
  }
}
项目:PyroDB    文件:TestHMasterRPCException.java   
@Test
public void testRPCException() throws Exception {
  HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
  TEST_UTIL.startMiniZKCluster();
  Configuration conf = TEST_UTIL.getConfiguration();
  conf.set(HConstants.MASTER_PORT, "0");
  CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(conf);
  HMaster hm = new HMaster(conf, cp);
  ServerName sm = hm.getServerName();
  RpcClient rpcClient = new RpcClient(conf, HConstants.CLUSTER_ID_DEFAULT);
  try {
    int i = 0;
    //retry the RPC a few times; we have seen SocketTimeoutExceptions if we
    //try to connect too soon. Retry on SocketTimeoutException.
    while (i < 20) {
      try {
        BlockingRpcChannel channel =
          rpcClient.createBlockingRpcChannel(sm, User.getCurrent(), 0);
        MasterProtos.MasterService.BlockingInterface stub =
          MasterProtos.MasterService.newBlockingStub(channel);
        stub.isMasterRunning(null, IsMasterRunningRequest.getDefaultInstance());
        fail();
      } catch (ServiceException ex) {
        IOException ie = ProtobufUtil.getRemoteException(ex);
        if (!(ie instanceof SocketTimeoutException)) {
          if (ie.getMessage().startsWith("org.apache.hadoop.hbase.ipc." +
              "ServerNotRunningYetException: Server is not running yet")) {
            // Done.  Got the exception we wanted.
            System.out.println("Expected exception: " + ie.getMessage());
            return;
          } else {
            throw ex;
          }
        } else {
          System.err.println("Got SocketTimeoutException. Will retry. ");
        }
      } catch (Throwable t) {
        fail("Unexpected throwable: " + t);
      }
      Thread.sleep(100);
      i++;
    }
    fail();
  } finally {
    rpcClient.stop();
  }
}
项目:PyroDB    文件:TestRegionMergeTransaction.java   
@Test
public void testWholesomeMerge() throws IOException, InterruptedException {
  final int rowCountOfRegionA = loadRegion(this.region_a, CF, true);
  final int rowCountOfRegionB = loadRegion(this.region_b, CF, true);
  assertTrue(rowCountOfRegionA > 0 && rowCountOfRegionB > 0);
  assertEquals(rowCountOfRegionA, countRows(this.region_a));
  assertEquals(rowCountOfRegionB, countRows(this.region_b));

  // Start transaction.
  RegionMergeTransaction mt = prepareOnGoodRegions();

  // Run the execute. Look at what it returns.
  TEST_UTIL.getConfiguration().setInt(HConstants.REGIONSERVER_PORT, 0);
  CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(
    TEST_UTIL.getConfiguration());
  Server mockServer = new HRegionServer(TEST_UTIL.getConfiguration(), cp);
  HRegion mergedRegion = mt.execute(mockServer, null);
  // Do some assertions about execution.
  assertTrue(this.fs.exists(mt.getMergesDir()));
  // Assert region_a and region_b is closed.
  assertTrue(region_a.isClosed());
  assertTrue(region_b.isClosed());

  // Assert mergedir is empty -- because its content will have been moved out
  // to be under the merged region dirs.
  assertEquals(0, this.fs.listStatus(mt.getMergesDir()).length);
  // Check merged region have correct key span.
  assertTrue(Bytes.equals(this.region_a.getStartKey(),
      mergedRegion.getStartKey()));
  assertTrue(Bytes.equals(this.region_b.getEndKey(),
      mergedRegion.getEndKey()));
  // Count rows. merged region are already open
  try {
    int mergedRegionRowCount = countRows(mergedRegion);
    assertEquals((rowCountOfRegionA + rowCountOfRegionB),
        mergedRegionRowCount);
  } finally {
    HRegion.closeHRegion(mergedRegion);
  }
  // Assert the write lock is no longer held on region_a and region_b
  assertTrue(!this.region_a.lock.writeLock().isHeldByCurrentThread());
  assertTrue(!this.region_b.lock.writeLock().isHeldByCurrentThread());
}
项目:PyroDB    文件:TestRegionMergeTransaction.java   
@Test
public void testRollback() throws IOException, InterruptedException {
  final int rowCountOfRegionA = loadRegion(this.region_a, CF, true);
  final int rowCountOfRegionB = loadRegion(this.region_b, CF, true);
  assertTrue(rowCountOfRegionA > 0 && rowCountOfRegionB > 0);
  assertEquals(rowCountOfRegionA, countRows(this.region_a));
  assertEquals(rowCountOfRegionB, countRows(this.region_b));

  // Start transaction.
  RegionMergeTransaction mt = prepareOnGoodRegions();

  when(mt.createMergedRegionFromMerges(region_a, region_b,
      mt.getMergedRegionInfo())).thenThrow(
      new MockedFailedMergedRegionCreation());

  // Run the execute. Look at what it returns.
  boolean expectedException = false;
  TEST_UTIL.getConfiguration().setInt(HConstants.REGIONSERVER_PORT, 0);
  CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(
    TEST_UTIL.getConfiguration());
  Server mockServer = new HRegionServer(TEST_UTIL.getConfiguration(), cp);
  try {
    mt.execute(mockServer, null);
  } catch (MockedFailedMergedRegionCreation e) {
    expectedException = true;
  }
  assertTrue(expectedException);
  // Run rollback
  assertTrue(mt.rollback(null, null));

  // Assert I can scan region_a and region_b.
  int rowCountOfRegionA2 = countRows(this.region_a);
  assertEquals(rowCountOfRegionA, rowCountOfRegionA2);
  int rowCountOfRegionB2 = countRows(this.region_b);
  assertEquals(rowCountOfRegionB, rowCountOfRegionB2);

  // Assert rollback cleaned up stuff in fs
  assertTrue(!this.fs.exists(HRegion.getRegionDir(this.testdir,
      mt.getMergedRegionInfo())));

  assertTrue(!this.region_a.lock.writeLock().isHeldByCurrentThread());
  assertTrue(!this.region_b.lock.writeLock().isHeldByCurrentThread());

  // Now retry the merge but do not throw an exception this time.
  assertTrue(mt.prepare(null));
  HRegion mergedRegion = mt.execute(mockServer, null);
  // Count rows. daughters are already open
  // Count rows. merged region are already open
  try {
    int mergedRegionRowCount = countRows(mergedRegion);
    assertEquals((rowCountOfRegionA + rowCountOfRegionB),
        mergedRegionRowCount);
  } finally {
    HRegion.closeHRegion(mergedRegion);
  }
  // Assert the write lock is no longer held on region_a and region_b
  assertTrue(!this.region_a.lock.writeLock().isHeldByCurrentThread());
  assertTrue(!this.region_b.lock.writeLock().isHeldByCurrentThread());
}
项目:ditb    文件:HRegionServer.java   
/**
 * Starts a HRegionServer at the default location.
 *
 * @param conf
 * @throws IOException
 * @throws InterruptedException
 */
public HRegionServer(Configuration conf) throws IOException, InterruptedException {
  this(conf, CoordinatedStateManagerFactory.getCoordinatedStateManager(conf));
}
项目:pbase    文件:HRegionServer.java   
/**
 * Starts a HRegionServer at the default location.
 *
 * @param conf
 * @throws IOException
 * @throws InterruptedException
 */
public HRegionServer(Configuration conf) throws IOException, InterruptedException {
    this(conf, CoordinatedStateManagerFactory.getCoordinatedStateManager(conf));
}