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


Java Admin.snapshot方法代碼示例

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


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

示例1: doWork

import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
@Override
protected int doWork() throws Exception {
    Connection connection = null;
    Admin admin = null;
    try {
        connection = ConnectionFactory.createConnection(getConf());
        admin = connection.getAdmin();
        HBaseProtos.SnapshotDescription.Type type = HBaseProtos.SnapshotDescription.Type.FLUSH;
        if (snapshotType != null) {
            type = HBaseProtos.SnapshotDescription.Type.valueOf(snapshotName.toUpperCase());
        }

        admin.snapshot(snapshotName, TableName.valueOf(tableName), type);
    } catch (Exception e) {
        return -1;
    } finally {
        if (admin != null) {
            admin.close();
        }
        if (connection != null) {
            connection.close();
        }
    }
    return 0;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:26,代碼來源:CreateSnapshot.java

示例2: snapshot

import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
public static void snapshot(Admin admin,
    final String snapshotName, final String tableName,
    SnapshotDescription.Type type, int numTries) throws IOException {
  int tries = 0;
  CorruptedSnapshotException lastEx = null;
  while (tries++ < numTries) {
    try {
      admin.snapshot(snapshotName, TableName.valueOf(tableName), type);
      return;
    } catch (CorruptedSnapshotException cse) {
      LOG.warn("Got CorruptedSnapshotException", cse);
      lastEx = cse;
    }
  }
  throw lastEx;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:17,代碼來源:SnapshotTestingUtils.java

示例3: createSnapshotAndValidate

import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
/**
 * Take a snapshot of the specified table and verify the given families.
 * Note that this will leave the table disabled in the case of an offline snapshot.
 */
public static void createSnapshotAndValidate(Admin admin,
    TableName tableName, List<byte[]> nonEmptyFamilyNames, List<byte[]> emptyFamilyNames,
    String snapshotNameString, Path rootDir, FileSystem fs, boolean onlineSnapshot)
      throws Exception {
  if (!onlineSnapshot) {
    try {
      admin.disableTable(tableName);
    } catch (TableNotEnabledException tne) {
      LOG.info("In attempting to disable " + tableName + " it turns out that the this table is " +
          "already disabled.");
    }
  }
  admin.snapshot(snapshotNameString, tableName);

  List<SnapshotDescription> snapshots = SnapshotTestingUtils.assertExistsMatchingSnapshot(admin,
    snapshotNameString, tableName);
  if (snapshots == null || snapshots.size() != 1) {
    Assert.fail("Incorrect number of snapshots for table " + tableName);
  }

  SnapshotTestingUtils.confirmSnapshotValid(snapshots.get(0), tableName, nonEmptyFamilyNames,
    emptyFamilyNames, rootDir, admin, fs);
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:28,代碼來源:SnapshotTestingUtils.java

示例4: perform

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

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

  LOG.info("Performing action: Snapshot table " + tableName);
  admin.snapshot(snapshotName, tableName);
  if (sleepTime > 0) {
    Thread.sleep(sleepTime);
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:18,代碼來源:SnapshotTableAction.java

示例5: testFlushTableSnapshot

import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
/**
 * Test simple flush snapshotting a table that is online
 * @throws Exception
 */
@Test (timeout=300000)
public void testFlushTableSnapshot() throws Exception {
  Admin admin = UTIL.getHBaseAdmin();
  // make sure we don't fail on listing snapshots
  SnapshotTestingUtils.assertNoSnapshots(admin);

  // put some stuff in the table
  SnapshotTestingUtils.loadData(UTIL, TABLE_NAME, DEFAULT_NUM_ROWS, TEST_FAM);

  LOG.debug("FS state before snapshot:");
  UTIL.getHBaseCluster().getMaster().getMasterFileSystem().logFileSystemState(LOG);

  // take a snapshot of the enabled table
  String snapshotString = "offlineTableSnapshot";
  byte[] snapshot = Bytes.toBytes(snapshotString);
  admin.snapshot(snapshotString, TABLE_NAME, SnapshotDescription.Type.FLUSH);
  LOG.debug("Snapshot completed.");

  // make sure we have the snapshot
  List<SnapshotDescription> snapshots = SnapshotTestingUtils.assertOneSnapshotThatMatches(admin,
    snapshot, TABLE_NAME);

  // make sure its a valid snapshot
  LOG.debug("FS state after snapshot:");
  UTIL.getHBaseCluster().getMaster().getMasterFileSystem().logFileSystemState(LOG);

  SnapshotTestingUtils.confirmSnapshotValid(UTIL, snapshots.get(0), TABLE_NAME, TEST_FAM);
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:33,代碼來源:TestFlushSnapshotFromClient.java

示例6: testSkipFlushTableSnapshot

import org.apache.hadoop.hbase.client.Admin; //導入方法依賴的package包/類
/**
 * Test snapshotting a table that is online without flushing
 * @throws Exception
 */
@Test(timeout=30000)
public void testSkipFlushTableSnapshot() throws Exception {
  Admin admin = UTIL.getHBaseAdmin();
  // make sure we don't fail on listing snapshots
  SnapshotTestingUtils.assertNoSnapshots(admin);

  // put some stuff in the table
  try (Table table = UTIL.getConnection().getTable(TABLE_NAME)) {
    UTIL.loadTable(table, TEST_FAM);
  }

  LOG.debug("FS state before snapshot:");
  UTIL.getHBaseCluster().getMaster().getMasterFileSystem().logFileSystemState(LOG);

  // take a snapshot of the enabled table
  String snapshotString = "skipFlushTableSnapshot";
  byte[] snapshot = Bytes.toBytes(snapshotString);
  admin.snapshot(snapshotString, TABLE_NAME, SnapshotDescription.Type.SKIPFLUSH);
  LOG.debug("Snapshot completed.");

  // make sure we have the snapshot
  List<SnapshotDescription> snapshots = SnapshotTestingUtils.assertOneSnapshotThatMatches(admin,
      snapshot, TABLE_NAME);

  // make sure its a valid snapshot
  LOG.debug("FS state after snapshot:");
  UTIL.getHBaseCluster().getMaster().getMasterFileSystem().logFileSystemState(LOG);

  SnapshotTestingUtils.confirmSnapshotValid(UTIL, snapshots.get(0), TABLE_NAME, TEST_FAM);

  admin.deleteSnapshot(snapshot);
  snapshots = admin.listSnapshots();
  SnapshotTestingUtils.assertNoSnapshots(admin);
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:39,代碼來源:TestFlushSnapshotFromClient.java

示例7: 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


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