當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。