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

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

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

Admin.restoreSnapshot介绍

[英]Restore the specified snapshot on the original table. (The table must be disabled) If the "hbase.snapshot.restore.take.failsafe.snapshot" configuration property is set to true, a snapshot of the current table is taken before executing the restore operation. In case of restore failure, the failsafe snapshot will be restored. If the restore completes without problem the failsafe snapshot is deleted.
[中]在原始表上还原指定的快照。(必须禁用该表)如果“hbase.snapshot.restore.take.failsafe.snapshot”配置属性设置为true,则在执行还原操作之前将获取当前表的快照。如果恢复失败,将恢复故障保护快照。如果恢复顺利完成,则会删除故障保护快照。

代码示例

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

public static void restoreFromSnapshot(Connection conn) throws IOException {
 Configuration conf = conn.getConfiguration();
 LOG.debug("Restoring " + BackupSystemTable.getTableNameAsString(conf) + " from snapshot");
 try (Admin admin = conn.getAdmin()) {
  String snapshotName = BackupSystemTable.getSnapshotName(conf);
  if (snapshotExists(admin, snapshotName)) {
   admin.disableTable(BackupSystemTable.getTableName(conf));
   admin.restoreSnapshot(snapshotName);
   admin.enableTable(BackupSystemTable.getTableName(conf));
   LOG.debug("Done restoring backup system table");
  } else {
   // Snapshot does not exists, i.e completeBackup failed after
   // deleting backup system table snapshot
   // In this case we log WARN and proceed
   LOG.warn(
    "Could not restore backup system table. Snapshot " + snapshotName + " does not exists.");
  }
 }
}

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

@Test
public void testRestoreSnapshot() throws IOException {
 verifyRowCount(UTIL, tableName, snapshot1Rows);
 // Restore from snapshot-0
 admin.disableTable(tableName);
 admin.restoreSnapshot(snapshotName0);
 logFSTree();
 admin.enableTable(tableName);
 LOG.info("=== after restore with 500 row snapshot");
 logFSTree();
 verifyRowCount(UTIL, tableName, snapshot0Rows);
 // Restore from snapshot-1
 admin.disableTable(tableName);
 admin.restoreSnapshot(snapshotName1);
 admin.enableTable(tableName);
 verifyRowCount(UTIL, tableName, snapshot1Rows);
}

代码示例来源: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
public void testRestoreSnapshot() throws Exception {
 String nsp = prefix + "_testRestoreSnapshot";
 NamespaceDescriptor nspDesc =
   NamespaceDescriptor.create(nsp)
     .addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "10").build();
 ADMIN.createNamespace(nspDesc);
 assertNotNull("Namespace descriptor found null.", ADMIN.getNamespaceDescriptor(nsp));
 TableName tableName1 = TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table1");
 HTableDescriptor tableDescOne = new HTableDescriptor(tableName1);
 HColumnDescriptor fam1 = new HColumnDescriptor("fam1");
 tableDescOne.addFamily(fam1);
 ADMIN.createTable(tableDescOne, Bytes.toBytes("AAA"), Bytes.toBytes("ZZZ"), 4);
 NamespaceTableAndRegionInfo nstate = getNamespaceState(nsp);
 assertEquals("Intial region count should be 4.", 4, nstate.getRegionCount());
 String snapshot = "snapshot_testRestoreSnapshot";
 ADMIN.snapshot(snapshot, tableName1);
 List<HRegionInfo> regions = ADMIN.getTableRegions(tableName1);
 Collections.sort(regions);
 ADMIN.split(tableName1, Bytes.toBytes("JJJ"));
 Thread.sleep(2000);
 assertEquals("Total regions count should be 5.", 5, nstate.getRegionCount());
 ADMIN.disableTable(tableName1);
 ADMIN.restoreSnapshot(snapshot);
 assertEquals("Total regions count should be 4 after restore.", 4, nstate.getRegionCount());
 ADMIN.enableTable(tableName1);
 ADMIN.deleteSnapshot(snapshot);
}

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

@Test
public void testRestoreSnapshot() throws IOException {
 verifyRowCount(TEST_UTIL, tableName, snapshot1Rows);
 admin.disableTable(tableName);
 admin.snapshot(snapshotName1, tableName);
 // Restore from snapshot-0
 admin.restoreSnapshot(snapshotName0);
 admin.enableTable(tableName);
 verifyRowCount(TEST_UTIL, tableName, snapshot0Rows);
 SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());
 // Restore from emptySnapshot
 admin.disableTable(tableName);
 admin.restoreSnapshot(emptySnapshot);
 admin.enableTable(tableName);
 verifyRowCount(TEST_UTIL, tableName, 0);
 SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());
 // Restore from snapshot-1
 admin.disableTable(tableName);
 admin.restoreSnapshot(snapshotName1);
 admin.enableTable(tableName);
 verifyRowCount(TEST_UTIL, tableName, snapshot1Rows);
 SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());
 // Restore from snapshot-1
 TEST_UTIL.deleteTable(tableName);
 admin.restoreSnapshot(snapshotName1);
 verifyRowCount(TEST_UTIL, tableName, snapshot1Rows);
 SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());
}

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

