當前位置: 首頁>>代碼示例>>Java>>正文


Java Admin.getTableRegions方法代碼示例

本文整理匯總了Java中org.apache.hadoop.hbase.client.Admin.getTableRegions方法的典型用法代碼示例。如果您正苦於以下問題:Java Admin.getTableRegions方法的具體用法?Java Admin.getTableRegions怎麽用?Java Admin.getTableRegions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.hadoop.hbase.client.Admin的用法示例。


在下文中一共展示了Admin.getTableRegions方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: creatTable

import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
/**
 * create table
 */
public static void creatTable(String tableName, String[] familys)
        throws Exception {
    Admin admin = connection.getAdmin();
    List<HRegionInfo> list = admin.getTableRegions(TableName.valueOf(tableName));
    if (admin.tableExists(TableName.valueOf(tableName))) {
        System.out.println("table already exists!");
    } else {
        HTableDescriptor tableDesc = new HTableDescriptor(tableName);
        for (int i = 0; i < familys.length; i++) {
            tableDesc.addFamily(new HColumnDescriptor(familys[i]));
        }
        admin.createTable(tableDesc);
        System.out.println("create table " + tableName + " ok.");
    }
}
 
開發者ID:yjp123456,項目名稱:SparkDemo,代碼行數:19,代碼來源:HBaseTest.java

示例2: sniff

