当前位置: 首页>>代码示例>>Java>>正文


Java ZkCoordinatedStateManager类代码示例

本文整理汇总了Java中org.apache.hadoop.hbase.coordination.ZkCoordinatedStateManager的典型用法代码示例。如果您正苦于以下问题:Java ZkCoordinatedStateManager类的具体用法?Java ZkCoordinatedStateManager怎么用?Java ZkCoordinatedStateManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ZkCoordinatedStateManager类属于org.apache.hadoop.hbase.coordination包,在下文中一共展示了ZkCoordinatedStateManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initialize

import org.apache.hadoop.hbase.coordination.ZkCoordinatedStateManager; //导入依赖的package包/类
@Override
public void initialize(MasterServices master, MetricsMaster metricsMaster)
    throws IOException, UnsupportedOperationException {
  this.master = master;
  this.done = false;

  // setup the default procedure coordinator
  String name = master.getServerName().toString();


  // get the configuration for the coordinator
  Configuration conf = master.getConfiguration();
  long wakeFrequency = conf.getInt(BACKUP_WAKE_MILLIS_KEY, BACKUP_WAKE_MILLIS_DEFAULT);
  long timeoutMillis = conf.getLong(BACKUP_TIMEOUT_MILLIS_KEY,BACKUP_TIMEOUT_MILLIS_DEFAULT);
  int opThreads = conf.getInt(BACKUP_POOL_THREAD_NUMBER_KEY,
                                  BACKUP_POOL_THREAD_NUMBER_DEFAULT);

  // setup the default procedure coordinator
  ThreadPoolExecutor tpool = ProcedureCoordinator.defaultPool(name, opThreads);
  CoordinatedStateManager coordManager = new ZkCoordinatedStateManager(master);
  ProcedureCoordinatorRpcs comms =
      coordManager.getProcedureCoordinatorRpcs(getProcedureSignature(), name);
  this.coordinator = new ProcedureCoordinator(comms, tpool, timeoutMillis, wakeFrequency);

}
 
开发者ID:apache,项目名称:hbase,代码行数:26,代码来源:LogRollMasterProcedureManager.java

示例2: initialize

import org.apache.hadoop.hbase.coordination.ZkCoordinatedStateManager; //导入依赖的package包/类
@Override
public void initialize(RegionServerServices rss) throws KeeperException {
  this.rss = rss;
  if (!BackupManager.isBackupEnabled(rss.getConfiguration())) {
    LOG.warn("Backup is not enabled. Check your " + BackupRestoreConstants.BACKUP_ENABLE_KEY
        + " setting");
    return;
  }
  CoordinatedStateManager coordManager = new ZkCoordinatedStateManager(rss);
  this.memberRpcs = coordManager
          .getProcedureMemberRpcs(LogRollMasterProcedureManager.ROLLLOG_PROCEDURE_SIGNATURE);

  // read in the backup handler configuration properties
  Configuration conf = rss.getConfiguration();
  long keepAlive = conf.getLong(BACKUP_TIMEOUT_MILLIS_KEY, BACKUP_TIMEOUT_MILLIS_DEFAULT);
  int opThreads = conf.getInt(BACKUP_REQUEST_THREADS_KEY, BACKUP_REQUEST_THREADS_DEFAULT);
  // create the actual cohort member
  ThreadPoolExecutor pool =
      ProcedureMember.defaultPool(rss.getServerName().toString(), opThreads, keepAlive);
  this.member = new ProcedureMember(memberRpcs, pool, new BackupSubprocedureBuilder());
}
 
开发者ID:apache,项目名称:hbase,代码行数:22,代码来源:LogRollRegionServerProcedureManager.java

示例3: getCoordinatedStateManager

import org.apache.hadoop.hbase.coordination.ZkCoordinatedStateManager; //导入依赖的package包/类
/**
 * Creates consensus provider from the given configuration.
 * @param conf Configuration
 * @return Implementation of  {@link CoordinatedStateManager}
 */