admin.restoreSnapshot(snapshotName);
admin.enableTable(originalTableName);

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

admin.restoreSnapshot(snapshotName0);
admin.enableTable(tableName);
SnapshotTestingUtils.verifyRowCount(UTIL, tableName, snapshot0Rows);
admin.restoreSnapshot(emptySnapshot);
admin.enableTable(tableName);
SnapshotTestingUtils.verifyRowCount(UTIL, tableName, 0);
admin.restoreSnapshot(snapshotName1);
admin.enableTable(tableName);
SnapshotTestingUtils.verifyRowCount(UTIL, tableName, snapshot1Rows);
admin.restoreSnapshot(snapshotName1);
SnapshotTestingUtils.verifyRowCount(UTIL, tableName, snapshot1Rows);
SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());

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

admin.restoreSnapshot(snapshotName);
admin.enableTable(BackupSystemTable.getTableName(conf1));

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

admin.restoreSnapshot(snapshotName0);
admin.enableTable(tableName);
SnapshotTestingUtils.verifyRowCount(UTIL, tableName, snapshot0Rows);
admin.restoreSnapshot(emptySnapshot);
admin.enableTable(tableName);
SnapshotTestingUtils.verifyRowCount(UTIL, tableName, 0);
admin.restoreSnapshot(snapshotName1);
admin.enableTable(tableName);
SnapshotTestingUtils.verifyRowCount(UTIL, tableName, snapshot1Rows);
admin.restoreSnapshot(snapshotName1);
SnapshotTestingUtils.verifyRowCount(UTIL, tableName, snapshot1Rows);
SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());

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

ADMIN.restoreSnapshot(snapshot);
fail("Region quota is exceeded so QuotaExceededException should be thrown but HBaseAdmin"
  + " wraps IOException into RestoreSnapshotException");

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

@Test
public void testCloneAndRestoreSnapshot() throws IOException, InterruptedException {
 TEST_UTIL.deleteTable(tableName);
 waitCleanerRun();
 admin.cloneSnapshot(snapshotName0, tableName);
 verifyRowCount(TEST_UTIL, tableName, snapshot0Rows);
 SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());
 waitCleanerRun();
 admin.disableTable(tableName);
 admin.restoreSnapshot(snapshotName0);
 admin.enableTable(tableName);
 verifyRowCount(TEST_UTIL, tableName, snapshot0Rows);
 SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());
}

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

@Test
 public void testRestoreSnapshotAfterTruncate() throws Exception {
  TableName tableName = TableName.valueOf(getValidMethodName());
  SnapshotTestingUtils.createTable(TEST_UTIL, tableName, getNumReplicas(), FAMILY);
  SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 500, FAMILY);
  int numOfRows = 0;

  try (Table table = TEST_UTIL.getConnection().getTable(tableName)) {
   numOfRows = countRows(table);
  }
  // take snapshot
  admin.snapshot("snap", tableName);
  admin.disableTable(tableName);
  admin.truncateTable(tableName, false);
  admin.disableTable(tableName);
  admin.restoreSnapshot("snap");

  admin.enableTable(tableName);
  verifyRowCount(TEST_UTIL, tableName, numOfRows);
  SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());
 }
}

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

admin.restoreSnapshot(TEST_SNAPSHOT);
assertTrue("Coprocessor should have been called on snapshot restore",
 cp.wasRestoreSnapshotCalled());

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

admin.restoreSnapshot(snapshotName0);
admin.enableTable(tableName);
assertEquals(1, table.getDescriptor().getColumnFamilyCount());
admin.restoreSnapshot(snapshotName2);
admin.enableTable(tableName);
htd = admin.getDescriptor(tableName);

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

admin.disableTable(TableName.valueOf(tableName));
tableDisabled = true;
admin.restoreSnapshot(snapshotName);
snapshotRestored = true;
logger.warn("Successfully restored " + tableName + " using snapshot "

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

if (!success && restoreSnapshot) {
  admin.disableTable(physicalName);
  admin.restoreSnapshot(snapshotName, false);
  admin.enableTable(physicalName);
  String msg = "Restored snapshot of " + physicalName + " due to failure of upgrade";

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

admin.restoreSnapshot(snapshotName1);
admin.enableTable(tableName);

代码示例来源:origin: larsgeorge/hbase-book

admin.restoreSnapshot("snapshot1"); // co SnapshotExample-5-Restore Restore the first snapshot, recreating the initial table. This needs to be done on a disabled table.
admin.enableTable(tableName);

代码示例来源:origin: org.apache.hbase/hbase-server

@Test
public void testCloneAndRestoreSnapshot() throws IOException, InterruptedException {
 TEST_UTIL.deleteTable(tableName);
 waitCleanerRun();
 admin.cloneSnapshot(snapshotName0, tableName);
 verifyRowCount(TEST_UTIL, tableName, snapshot0Rows);
 SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());
 waitCleanerRun();
 admin.disableTable(tableName);
 admin.restoreSnapshot(snapshotName0);
 admin.enableTable(tableName);
 verifyRowCount(TEST_UTIL, tableName, snapshot0Rows);
 SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());
}

相关文章

Admin类方法