org.apache.hadoop.hbase.client.Admin.snapshot()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(11.3k)|赞(0)|评价(0)|浏览(128)

本文整理了Java中org.apache.hadoop.hbase.client.Admin.snapshot()方法的一些代码示例,展示了Admin.snapshot()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Admin.snapshot()方法的具体详情如下:
包路径:org.apache.hadoop.hbase.client.Admin
类名称:Admin
方法名:snapshot

Admin.snapshot介绍

[英]Take a snapshot for the given table. If the table is enabled, a FLUSH-type snapshot will be taken. If the table is disabled, an offline snapshot is taken. Snapshots are considered unique based on the name of the snapshot. Attempts to take a snapshot with the same name (even a different type or with different parameters) will fail with a org.apache.hadoop.hbase.snapshot.SnapshotCreationException indicating the duplicate naming. Snapshot names follow the same naming constraints as tables in HBase. See org.apache.hadoop.hbase.TableName#isLegalFullyQualifiedTableName(byte[]).
[中]为给定表拍摄快照。如果该表已启用,则将拍摄刷新类型快照。如果该表被禁用,则会拍摄脱机快照。根据快照的名称,快照被认为是唯一的。尝试使用相同名称(即使是不同类型或不同参数)拍摄快照将因组织而失败。阿帕奇。hadoop。hbase。快照指示重复命名的SnapshotCreationException。快照名称遵循与HBase中的表相同的命名约束。见组织。阿帕奇。hadoop。hbase。TableName#isLegalFullyQualifiedTableName(字节[])。

代码示例

代码示例来源:origin: apache/hbase

public static void snapshot(Admin admin, final String snapshotName, final TableName tableName,
  final SnapshotType type, final int numTries) throws IOException {
 int tries = 0;
 CorruptedSnapshotException lastEx = null;
 while (tries++ < numTries) {
  try {
   admin.snapshot(snapshotName, tableName, type);
   return;
  } catch (CorruptedSnapshotException cse) {
   LOG.warn("Got CorruptedSnapshotException", cse);
   lastEx = cse;
  }
 }
 throw lastEx;
}

代码示例来源:origin: apache/hbase

private void failSnapshotStart(Admin admin, SnapshotDescription snapshot)
  throws IOException {
 try {
  admin.snapshot(snapshot);
  fail("Snapshot should not have succeed with name:" + snapshot.getName());
 } catch (IllegalArgumentException e) {
  LOG.debug("Correctly failed to start snapshot:" + e.getMessage());
 }
}

代码示例来源:origin: apache/hbase

public static void snapshot(Connection conn) throws IOException {
 try (Admin admin = conn.getAdmin()) {
  Configuration conf = conn.getConfiguration();
  admin.snapshot(BackupSystemTable.getSnapshotName(conf), BackupSystemTable.getTableName(conf));
 }
}

代码示例来源:origin: apache/hbase

public void snapshotAndAssertOneRetry(final String snapshotName, final TableName tableName)
  throws Exception {
 MasterSyncObserver observer = getMasterSyncObserver();
 observer.snapshotCount = new AtomicInteger(0);
 TEST_UTIL.getAdmin().snapshot(snapshotName, tableName);
 assertEquals(1, observer.snapshotCount.get());
}

代码示例来源:origin: apache/hbase

private void takeSnapshot(TableName tableName, String snapshotName, boolean disabled)
   throws IOException {
  SnapshotType type = disabled ? SnapshotType.DISABLED : SnapshotType.FLUSH;
  SnapshotDescription desc =
    new SnapshotDescription(snapshotName, tableName.getNameAsString(), type, null, -1,
      manifestVersion);
  admin.snapshot(desc);
 }
}

代码示例来源:origin: apache/hbase

@Override
 public void perform() throws Exception {
  HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
  String snapshotName = tableName + "-it-" + System.currentTimeMillis();
  Admin admin = util.getAdmin();

  // 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);
  }
 }
}

代码示例来源:origin: apache/hbase

protected void createTableAndSnapshot(TableName tableName, String snapshotName)
  throws IOException {
 byte[] column = Bytes.toBytes("A");
 Table table = TEST_UTIL.createTable(tableName, column, 2);
 TEST_UTIL.loadTable(table, column);
 TEST_UTIL.getAdmin().snapshot(snapshotName, tableName);
}

代码示例来源:origin: apache/hbase

@Override
 protected void createTableAndSnapshot(TableName tableName, String snapshotName)
   throws IOException {
  byte[] column = Bytes.toBytes("A");
  Table table = MobSnapshotTestingUtils.createMobTable(TEST_UTIL, tableName, column);
  TEST_UTIL.loadTable(table, column);
  TEST_UTIL.getAdmin().snapshot(snapshotName, tableName);
 }
}

代码示例来源:origin: apache/hbase