public static CoordinatedStateManager getCoordinatedStateManager(Configuration conf) {
  Class<? extends CoordinatedStateManager> coordinatedStateMgrKlass =
    conf.getClass(HConstants.HBASE_COORDINATED_STATE_MANAGER_CLASS,
      ZkCoordinatedStateManager.class, CoordinatedStateManager.class);
  return ReflectionUtils.newInstance(coordinatedStateMgrKlass, conf);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:12,代码来源:CoordinatedStateManagerFactory.java

示例4: testZKClosingNodeVersionMismatch

import org.apache.hadoop.hbase.coordination.ZkCoordinatedStateManager; //导入依赖的package包/类
/**
 * Test if close region can handle ZK closing node version mismatch
 * @throws IOException
 * @throws NodeExistsException
 * @throws KeeperException
* @throws DeserializationException
 */
@Test public void testZKClosingNodeVersionMismatch()
throws IOException, NodeExistsException, KeeperException, DeserializationException {
  final Server server = new MockServer(HTU);
  final RegionServerServices rss = HTU.createMockRegionServerService();

  HTableDescriptor htd = TEST_HTD;
  final HRegionInfo hri = TEST_HRI;

  ZkCoordinatedStateManager coordinationProvider = new ZkCoordinatedStateManager();
  coordinationProvider.initialize(server);
  coordinationProvider.start();

  // open a region first so that it can be closed later
  OpenRegion(server, rss, htd, hri, coordinationProvider.getOpenRegionCoordination());

  // close the region
  // Create it CLOSING, which is what Master set before sending CLOSE RPC
  int versionOfClosingNode = ZKAssign.createNodeClosing(server.getZooKeeper(),
    hri, server.getServerName());

  // The CloseRegionHandler will validate the expected version
  // Given it is set to invalid versionOfClosingNode+1,
  // CloseRegionHandler should be M_ZK_REGION_CLOSING

  ZkCloseRegionCoordination.ZkCloseRegionDetails zkCrd =
    new ZkCloseRegionCoordination.ZkCloseRegionDetails();
  zkCrd.setPublishStatusInZk(true);
  zkCrd.setExpectedVersion(versionOfClosingNode+1);

  CloseRegionHandler handler = new CloseRegionHandler(server, rss, hri, false,
    coordinationProvider.getCloseRegionCoordination(), zkCrd);
  handler.process();

  // Handler should remain in M_ZK_REGION_CLOSING
  RegionTransition rt =
    RegionTransition.parseFrom(ZKAssign.getData(server.getZooKeeper(), hri.getEncodedName()));
  assertTrue(rt.getEventType().equals(EventType.M_ZK_REGION_CLOSING ));
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:46,代码来源:TestCloseRegionHandler.java

示例5: testCloseRegion

import org.apache.hadoop.hbase.coordination.ZkCoordinatedStateManager; //导入依赖的package包/类
/**
 * Test if the region can be closed properly
 * @throws IOException
 * @throws NodeExistsException
 * @throws KeeperException
* @throws org.apache.hadoop.hbase.exceptions.DeserializationException
 */
@Test public void testCloseRegion()
throws IOException, NodeExistsException, KeeperException, DeserializationException {
  final Server server = new MockServer(HTU);
  final RegionServerServices rss = HTU.createMockRegionServerService();

  HTableDescriptor htd = TEST_HTD;
  HRegionInfo hri = TEST_HRI;

  ZkCoordinatedStateManager coordinationProvider = new ZkCoordinatedStateManager();
  coordinationProvider.initialize(server);
  coordinationProvider.start();

  // open a region first so that it can be closed later
  OpenRegion(server, rss, htd, hri, coordinationProvider.getOpenRegionCoordination());

  // close the region
  // Create it CLOSING, which is what Master set before sending CLOSE RPC
  int versionOfClosingNode = ZKAssign.createNodeClosing(server.getZooKeeper(),
    hri, server.getServerName());

  // The CloseRegionHandler will validate the expected version
  // Given it is set to correct versionOfClosingNode,
  // CloseRegionHandlerit should be RS_ZK_REGION_CLOSED

  ZkCloseRegionCoordination.ZkCloseRegionDetails zkCrd =
    new ZkCloseRegionCoordination.ZkCloseRegionDetails();
  zkCrd.setPublishStatusInZk(true);
  zkCrd.setExpectedVersion(versionOfClosingNode);

  CloseRegionHandler handler = new CloseRegionHandler(server, rss, hri, false,
    coordinationProvider.getCloseRegionCoordination(), zkCrd);
  handler.process();
  // Handler should have transitioned it to RS_ZK_REGION_CLOSED
  RegionTransition rt = RegionTransition.parseFrom(
    ZKAssign.getData(server.getZooKeeper(), hri.getEncodedName()));
  assertTrue(rt.getEventType().equals(EventType.RS_ZK_REGION_CLOSED));
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:45,代码来源:TestCloseRegionHandler.java

示例6: testFailedOpenRegion

import org.apache.hadoop.hbase.coordination.ZkCoordinatedStateManager; //导入依赖的package包/类
@Test
public void testFailedOpenRegion() throws Exception {
  Server server = new MockServer(HTU);
  RegionServerServices rsServices = HTU.createMockRegionServerService();

  // Create it OFFLINE, which is what it expects
  ZKAssign.createNodeOffline(server.getZooKeeper(), TEST_HRI, server.getServerName());

  ZkCoordinatedStateManager csm = new ZkCoordinatedStateManager();
  csm.initialize(server);
  csm.start();

  ZkOpenRegionCoordination.ZkOpenRegionDetails zkCrd =
    new ZkOpenRegionCoordination.ZkOpenRegionDetails();
  zkCrd.setServerName(server.getServerName());

  // Create the handler
  OpenRegionHandler handler =
    new OpenRegionHandler(server, rsServices, TEST_HRI, TEST_HTD, -1,
      csm.getOpenRegionCoordination(), zkCrd) {
      @Override
      HRegion openRegion() {
        // Fake failure of opening a region due to an IOE, which is caught
        return null;
      }
  };
  rsServices.getRegionsInTransitionInRS().put(
    TEST_HRI.getEncodedNameAsBytes(), Boolean.TRUE);
  handler.process();

  // Handler should have transitioned it to FAILED_OPEN
  RegionTransition rt = RegionTransition.parseFrom(
    ZKAssign.getData(server.getZooKeeper(), TEST_HRI.getEncodedName()));
  assertEquals(EventType.RS_ZK_REGION_FAILED_OPEN, rt.getEventType());
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:36,代码来源:TestOpenRegionHandler.java

示例7: testFailedUpdateMeta

import org.apache.hadoop.hbase.coordination.ZkCoordinatedStateManager; //导入依赖的package包/类
@Test
public void testFailedUpdateMeta() throws Exception {
  Server server = new MockServer(HTU);
  RegionServerServices rsServices = HTU.createMockRegionServerService();

  // Create it OFFLINE, which is what it expects
  ZKAssign.createNodeOffline(server.getZooKeeper(), TEST_HRI, server.getServerName());

  // Create the handler
  ZkCoordinatedStateManager csm = new ZkCoordinatedStateManager();
  csm.initialize(server);
  csm.start();

  ZkOpenRegionCoordination.ZkOpenRegionDetails zkCrd =
    new ZkOpenRegionCoordination.ZkOpenRegionDetails();
  zkCrd.setServerName(server.getServerName());

  OpenRegionHandler handler = new OpenRegionHandler(server, rsServices, TEST_HRI, TEST_HTD,
    -1, csm.getOpenRegionCoordination(), zkCrd) {
      @Override
      boolean updateMeta(final HRegion r, long masterSystemTime) {
        // Fake failure of updating META
        return false;
      }
  };
  rsServices.getRegionsInTransitionInRS().put(
    TEST_HRI.getEncodedNameAsBytes(), Boolean.TRUE);
  handler.process();

  // Handler should have transitioned it to FAILED_OPEN
  RegionTransition rt = RegionTransition.parseFrom(
    ZKAssign.getData(server.getZooKeeper(), TEST_HRI.getEncodedName()));
  assertEquals(EventType.RS_ZK_REGION_FAILED_OPEN, rt.getEventType());
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:35,代码来源:TestOpenRegionHandler.java

示例8: testTransitionToFailedOpenEvenIfCleanupFails

import org.apache.hadoop.hbase.coordination.ZkCoordinatedStateManager; //导入依赖的package包/类
@Test
public void testTransitionToFailedOpenEvenIfCleanupFails() throws Exception {
  Server server = new MockServer(HTU);
  RegionServerServices rsServices = HTU.createMockRegionServerService();
  // Create it OFFLINE, which is what it expects
  ZKAssign.createNodeOffline(server.getZooKeeper(), TEST_HRI, server.getServerName());
  // Create the handler
  ZkCoordinatedStateManager csm = new ZkCoordinatedStateManager();
  csm.initialize(server);
  csm.start();

  ZkOpenRegionCoordination.ZkOpenRegionDetails zkCrd =
    new ZkOpenRegionCoordination.ZkOpenRegionDetails();
  zkCrd.setServerName(server.getServerName());

  OpenRegionHandler handler = new OpenRegionHandler(server, rsServices, TEST_HRI, TEST_HTD,
    -1, csm.getOpenRegionCoordination(), zkCrd) {
    @Override
    boolean updateMeta(HRegion r, long masterSystemTime) {
      return false;
    };

    @Override
    void cleanupFailedOpen(HRegion region) throws IOException {
      throw new IOException("FileSystem got closed.");
    }
  };
  rsServices.getRegionsInTransitionInRS().put(TEST_HRI.getEncodedNameAsBytes(), Boolean.TRUE);
  try {
    handler.process();
  } catch (Exception e) {
    // Ignore the IOException that we have thrown from cleanupFailedOpen
  }
  RegionTransition rt = RegionTransition.parseFrom(ZKAssign.getData(server.getZooKeeper(),
      TEST_HRI.getEncodedName()));
  assertEquals(EventType.RS_ZK_REGION_FAILED_OPEN, rt.getEventType());
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:38,代码来源:TestOpenRegionHandler.java

示例9: testTransitionToFailedOpenFromOffline

import org.apache.hadoop.hbase.coordination.ZkCoordinatedStateManager; //导入依赖的package包/类
@Test
public void testTransitionToFailedOpenFromOffline() throws Exception {
  Server server = new MockServer(HTU);
  RegionServerServices rsServices = HTU.createMockRegionServerService(server.getServerName());
  // Create it OFFLINE, which is what it expects
  ZKAssign.createNodeOffline(server.getZooKeeper(), TEST_HRI, server.getServerName());
  // Create the handler
  ZkCoordinatedStateManager csm = new ZkCoordinatedStateManager();
  csm.initialize(server);
  csm.start();

  ZkOpenRegionCoordination.ZkOpenRegionDetails zkCrd =
    new ZkOpenRegionCoordination.ZkOpenRegionDetails();
  zkCrd.setServerName(server.getServerName());

  ZkOpenRegionCoordination openRegionCoordination =
    new ZkOpenRegionCoordination(csm, server.getZooKeeper()) {
    @Override
    public boolean transitionFromOfflineToOpening(HRegionInfo regionInfo,
                                                  OpenRegionDetails ord) {
      return false;
    }
  };

  OpenRegionHandler handler = new OpenRegionHandler(server, rsServices, TEST_HRI, TEST_HTD,
    -1, openRegionCoordination, zkCrd);
  rsServices.getRegionsInTransitionInRS().put(TEST_HRI.getEncodedNameAsBytes(), Boolean.TRUE);

  handler.process();

  RegionTransition rt = RegionTransition.parseFrom(ZKAssign.getData(server.getZooKeeper(),
      TEST_HRI.getEncodedName()));
  assertEquals(EventType.RS_ZK_REGION_FAILED_OPEN, rt.getEventType());
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:35,代码来源:TestOpenRegionHandler.java

示例10: testRegionInOpeningStateOnDeadRSWhileMasterFailover

import org.apache.hadoop.hbase.coordination.ZkCoordinatedStateManager; //导入依赖的package包/类
/**
 * Test the scenario when the master is in failover and trying to process a
 * region which is in Opening state on a dead RS. Master will force offline the
 * region and put it in transition. AM relies on SSH to reassign it.
 */
@Test(timeout = 60000)
public void testRegionInOpeningStateOnDeadRSWhileMasterFailover() throws IOException,
    KeeperException, ServiceException, CoordinatedStateException, InterruptedException {
  AssignmentManagerWithExtrasForTesting am = setUpMockedAssignmentManager(
    this.server, this.serverManager);
  ZKAssign.createNodeOffline(this.watcher, REGIONINFO, SERVERNAME_A);
  int version = ZKAssign.getVersion(this.watcher, REGIONINFO);
  ZKAssign.transitionNode(this.watcher, REGIONINFO, SERVERNAME_A, EventType.M_ZK_REGION_OFFLINE,
      EventType.RS_ZK_REGION_OPENING, version);
  RegionTransition rt = RegionTransition.createRegionTransition(EventType.RS_ZK_REGION_OPENING,
      REGIONINFO.getRegionName(), SERVERNAME_A, HConstants.EMPTY_BYTE_ARRAY);
  version = ZKAssign.getVersion(this.watcher, REGIONINFO);
  Mockito.when(this.serverManager.isServerOnline(SERVERNAME_A)).thenReturn(false);
  am.getRegionStates().logSplit(SERVERNAME_A); // Assume log splitting is done
  am.getRegionStates().createRegionState(REGIONINFO);
  am.gate.set(false);

  BaseCoordinatedStateManager cp = new ZkCoordinatedStateManager();
  cp.initialize(server);
  cp.start();

  OpenRegionCoordination orc = cp.getOpenRegionCoordination();
  ZkOpenRegionCoordination.ZkOpenRegionDetails zkOrd =
    new ZkOpenRegionCoordination.ZkOpenRegionDetails();
  zkOrd.setServerName(server.getServerName());
  zkOrd.setVersion(version);

  assertFalse(am.processRegionsInTransition(rt, REGIONINFO, orc, zkOrd));
  am.getTableStateManager().setTableState(REGIONINFO.getTable(), Table.State.ENABLED);
  processServerShutdownHandler(am, false);
  // Waiting for the assignment to get completed.
  while (!am.gate.get()) {
    Thread.sleep(10);
  }
  assertTrue("The region should be assigned immediately.", null != am.regionPlans.get(REGIONINFO
      .getEncodedName()));
  am.shutdown();
}
 
开发者ID:grokcoder,项目名称:pbase,代码行数:44,代码来源:TestAssignmentManager.java

示例11: testFailedOpenRegion

import org.apache.hadoop.hbase.coordination.ZkCoordinatedStateManager; //导入依赖的package包/类
@Test
public void testFailedOpenRegion() throws Exception {
  Server server = new MockServer(HTU);
  RegionServerServices rsServices = HTU.createMockRegionServerService();

  // Create it OFFLINE, which is what it expects
  ZKAssign.createNodeOffline(server.getZooKeeper(), TEST_HRI, server.getServerName());

  ZkCoordinatedStateManager csm = new ZkCoordinatedStateManager();
  csm.initialize(server);
  csm.start();

  ZkOpenRegionCoordination.ZkOpenRegionDetails zkCrd =
    new ZkOpenRegionCoordination.ZkOpenRegionDetails();
  zkCrd.setServerName(server.getServerName());

  // Create the handler
  OpenRegionHandler handler =
    new OpenRegionHandler(server, rsServices, TEST_HRI, TEST_HTD,
      csm.getOpenRegionCoordination(), zkCrd) {
      @Override
      HRegion openRegion() {
        // Fake failure of opening a region due to an IOE, which is caught
        return null;
      }
  };
  rsServices.getRegionsInTransitionInRS().put(
    TEST_HRI.getEncodedNameAsBytes(), Boolean.TRUE);
  handler.process();

  // Handler should have transitioned it to FAILED_OPEN
  RegionTransition rt = RegionTransition.parseFrom(
    ZKAssign.getData(server.getZooKeeper(), TEST_HRI.getEncodedName()));
  assertEquals(EventType.RS_ZK_REGION_FAILED_OPEN, rt.getEventType());
}
 
开发者ID:grokcoder,项目名称:pbase,代码行数:36,代码来源:TestOpenRegionHandler.java

示例12: testFailedUpdateMeta

import org.apache.hadoop.hbase.coordination.ZkCoordinatedStateManager; //导入依赖的package包/类
@Test
public void testFailedUpdateMeta() throws Exception {
  Server server = new MockServer(HTU);
  RegionServerServices rsServices = HTU.createMockRegionServerService();

  // Create it OFFLINE, which is what it expects
  ZKAssign.createNodeOffline(server.getZooKeeper(), TEST_HRI, server.getServerName());

  // Create the handler
  ZkCoordinatedStateManager csm = new ZkCoordinatedStateManager();
  csm.initialize(server);
  csm.start();

  ZkOpenRegionCoordination.ZkOpenRegionDetails zkCrd =
    new ZkOpenRegionCoordination.ZkOpenRegionDetails();
  zkCrd.setServerName(server.getServerName());

  OpenRegionHandler handler = new OpenRegionHandler(server, rsServices, TEST_HRI, TEST_HTD,
    csm.getOpenRegionCoordination(), zkCrd) {
      @Override
      boolean updateMeta(final HRegion r) {
        // Fake failure of updating META
        return false;
      }
  };
  rsServices.getRegionsInTransitionInRS().put(
    TEST_HRI.getEncodedNameAsBytes(), Boolean.TRUE);
  handler.process();

  // Handler should have transitioned it to FAILED_OPEN
  RegionTransition rt = RegionTransition.parseFrom(
    ZKAssign.getData(server.getZooKeeper(), TEST_HRI.getEncodedName()));
  assertEquals(EventType.RS_ZK_REGION_FAILED_OPEN, rt.getEventType());
}
 
开发者ID:grokcoder,项目名称:pbase,代码行数:35,代码来源:TestOpenRegionHandler.java

示例13: testTransitionToFailedOpenEvenIfCleanupFails

import org.apache.hadoop.hbase.coordination.ZkCoordinatedStateManager; //导入依赖的package包/类
@Test
public void testTransitionToFailedOpenEvenIfCleanupFails() throws Exception {
  Server server = new MockServer(HTU);
  RegionServerServices rsServices = HTU.createMockRegionServerService();
  // Create it OFFLINE, which is what it expects
  ZKAssign.createNodeOffline(server.getZooKeeper(), TEST_HRI, server.getServerName());
  // Create the handler
  ZkCoordinatedStateManager csm = new ZkCoordinatedStateManager();
  csm.initialize(server);
  csm.start();

  ZkOpenRegionCoordination.ZkOpenRegionDetails zkCrd =
    new ZkOpenRegionCoordination.ZkOpenRegionDetails();
  zkCrd.setServerName(server.getServerName());

  OpenRegionHandler handler = new OpenRegionHandler(server, rsServices, TEST_HRI, TEST_HTD,
    csm.getOpenRegionCoordination(), zkCrd) {
    @Override
    boolean updateMeta(HRegion r) {
      return false;
    };

    @Override
    void cleanupFailedOpen(HRegion region) throws IOException {
      throw new IOException("FileSystem got closed.");
    }
  };
  rsServices.getRegionsInTransitionInRS().put(TEST_HRI.getEncodedNameAsBytes(), Boolean.TRUE);
  try {
    handler.process();
  } catch (Exception e) {
    // Ignore the IOException that we have thrown from cleanupFailedOpen
  }
  RegionTransition rt = RegionTransition.parseFrom(ZKAssign.getData(server.getZooKeeper(),
      TEST_HRI.getEncodedName()));
  assertEquals(EventType.RS_ZK_REGION_FAILED_OPEN, rt.getEventType());
}
 
开发者ID:grokcoder,项目名称:pbase,代码行数:38,代码来源:TestOpenRegionHandler.java

示例14: testTransitionToFailedOpenFromOffline

import org.apache.hadoop.hbase.coordination.ZkCoordinatedStateManager; //导入依赖的package包/类
@Test
public void testTransitionToFailedOpenFromOffline() throws Exception {
  Server server = new MockServer(HTU);
  RegionServerServices rsServices = HTU.createMockRegionServerService(server.getServerName());
  // Create it OFFLINE, which is what it expects
  ZKAssign.createNodeOffline(server.getZooKeeper(), TEST_HRI, server.getServerName());
  // Create the handler
  ZkCoordinatedStateManager csm = new ZkCoordinatedStateManager();
  csm.initialize(server);
  csm.start();

  ZkOpenRegionCoordination.ZkOpenRegionDetails zkCrd =
    new ZkOpenRegionCoordination.ZkOpenRegionDetails();
  zkCrd.setServerName(server.getServerName());

  ZkOpenRegionCoordination openRegionCoordination =
    new ZkOpenRegionCoordination(csm, server.getZooKeeper()) {
    @Override
    public boolean transitionFromOfflineToOpening(HRegionInfo regionInfo,
                                                  OpenRegionDetails ord) {
      return false;
    }
  };

  OpenRegionHandler handler = new OpenRegionHandler(server, rsServices, TEST_HRI, TEST_HTD,
    openRegionCoordination, zkCrd);
  rsServices.getRegionsInTransitionInRS().put(TEST_HRI.getEncodedNameAsBytes(), Boolean.TRUE);

  handler.process();

  RegionTransition rt = RegionTransition.parseFrom(ZKAssign.getData(server.getZooKeeper(),
      TEST_HRI.getEncodedName()));
  assertEquals(EventType.RS_ZK_REGION_FAILED_OPEN, rt.getEventType());
}
 
开发者ID:grokcoder,项目名称:pbase,代码行数:35,代码来源:TestOpenRegionHandler.java

示例15: testShouldNotCompeleteOpenedRegionSuccessfullyIfVersionMismatches

import org.apache.hadoop.hbase.coordination.ZkCoordinatedStateManager; //导入依赖的package包/类
@Test
public void testShouldNotCompeleteOpenedRegionSuccessfullyIfVersionMismatches()
    throws Exception {
  HRegion region = null;
  try {
    int testIndex = 0;
    TEST_UTIL.startMiniZKCluster();
    final Server server = new MockServer(TEST_UTIL);
    HTableDescriptor htd = new HTableDescriptor(
        TableName.valueOf("testShouldNotCompeleteOpenedRegionSuccessfullyIfVersionMismatches"));
    HRegionInfo hri = new HRegionInfo(htd.getTableName(),
        Bytes.toBytes(testIndex), Bytes.toBytes(testIndex + 1));
    region = HRegion.createHRegion(hri, TEST_UTIL.getDataTestDir(), TEST_UTIL.getConfiguration(), htd);
    assertNotNull(region);
    AssignmentManager am = Mockito.mock(AssignmentManager.class);
    RegionStates rsm = Mockito.mock(RegionStates.class);
    Mockito.doReturn(rsm).when(am).getRegionStates();
    when(rsm.isRegionInTransition(hri)).thenReturn(false);
    when(rsm.getRegionState(hri)).thenReturn(
      new RegionState(region.getRegionInfo(), RegionState.State.OPEN,
        System.currentTimeMillis(), server.getServerName()));
    // create a node with OPENED state
    zkw = HBaseTestingUtility.createAndForceNodeToOpenedState(TEST_UTIL,
        region, server.getServerName());
    when(am.getTableStateManager()).thenReturn(new ZKTableStateManager(zkw));
    Stat stat = new Stat();
    String nodeName = ZKAssign.getNodeName(zkw, region.getRegionInfo()
        .getEncodedName());
    ZKUtil.getDataAndWatch(zkw, nodeName, stat);

    // use the version for the OpenedRegionHandler
    BaseCoordinatedStateManager csm = new ZkCoordinatedStateManager();
    csm.initialize(server);
    csm.start();

    OpenRegionCoordination orc = csm.getOpenRegionCoordination();
    ZkOpenRegionCoordination.ZkOpenRegionDetails zkOrd =
      new ZkOpenRegionCoordination.ZkOpenRegionDetails();
    zkOrd.setServerName(server.getServerName());
    zkOrd.setVersion(stat.getVersion());
    OpenedRegionHandler handler = new OpenedRegionHandler(server, am, region
        .getRegionInfo(), orc, zkOrd);
    // Once again overwrite the same znode so that the version changes.
    ZKAssign.transitionNode(zkw, region.getRegionInfo(), server
        .getServerName(), EventType.RS_ZK_REGION_OPENED,
        EventType.RS_ZK_REGION_OPENED, stat.getVersion());

    // Should not invoke assignmentmanager.regionOnline. If it is 
    // invoked as per current mocking it will throw null pointer exception.
    boolean expectedException = false;
    try {
      handler.process();
    } catch (Exception e) {
      expectedException = true;
    }
    assertFalse("The process method should not throw any exception.",
        expectedException);
    List<String> znodes = ZKUtil.listChildrenAndWatchForNewChildren(zkw,
        zkw.assignmentZNode);
    String regionName = znodes.get(0);
    assertEquals("The region should not be opened successfully.", regionName,
        region.getRegionInfo().getEncodedName());
  } finally {
    HRegion.closeHRegion(region);
    TEST_UTIL.shutdownMiniZKCluster();
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:68,代码来源:TestOpenedRegionHandler.java


注:本文中的org.apache.hadoop.hbase.coordination.ZkCoordinatedStateManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。