import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
private static List<Future<Void>> sniff(final Admin admin, final Sink sink,
    HTableDescriptor tableDesc, ExecutorService executor, TaskType taskType) throws Exception {
  Table table = null;
  try {
    table = admin.getConnection().getTable(tableDesc.getTableName());
  } catch (TableNotFoundException e) {
    return new ArrayList<Future<Void>>();
  }
  List<RegionTask> tasks = new ArrayList<RegionTask>();
  try {
    for (HRegionInfo region : admin.getTableRegions(tableDesc.getTableName())) {
      tasks.add(new RegionTask(admin.getConnection(), region, sink, taskType));
    }
  } finally {
    table.close();
  }
  return executor.invokeAll(tasks);
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:19,代碼來源:Canary.java

示例3: perform

import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
@Override
public void perform() throws Exception {
  HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
  Admin admin = util.getHBaseAdmin();

  LOG.info("Performing action: Flush random region of table " + tableName);
  List<HRegionInfo> regions = admin.getTableRegions(tableName);
  if (regions == null || regions.isEmpty()) {
    LOG.info("Table " + tableName + " doesn't have regions to flush");
    return;
  }

  HRegionInfo region = PolicyBasedChaosMonkey.selectRandomItem(
    regions.toArray(new HRegionInfo[regions.size()]));
  LOG.debug("Flushing region " + region.getRegionNameAsString());
  try {
    admin.flushRegion(region.getRegionName());
  } catch (Exception ex) {
    LOG.warn("Flush failed, might be caused by other chaos: " + ex.getMessage());
  }
  if (sleepTime > 0) {
    Thread.sleep(sleepTime);
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:25,代碼來源:FlushRandomRegionOfTableAction.java

示例4: perform

import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
@Override
public void perform() throws Exception {
  if (sleepTime > 0) {
    Thread.sleep(sleepTime);
  }

  HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
  Admin admin = util.getHBaseAdmin();

  LOG.info("Performing action: Move random region of table " + tableName);
  List<HRegionInfo> regions = admin.getTableRegions(tableName);
  if (regions == null || regions.isEmpty()) {
    LOG.info("Table " + tableName + " doesn't have regions to move");
    return;
  }

  HRegionInfo region = PolicyBasedChaosMonkey.selectRandomItem(
    regions.toArray(new HRegionInfo[regions.size()]));
  LOG.debug("Unassigning region " + region.getRegionNameAsString());
  admin.unassign(region.getRegionName(), false);
  if (sleepTime > 0) {
    Thread.sleep(sleepTime);
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:25,代碼來源:MoveRandomRegionOfTableAction.java

示例5: verifyReplicasCameOnline

import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
public static void verifyReplicasCameOnline(TableName tableName, Admin admin,
    int regionReplication) throws IOException {
  List<HRegionInfo> regions = admin.getTableRegions(tableName);
  HashSet<HRegionInfo> set = new HashSet<HRegionInfo>();
  for (HRegionInfo hri : regions) {
    set.add(RegionReplicaUtil.getRegionInfoForDefaultReplica(hri));
    for (int i = 0; i < regionReplication; i++) {
      HRegionInfo replica = RegionReplicaUtil.getRegionInfoForReplica(hri, i);
      if (!regions.contains(replica)) {
        Assert.fail(replica + " is not contained in the list of online regions");
      }
    }
  }
  assert(set.size() == getSplitKeys().length + 1);
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:16,代碼來源:SnapshotTestingUtils.java

示例6: perform

import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
@Override
public void perform() throws Exception {
  HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
  Admin admin = util.getHBaseAdmin();
  boolean major = RandomUtils.nextInt(100) < majorRatio;

  LOG.info("Performing action: Compact random region of table "
    + tableName + ", major=" + major);
  List<HRegionInfo> regions = admin.getTableRegions(tableName);
  if (regions == null || regions.isEmpty()) {
    LOG.info("Table " + tableName + " doesn't have regions to compact");
    return;
  }

  HRegionInfo region = PolicyBasedChaosMonkey.selectRandomItem(
    regions.toArray(new HRegionInfo[regions.size()]));

  try {
    if (major) {
      LOG.debug("Major compacting region " + region.getRegionNameAsString());
      admin.majorCompactRegion(region.getRegionName());
    } else {
      LOG.debug("Compacting region " + region.getRegionNameAsString());
      admin.compactRegion(region.getRegionName());
    }
  } catch (Exception ex) {
    LOG.warn("Compaction failed, might be caused by other chaos: " + ex.getMessage());
  }
  if (sleepTime > 0) {
    Thread.sleep(sleepTime);
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:33,代碼來源:CompactRandomRegionOfTableAction.java

示例7: perform

import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
@Override
public void perform() throws Exception {
  HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
  Admin admin = util.getHBaseAdmin();

  LOG.info("Performing action: Merge random adjacent regions of table " + tableName);
  List<HRegionInfo> regions = admin.getTableRegions(tableName);
  if (regions == null || regions.size() < 2) {
    LOG.info("Table " + tableName + " doesn't have enough regions to merge");
    return;
  }

  int i = RandomUtils.nextInt(regions.size() - 1);
  HRegionInfo a = regions.get(i++);
  HRegionInfo b = regions.get(i);
  LOG.debug("Merging " + a.getRegionNameAsString() + " and " + b.getRegionNameAsString());

  // Don't try the merge if we're stopping
  if (context.isStopping()) {
    return;
  }

  try {
    admin.mergeRegions(a.getEncodedNameAsBytes(), b.getEncodedNameAsBytes(), false);
  } catch (Exception ex) {
    LOG.warn("Merge failed, might be caused by other chaos: " + ex.getMessage());
  }
  if (sleepTime > 0) {
    Thread.sleep(sleepTime);
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:32,代碼來源:MergeRandomAdjacentRegionsOfTableAction.java

示例8: perform

import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
@Override
public void perform() throws Exception {
  HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
  Admin admin = util.getHBaseAdmin();

  LOG.info("Performing action: Split random region of table " + tableName);
  List<HRegionInfo> regions = admin.getTableRegions(tableName);
  if (regions == null || regions.isEmpty()) {
    LOG.info("Table " + tableName + " doesn't have regions to split");
    return;
  }
  // Don't try the split if we're stopping
  if (context.isStopping()) {
    return;
  }

  HRegionInfo region = PolicyBasedChaosMonkey.selectRandomItem(
      regions.toArray(new HRegionInfo[regions.size()]));
  LOG.debug("Splitting region " + region.getRegionNameAsString());
  try {
    admin.splitRegion(region.getRegionName());
  } catch (Exception ex) {
    LOG.warn("Split failed, might be caused by other chaos: " + ex.getMessage());
  }
  if (sleepTime > 0) {
    Thread.sleep(sleepTime);
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:29,代碼來源:SplitRandomRegionOfTableAction.java

示例9: testAssignmentListener

import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
@Test(timeout=60000)
public void testAssignmentListener() throws IOException, InterruptedException {
  AssignmentManager am = TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager();
  Admin admin = TEST_UTIL.getHBaseAdmin();

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

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

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

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

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

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

    // Delete the table
    LOG.info("Drop Table");
    listener.reset();
    TEST_UTIL.deleteTable(TABLE_NAME);
    listener.awaitModifications(1);
    assertEquals(0, listener.getLoadCount());
    assertEquals(1, listener.getCloseCount());
  } finally {
    am.unregisterListener(listener);
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:78,代碼來源:TestAssignmentListener.java

示例10: testSnapshotStateAfterMerge

import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
@Test (timeout=300000)
public void testSnapshotStateAfterMerge() throws Exception {
  int numRows = DEFAULT_NUM_ROWS;
  Admin admin = UTIL.getHBaseAdmin();
  // make sure we don't fail on listing snapshots
  SnapshotTestingUtils.assertNoSnapshots(admin);
  // load the table so we have some data
  SnapshotTestingUtils.loadData(UTIL, TABLE_NAME, numRows, TEST_FAM);

  // Take a snapshot
  String snapshotBeforeMergeName = "snapshotBeforeMerge";
  admin.snapshot(snapshotBeforeMergeName, TABLE_NAME, SnapshotDescription.Type.FLUSH);

  // Clone the table
  TableName cloneBeforeMergeName = TableName.valueOf("cloneBeforeMerge");
  admin.cloneSnapshot(snapshotBeforeMergeName, cloneBeforeMergeName);
  SnapshotTestingUtils.waitForTableToBeOnline(UTIL, cloneBeforeMergeName);

  // Merge two regions
  List<HRegionInfo> regions = admin.getTableRegions(TABLE_NAME);
  Collections.sort(regions, new Comparator<HRegionInfo>() {
    public int compare(HRegionInfo r1, HRegionInfo r2) {
      return Bytes.compareTo(r1.getStartKey(), r2.getStartKey());
    }
  });

  int numRegions = admin.getTableRegions(TABLE_NAME).size();
  int numRegionsAfterMerge = numRegions - 2;
  admin.mergeRegions(regions.get(1).getEncodedNameAsBytes(),
      regions.get(2).getEncodedNameAsBytes(), true);
  admin.mergeRegions(regions.get(5).getEncodedNameAsBytes(),
      regions.get(6).getEncodedNameAsBytes(), true);

  // Verify that there's one region less
  waitRegionsAfterMerge(numRegionsAfterMerge);
  assertEquals(numRegionsAfterMerge, admin.getTableRegions(TABLE_NAME).size());

  // Clone the table
  TableName cloneAfterMergeName = TableName.valueOf("cloneAfterMerge");
  admin.cloneSnapshot(snapshotBeforeMergeName, cloneAfterMergeName);
  SnapshotTestingUtils.waitForTableToBeOnline(UTIL, cloneAfterMergeName);

  SnapshotTestingUtils.verifyRowCount(UTIL, TABLE_NAME, numRows);
  SnapshotTestingUtils.verifyRowCount(UTIL, cloneBeforeMergeName, numRows);
  SnapshotTestingUtils.verifyRowCount(UTIL, cloneAfterMergeName, numRows);

  // test that we can delete the snapshot
  UTIL.deleteTable(cloneAfterMergeName);
  UTIL.deleteTable(cloneBeforeMergeName);
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:51,代碼來源:TestFlushSnapshotFromClient.java

示例11: testTakeSnapshotAfterMerge

import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
@Test (timeout=300000)
public void testTakeSnapshotAfterMerge() throws Exception {
  int numRows = DEFAULT_NUM_ROWS;
  Admin admin = UTIL.getHBaseAdmin();
  // make sure we don't fail on listing snapshots
  SnapshotTestingUtils.assertNoSnapshots(admin);
  // load the table so we have some data
  SnapshotTestingUtils.loadData(UTIL, TABLE_NAME, numRows, TEST_FAM);

  // Merge two regions
  List<HRegionInfo> regions = admin.getTableRegions(TABLE_NAME);
  Collections.sort(regions, new Comparator<HRegionInfo>() {
    public int compare(HRegionInfo r1, HRegionInfo r2) {
      return Bytes.compareTo(r1.getStartKey(), r2.getStartKey());
    }
  });

  int numRegions = admin.getTableRegions(TABLE_NAME).size();
  int numRegionsAfterMerge = numRegions - 2;
  admin.mergeRegions(regions.get(1).getEncodedNameAsBytes(),
      regions.get(2).getEncodedNameAsBytes(), true);
  admin.mergeRegions(regions.get(5).getEncodedNameAsBytes(),
      regions.get(6).getEncodedNameAsBytes(), true);

  waitRegionsAfterMerge(numRegionsAfterMerge);
  assertEquals(numRegionsAfterMerge, admin.getTableRegions(TABLE_NAME).size());

  // Take a snapshot
  String snapshotName = "snapshotAfterMerge";
  SnapshotTestingUtils.snapshot(admin, snapshotName, TABLE_NAME.getNameAsString(),
    SnapshotDescription.Type.FLUSH, 3);

  // Clone the table
  TableName cloneName = TableName.valueOf("cloneMerge");
  admin.cloneSnapshot(snapshotName, cloneName);
  SnapshotTestingUtils.waitForTableToBeOnline(UTIL, cloneName);

  SnapshotTestingUtils.verifyRowCount(UTIL, TABLE_NAME, numRows);
  SnapshotTestingUtils.verifyRowCount(UTIL, cloneName, numRows);

  // test that we can delete the snapshot
  UTIL.deleteTable(cloneName);
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:44,代碼來源:TestFlushSnapshotFromClient.java

示例12: perform

import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
@Override
public void perform() throws Exception {
  if (sleepTime > 0) {
    Thread.sleep(sleepTime);
  }

  Admin admin = this.context.getHBaseIntegrationTestingUtility().getHBaseAdmin();
  Collection<ServerName> serversList = admin.getClusterStatus().getServers();
  ServerName[] servers = serversList.toArray(new ServerName[serversList.size()]);

  LOG.info("Performing action: Move regions of table " + tableName);
  List<HRegionInfo> regions = admin.getTableRegions(tableName);
  if (regions == null || regions.isEmpty()) {
    LOG.info("Table " + tableName + " doesn't have regions to move");
    return;
  }

  Collections.shuffle(regions);

  long start = System.currentTimeMillis();
  for (HRegionInfo regionInfo:regions) {

    // Don't try the move if we're stopping
    if (context.isStopping()) {
      return;
    }

    try {
      String destServerName =
        servers[RandomUtils.nextInt(servers.length)].getServerName();
      LOG.debug("Moving " + regionInfo.getRegionNameAsString() + " to " + destServerName);
      admin.move(regionInfo.getEncodedNameAsBytes(), Bytes.toBytes(destServerName));
    } catch (Exception ex) {
      LOG.warn("Move failed, might be caused by other chaos: " + ex.getMessage());
    }
    if (sleepTime > 0) {
      Thread.sleep(sleepTime);
    }

    // put a limit on max num regions. Otherwise, this won't finish
    // with a sleep time of 10sec, 100 regions will finish in 16min
    if (System.currentTimeMillis() - start > maxTime) {
      break;
    }
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:47,代碼來源:MoveRegionsOfTableAction.java


注:本文中的org.apache.hadoop.hbase.client.Admin.getTableRegions方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。