/**
 * Test snapshotting not allowed hbase:meta and -ROOT-
 * @throws Exception
 */
@Test
public void testMetaTablesSnapshot() throws Exception {
 Admin admin = UTIL.getAdmin();
 byte[] snapshotName = Bytes.toBytes("metaSnapshot");
 try {
  admin.snapshot(snapshotName, TableName.META_TABLE_NAME);
  fail("taking a snapshot of hbase:meta should not be allowed");
 } catch (IllegalArgumentException e) {
  // expected
 }
}

代码示例来源:origin: apache/hbase

@Test
public void testCloneSnapshot() throws Exception {
 byte[] FAMILY = Bytes.toBytes("test");
 String snapshotName = tableName.getNameAsString() + "_snap";
 TableName clonedTableName = TableName.valueOf(tableName.getNameAsString() + "_clone");
 // create base table
 TEST_UTIL.createTable(tableName, FAMILY);
 // create snapshot
 admin.snapshot(snapshotName, tableName);
 // clone
 admin.cloneSnapshot(snapshotName, clonedTableName);
}

代码示例来源:origin: apache/hbase

@Test
public void testRestoreSnapshotOfCloned() throws IOException, InterruptedException {
 TableName clonedTableName = TableName.valueOf("clonedtb-" + System.currentTimeMillis());
 admin.cloneSnapshot(snapshotName0, clonedTableName);
 verifyRowCount(UTIL, clonedTableName, snapshot0Rows);
 admin.snapshot(Bytes.toString(snapshotName2), clonedTableName, SnapshotType.FLUSH);
 UTIL.deleteTable(clonedTableName);
 admin.cloneSnapshot(snapshotName2, clonedTableName);
 verifyRowCount(UTIL, clonedTableName, snapshot0Rows);
 UTIL.deleteTable(clonedTableName);
}

代码示例来源:origin: apache/hbase

/**
 * Create a table and take a snapshot of the table used by the export test.
 */
@Before
public void setUp() throws Exception {
 this.admin = TEST_UTIL.getAdmin();
 tableName = TableName.valueOf("testtb-" + testName.getMethodName());
 snapshotName = Bytes.toBytes("snaptb0-" + testName.getMethodName());
 emptySnapshotName = Bytes.toBytes("emptySnaptb0-" + testName.getMethodName());
 // create Table
 createTable();
 // Take an empty snapshot
 admin.snapshot(emptySnapshotName, tableName);
 // Add some rows
 SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 50, FAMILY);
 tableNumFiles = admin.getTableRegions(tableName).size();
 // take a snapshot
 admin.snapshot(snapshotName, tableName);
}

代码示例来源:origin: apache/hbase

@Test
 public void testOnlineSnapshotAfterSplittingRegions() throws IOException, InterruptedException {
  List<RegionInfo> regionInfos = admin.getRegions(tableName);
  RegionReplicaUtil.removeNonDefaultRegions(regionInfos);

  // Split a region
  splitRegion(regionInfos.get(0));

  // Take a online snapshot
  admin.snapshot(snapshotName1, tableName);

  // Clone the snapshot to another table
  TableName clonedTableName =
   TableName.valueOf(name.getMethodName() + "-" + System.currentTimeMillis());
  admin.cloneSnapshot(snapshotName1, clonedTableName);

  verifyRowCount(TEST_UTIL, clonedTableName, snapshot1Rows);
 }
}

代码示例来源:origin: apache/hbase

private SnapshotProtos.SnapshotDescription getSnapshot() throws Exception {
 if (snapshot == null) {
  final TableName snapshotTableName = TableName.valueOf("testCloneSnapshot");
  long tid = System.currentTimeMillis();
  final byte[] snapshotName = Bytes.toBytes("snapshot-" + tid);
  Admin admin = UTIL.getAdmin();
  // create Table
  SnapshotTestingUtils.createTable(UTIL, snapshotTableName, getNumReplicas(), CF);
  // Load data
  SnapshotTestingUtils.loadData(UTIL, snapshotTableName, 500, CF);
  admin.disableTable(snapshotTableName);
  // take a snapshot
  admin.snapshot(snapshotName, snapshotTableName);
  admin.enableTable(snapshotTableName);
  List<SnapshotDescription> snapshotList = admin.listSnapshots();
  snapshot = ProtobufUtil.createHBaseProtosSnapshotDesc(snapshotList.get(0));
 }
 return snapshot;
}

代码示例来源:origin: apache/hbase

