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


Java HTable.getRegionLocator方法代码示例

本文整理汇总了Java中org.apache.hadoop.hbase.client.HTable.getRegionLocator方法的典型用法代码示例。如果您正苦于以下问题:Java HTable.getRegionLocator方法的具体用法?Java HTable.getRegionLocator怎么用?Java HTable.getRegionLocator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.hadoop.hbase.client.HTable的用法示例。


在下文中一共展示了HTable.getRegionLocator方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setHTable

import org.apache.hadoop.hbase.client.HTable; //导入方法依赖的package包/类
/**
 * Allows subclasses to set the {@link HTable}.
 *
 * Will attempt to reuse the underlying Connection for our own needs, including
 * retreiving an Admin interface to the HBase cluster.
 *
 * @param table  The table to get the data from.
 * @throws IOException 
 * @deprecated Use {@link #initializeTable(Connection, TableName)} instead.
 */
@Deprecated
protected void setHTable(HTable table) throws IOException {
  this.table = table;
  this.connection = table.getConnection();
  try {
    this.regionLocator = table.getRegionLocator();
    this.admin = this.connection.getAdmin();
  } catch (NeedUnmanagedConnectionException exception) {
    LOG.warn("You are using an HTable instance that relies on an HBase-managed Connection. " +
        "This is usually due to directly creating an HTable, which is deprecated. Instead, you " +
        "should create a Connection object and then request a Table instance from it. If you " +
        "don't need the Table instance for your own use, you should instead use the " +
        "TableInputFormatBase.initalizeTable method directly.");
    LOG.info("Creating an additional unmanaged connection because user provided one can't be " +
        "used for administrative actions. We'll close it when we close out the table.");
    LOG.debug("Details about our failure to request an administrative interface.", exception);
    // Do we need a "copy the settings from this Connection" method? are things like the User
    // properly maintained by just looking again at the Configuration?
    this.connection = ConnectionFactory.createConnection(this.connection.getConfiguration());
    this.regionLocator = this.connection.getRegionLocator(table.getName());
    this.admin = this.connection.getAdmin();
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:34,代码来源:TableInputFormatBase.java

示例2: beforeAllTests

import org.apache.hadoop.hbase.client.HTable; //导入方法依赖的package包/类
@BeforeClass public static void beforeAllTests() throws Exception {
  Configuration c = TEST_UTIL.getConfiguration();
  c.setBoolean("hbase.assignment.usezk", true);
  c.setBoolean("dfs.support.append", true);
  c.setInt("hbase.regionserver.info.port", 0);
  TEST_UTIL.startMiniCluster(2);
  TEST_UTIL.createMultiRegionTable(TABLENAME, FAMILIES);
  HTable t = new HTable(TEST_UTIL.getConfiguration(), TABLENAME);
  countOfRegions = -1;
  try (RegionLocator r = t.getRegionLocator()) {
    countOfRegions = r.getStartKeys().length;
  }
  waitUntilAllRegionsAssigned();
  addToEachStartKey(countOfRegions);
  t.close();
  TEST_UTIL.getHBaseCluster().getMaster().assignmentManager.initializeHandlerTrackers();
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:18,代码来源:TestZKBasedOpenCloseRegion.java

示例3: beforeAllTests

import org.apache.hadoop.hbase.client.HTable; //导入方法依赖的package包/类
/**
 * Start up a mini cluster and put a small table of many empty regions into it.
 * @throws Exception
 */
@BeforeClass public static void beforeAllTests() throws Exception {
  TEST_UTIL.getConfiguration().setBoolean("dfs.support.append", true);
  TEST_UTIL.startMiniCluster(2);
  // Create a table of three families.  This will assign a region.
  TEST_UTIL.createMultiRegionTable(TABLENAME, FAMILIES);
  HTable t = (HTable) TEST_UTIL.getConnection().getTable(TABLENAME);
  int countOfRegions = -1;
  try (RegionLocator r = t.getRegionLocator()) {
    countOfRegions = r.getStartKeys().length;
  }
  TEST_UTIL.waitUntilAllRegionsAssigned(TABLENAME);
  addToEachStartKey(countOfRegions);
  t.close();
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:19,代码来源:TestMasterTransitions.java

示例4: testRetrying

import org.apache.hadoop.hbase.client.HTable; //导入方法依赖的package包/类
/**
 * Does {@link MetaTableAccessor#getRegion(Connection, byte[])} and a write
 * against hbase:meta while its hosted server is restarted to prove our retrying
 * works.
 * @throws IOException
 * @throws InterruptedException
 */
@Test public void testRetrying()
throws IOException, InterruptedException {
  final TableName name =
      TableName.valueOf("testRetrying");
  LOG.info("Started " + name);
  HTable t = UTIL.createMultiRegionTable(name, HConstants.CATALOG_FAMILY);
  int regionCount = -1;
  try (RegionLocator r = t.getRegionLocator()) {
    regionCount = r.getStartKeys().length;
  }
  // Test it works getting a region from just made user table.
  final List<HRegionInfo> regions =
    testGettingTableRegions(connection, name, regionCount);
  MetaTask reader = new MetaTask(connection, "reader") {
    @Override
    void metaTask() throws Throwable {
      testGetRegion(connection, regions.get(0));
      LOG.info("Read " + regions.get(0).getEncodedName());
    }
  };
  MetaTask writer = new MetaTask(connection, "writer") {
    @Override
    void metaTask() throws Throwable {
      MetaTableAccessor.addRegionToMeta(connection, regions.get(0));
      LOG.info("Wrote " + regions.get(0).getEncodedName());
    }
  };
  reader.start();
  writer.start();

  // We're gonna check how it takes. If it takes too long, we will consider
  //  it as a fail. We can't put that in the @Test tag as we want to close
  //  the threads nicely
  final long timeOut = 180000;
  long startTime = System.currentTimeMillis();

  try {
    // Make sure reader and writer are working.
    assertTrue(reader.isProgressing());
    assertTrue(writer.isProgressing());

    // Kill server hosting meta -- twice  . See if our reader/writer ride over the
    // meta moves.  They'll need to retry.
    for (int i = 0; i < 2; i++) {
      LOG.info("Restart=" + i);
      UTIL.ensureSomeRegionServersAvailable(2);
      int index = -1;
      do {
        index = UTIL.getMiniHBaseCluster().getServerWithMeta();
      } while (index == -1 &&
        startTime + timeOut < System.currentTimeMillis());

      if (index != -1){
        UTIL.getMiniHBaseCluster().abortRegionServer(index);
        UTIL.getMiniHBaseCluster().waitOnRegionServer(index);
      }
    }

    assertTrue("reader: " + reader.toString(), reader.isProgressing());
    assertTrue("writer: " + writer.toString(), writer.isProgressing());
  } catch (IOException e) {
    throw e;
  } finally {
    reader.stop = true;
    writer.stop = true;
    reader.join();
    writer.join();
    t.close();
  }
  long exeTime = System.currentTimeMillis() - startTime;
  assertTrue("Timeout: test took " + exeTime / 1000 + " sec", exeTime < timeOut);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:80,代码来源:TestMetaTableAccessor.java

示例5: testForCheckingIfEnableAndDisableWorksFineAfterSwitch

import org.apache.hadoop.hbase.client.HTable; //导入方法依赖的package包/类
@Test
public void testForCheckingIfEnableAndDisableWorksFineAfterSwitch()
    throws Exception {
  final int NUM_MASTERS = 2;
  final int NUM_RS = 1;
  final int NUM_REGIONS_TO_CREATE = 4;

  // Start the cluster
  log("Starting cluster");
  Configuration conf = HBaseConfiguration.create();
  HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(conf);
  TEST_UTIL.startMiniCluster(NUM_MASTERS, NUM_RS);
  MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
  log("Waiting for active/ready master");
  cluster.waitForActiveAndReadyMaster();
  ZooKeeperWatcher zkw = new ZooKeeperWatcher(conf, "testmasterRestart", null);
  HMaster master = cluster.getMaster();

  // Create a table with regions
  TableName table = TableName.valueOf("tableRestart");
  byte[] family = Bytes.toBytes("family");
  log("Creating table with " + NUM_REGIONS_TO_CREATE + " regions");
  HTable ht = TEST_UTIL.createMultiRegionTable(table, family, NUM_REGIONS_TO_CREATE);
  int numRegions = -1;
  try (RegionLocator r = ht.getRegionLocator()) {
    numRegions = r.getStartKeys().length;
  }
  numRegions += 1; // catalogs
  log("Waiting for no more RIT\n");
  blockUntilNoRIT(zkw, master);
  log("Disabling table\n");
  TEST_UTIL.getHBaseAdmin().disableTable(table);

  NavigableSet<String> regions = HBaseTestingUtility.getAllOnlineRegions(cluster);
  assertEquals(
      "The number of regions for the table tableRestart should be 0 and only"
          + "the catalog and namespace tables should be present.", 2, regions.size());

  List<MasterThread> masterThreads = cluster.getMasterThreads();
  MasterThread activeMaster = null;
  if (masterThreads.get(0).getMaster().isActiveMaster()) {
    activeMaster = masterThreads.get(0);
  } else {
    activeMaster = masterThreads.get(1);
  }
  activeMaster.getMaster().stop(
      "stopping the active master so that the backup can become active");
  cluster.hbaseCluster.waitOnMaster(activeMaster);
  cluster.waitForActiveAndReadyMaster();

  assertTrue("The table should not be in enabled state", cluster.getMaster()
      .getAssignmentManager().getTableStateManager().isTableState(
      TableName.valueOf("tableRestart"), ZooKeeperProtos.Table.State.DISABLED,
      ZooKeeperProtos.Table.State.DISABLING));
  log("Enabling table\n");
  // Need a new Admin, the previous one is on the old master
  Admin admin = new HBaseAdmin(TEST_UTIL.getConfiguration());
  admin.enableTable(table);
  admin.close();
  log("Waiting for no more RIT\n");
  blockUntilNoRIT(zkw, master);
  log("Verifying there are " + numRegions + " assigned on cluster\n");
  regions = HBaseTestingUtility.getAllOnlineRegions(cluster);
  assertEquals("The assigned regions were not onlined after master"
      + " switch except for the catalog and namespace tables.",
        6, regions.size());
  assertTrue("The table should be in enabled state", cluster.getMaster()
      .getAssignmentManager().getTableStateManager()
      .isTableState(TableName.valueOf("tableRestart"), ZooKeeperProtos.Table.State.ENABLED));
  ht.close();
  TEST_UTIL.shutdownMiniCluster();
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:73,代码来源:TestMasterRestartAfterDisablingTable.java


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