private void testCopyTableBySnapshot(String tablePrefix, boolean bulkLoad, boolean isMob)
  throws Exception {
 TableName table1 = TableName.valueOf(tablePrefix + 1);
 TableName table2 = TableName.valueOf(tablePrefix + 2);
 Table t1 = createTable(table1, FAMILY_A, isMob);
 Table t2 = createTable(table2, FAMILY_A, isMob);
 loadData(t1, FAMILY_A, Bytes.toBytes("qualifier"));
 String snapshot = tablePrefix + "_snapshot";
 TEST_UTIL.getAdmin().snapshot(snapshot, table1);
 boolean success;
 if (bulkLoad) {
  success =
    runCopy(new String[] { "--snapshot", "--new.name=" + table2, "--bulkload", snapshot });
 } else {
  success = runCopy(new String[] { "--snapshot", "--new.name=" + table2, snapshot });
 }
 Assert.assertTrue(success);
 verifyRows(t2, FAMILY_A, Bytes.toBytes("qualifier"));
}

代码示例来源:origin: apache/hbase

@Test(expected = QuotaExceededException.class)
public void testCloneSnapshotQuotaExceed() throws Exception {
 String nsp = prefix + "_testTableQuotaExceedWithCloneSnapshot";
 NamespaceDescriptor nspDesc =
   NamespaceDescriptor.create(nsp).addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "1")
     .build();
 ADMIN.createNamespace(nspDesc);
 assertNotNull("Namespace descriptor found null.", ADMIN.getNamespaceDescriptor(nsp));
 TableName tableName = TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table1");
 TableName cloneTableName = TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table2");
 HColumnDescriptor fam1 = new HColumnDescriptor("fam1");
 HTableDescriptor tableDescOne = new HTableDescriptor(tableName);
 tableDescOne.addFamily(fam1);
 ADMIN.createTable(tableDescOne);
 String snapshot = "snapshot_testTableQuotaExceedWithCloneSnapshot";
 ADMIN.snapshot(snapshot, tableName);
 ADMIN.cloneSnapshot(snapshot, cloneTableName);
 ADMIN.deleteSnapshot(snapshot);
}

代码示例来源:origin: apache/hbase

@Test
 public void testGetCompactionStateAfterRestoringSnapshot()
   throws IOException, InterruptedException {
  // Take a snapshot
  admin.snapshot(snapshotName1, tableName);

  // Restore the snapshot
  admin.disableTable(tableName);
  admin.restoreSnapshot(snapshotName1);

  // Get the compaction state of the restored table
  CompactionState compactionState = admin.getCompactionState(tableName);

  // The compactionState should be NONE because the table is disabled
  assertEquals(CompactionState.NONE, compactionState);
 }
}

代码示例来源:origin: apache/hbase

@Test
 public void testRestoreSnapshotAfterSplittingRegions() throws IOException, InterruptedException {
  List<RegionInfo> regionInfos = admin.getRegions(tableName);
  RegionReplicaUtil.removeNonDefaultRegions(regionInfos);

  // Split the first region
  splitRegion(regionInfos.get(0));

  // Take a snapshot
  admin.snapshot(snapshotName1, tableName);

  // Load more data
  SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 500, FAMILY);

  // Split the second region
  splitRegion(regionInfos.get(1));

  // Restore the snapshot
  admin.disableTable(tableName);
  admin.restoreSnapshot(snapshotName1);
  admin.enableTable(tableName);

  verifyRowCount(TEST_UTIL, tableName, snapshot1Rows);
 }
}

代码示例来源:origin: apache/hbase

@Test(expected=SnapshotExistsException.class)
public void testSnapshotAlreadyExist() throws Exception {
 final String snapshotName = "testSnapshotAlreadyExist";
 TEST_UTIL.createTable(TEST_TABLE.getTableName(), "f");
 TEST_UTIL.getAdmin().snapshot(snapshotName, TEST_TABLE.getTableName());
 snapshotAndAssertOneRetry(snapshotName, TEST_TABLE.getTableName());
}

代码示例来源:origin: apache/hbase

@Test
public void testCloneSnapshotOfCloned() throws IOException, InterruptedException {
 TableName clonedTableName =
  TableName.valueOf(getValidMethodName() + "-" + System.currentTimeMillis());
 admin.cloneSnapshot(snapshotName0, clonedTableName);
 verifyRowCount(TEST_UTIL, clonedTableName, snapshot0Rows);
 SnapshotTestingUtils.verifyReplicasCameOnline(clonedTableName, admin, getNumReplicas());
 admin.disableTable(clonedTableName);
 admin.snapshot(snapshotName2, clonedTableName);
 TEST_UTIL.deleteTable(clonedTableName);
 waitCleanerRun();
 admin.cloneSnapshot(snapshotName2, clonedTableName);
 verifyRowCount(TEST_UTIL, clonedTableName, snapshot0Rows);
 SnapshotTestingUtils.verifyReplicasCameOnline(clonedTableName, admin, getNumReplicas());
 TEST_UTIL.deleteTable(clonedTableName);
}

相关文章

Admin类方法