Java Code Examples for org.apache.hadoop.hbase.client.Admin#listSnapshots()

The following examples show how to use org.apache.hadoop.hbase.client.Admin#listSnapshots() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestCloneSnapshotProcedure.java    From hbase with Apache License 2.0 6 votes vote down vote up
private SnapshotProtos.SnapshotDescription getSnapshot() throws Exception {
  if (snapshot == null) {
    final TableName snapshotTableName = TableName.valueOf("testCloneSnapshot");
    long tid = System.currentTimeMillis();
    final String snapshotName = "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;
}
 
Example 2
Source File: SnapshotTestingUtils.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Make sure that there is only one snapshot returned from the master and its
 * name and table match the passed in parameters.
 */
public static List<SnapshotDescription> assertExistsMatchingSnapshot(
    Admin admin, String snapshotName, TableName tableName)
    throws IOException {
  // list the snapshot
  List<SnapshotDescription> snapshots = admin.listSnapshots();

  List<SnapshotDescription> returnedSnapshots = new ArrayList<>();
  for (SnapshotDescription sd : snapshots) {
    if (snapshotName.equals(sd.getName()) && tableName.equals(sd.getTableName())) {
      returnedSnapshots.add(sd);
    }
  }

  Assert.assertTrue("No matching snapshots found.", returnedSnapshots.size()>0);
  return returnedSnapshots;
}
 
Example 3
Source File: TableSnapshotReadsMapReduceIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
private void upsertAndSnapshot(String tableName, boolean shouldSplit) throws Exception {
  upsertData(tableName);

  TableName hbaseTableName = TableName.valueOf(tableName);
  Connection conn = DriverManager.getConnection(getUrl());
  Admin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin();

  if (shouldSplit) {
    splitTableSync(admin, hbaseTableName, "BBBB".getBytes(), 2);
  }

  admin.snapshot(SNAPSHOT_NAME, hbaseTableName);

  List<SnapshotDescription> snapshots = admin.listSnapshots();
  Assert.assertEquals(tableName, snapshots.get(0).getTable());

  // Capture the snapshot timestamp to use as SCN while reading the table later
  // Assigning the timestamp value here will make tests less flaky
  timestamp = System.currentTimeMillis();

  // upsert data after snapshot
  PreparedStatement stmt = conn.prepareStatement(String.format(UPSERT, tableName));
  upsertData(stmt, "DDDD", "SNFB", 45);
  conn.commit();
}
 
Example 4
Source File: BackupSystemTable.java    From hbase with Apache License 2.0 5 votes vote down vote up
protected static boolean snapshotExists(Admin admin, String snapshotName) throws IOException {
  List<SnapshotDescription> list = admin.listSnapshots();
  for (SnapshotDescription desc : list) {
    if (desc.getName().equals(snapshotName)) {
      return true;
    }
  }
  return false;
}
 
Example 5
Source File: SnapshotQuotaObserverChore.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Computes a mapping of originating {@code TableName} to snapshots, when the {@code TableName}
 * exists in the provided {@code Set}.
 */
Multimap<TableName,String> getSnapshotsFromTables(
    Admin admin, Set<TableName> tablesToFetchSnapshotsFrom) throws IOException {
  Multimap<TableName,String> snapshotsToCompute = HashMultimap.create();
  for (org.apache.hadoop.hbase.client.SnapshotDescription sd : admin.listSnapshots()) {
    TableName tn = sd.getTableName();
    if (tablesToFetchSnapshotsFrom.contains(tn)) {
      snapshotsToCompute.put(tn, sd.getName());
    }
  }
  return snapshotsToCompute;
}
 
Example 6
Source File: SnapshotTestingUtils.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Make sure that there is only one snapshot returned from the master and its
 * name and table match the passed in parameters.
 */
public static List<SnapshotDescription> assertOneSnapshotThatMatches(
    Admin admin, String snapshotName, TableName tableName)
    throws IOException {
  // list the snapshot
  List<SnapshotDescription> snapshots = admin.listSnapshots();

  assertEquals("Should only have 1 snapshot", 1, snapshots.size());
  assertEquals(snapshotName, snapshots.get(0).getName());
  assertEquals(tableName, snapshots.get(0).getTableName());

  return snapshots;
}
 
Example 7
Source File: SnapshotTestingUtils.java    From hbase with Apache License 2.0 5 votes vote down vote up
public static void deleteAllSnapshots(final Admin admin)
    throws IOException {
  // Delete all the snapshots
  for (SnapshotDescription snapshot: admin.listSnapshots()) {
    admin.deleteSnapshot(snapshot.getName());
  }
  SnapshotTestingUtils.assertNoSnapshots(admin);
}
 
Example 8
Source File: TestRestoreSnapshotProcedure.java    From hbase with Apache License 2.0 4 votes vote down vote up
private void setupSnapshotAndUpdateTable() throws Exception {
  long tid = System.currentTimeMillis();
  final String snapshotName = "snapshot-" + tid;
  Admin admin = UTIL.getAdmin();
  // create Table
  SnapshotTestingUtils.createTable(UTIL, snapshotTableName, getNumReplicas(), CF1, CF2);
  // Load data
  SnapshotTestingUtils.loadData(UTIL, snapshotTableName, rowCountCF1, CF1);
  SnapshotTestingUtils.loadData(UTIL, snapshotTableName, rowCountCF2, CF2);
  SnapshotTestingUtils.verifyRowCount(UTIL, snapshotTableName, rowCountCF1 + rowCountCF2);

  snapshotHTD = admin.getDescriptor(snapshotTableName);

  admin.disableTable(snapshotTableName);
  // take a snapshot
  admin.snapshot(snapshotName, snapshotTableName);

  List<SnapshotDescription> snapshotList = admin.listSnapshots();
  snapshot = ProtobufUtil.createHBaseProtosSnapshotDesc(snapshotList.get(0));

  // modify the table
  ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor columnFamilyDescriptor3 =
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(CF3);
  ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor columnFamilyDescriptor4 =
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(CF4);
  admin.addColumnFamily(snapshotTableName, columnFamilyDescriptor3);
  admin.addColumnFamily(snapshotTableName, columnFamilyDescriptor4);
  admin.deleteColumnFamily(snapshotTableName, CF2);
  // enable table and insert data
  admin.enableTable(snapshotTableName);
  SnapshotTestingUtils.loadData(UTIL, snapshotTableName, rowCountCF3, CF3);
  SnapshotTestingUtils.loadData(UTIL, snapshotTableName, rowCountCF4, CF4);
  SnapshotTestingUtils.loadData(UTIL, snapshotTableName, rowCountCF1addition, CF1);
  HTableDescriptor currentHTD = new HTableDescriptor(admin.getDescriptor(snapshotTableName));
  assertTrue(currentHTD.hasFamily(CF1));
  assertFalse(currentHTD.hasFamily(CF2));
  assertTrue(currentHTD.hasFamily(CF3));
  assertTrue(currentHTD.hasFamily(CF4));
  assertNotEquals(currentHTD.getFamiliesKeys().size(), snapshotHTD.getColumnFamilies().length);
  SnapshotTestingUtils.verifyRowCount(
    UTIL, snapshotTableName, rowCountCF1 + rowCountCF3 + rowCountCF4 + rowCountCF1addition);
  admin.disableTable(snapshotTableName);
}
 
Example 9
Source File: TestMasterObserver.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testSnapshotOperations() throws Exception {
  final TableName tableName = TableName.valueOf(name.getMethodName());
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();
  HMaster master = cluster.getMaster();
  MasterCoprocessorHost host = master.getMasterCoprocessorHost();
  CPMasterObserver cp = host.findCoprocessor(CPMasterObserver.class);
  cp.resetStates();

  // create a table
  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(tableName);

  tableDescriptor.setColumnFamily(
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(TEST_FAMILY));
  Admin admin = UTIL.getAdmin();

  tableCreationLatch = new CountDownLatch(1);
  admin.createTable(tableDescriptor);
  tableCreationLatch.await();
  tableCreationLatch = new CountDownLatch(1);

  admin.disableTable(tableName);
  assertTrue(admin.isTableDisabled(tableName));

  try {
    // Test snapshot operation
    assertFalse("Coprocessor should not have been called yet",
      cp.wasSnapshotCalled());
    admin.snapshot(TEST_SNAPSHOT, tableName);
    assertTrue("Coprocessor should have been called on snapshot",
      cp.wasSnapshotCalled());

    //Test list operation
    admin.listSnapshots();
    assertTrue("Coprocessor should have been called on snapshot list",
      cp.wasListSnapshotCalled());

    // Test clone operation
    admin.cloneSnapshot(TEST_SNAPSHOT, TEST_CLONE);
    assertTrue("Coprocessor should have been called on snapshot clone",
      cp.wasCloneSnapshotCalled());
    assertFalse("Coprocessor restore should not have been called on snapshot clone",
      cp.wasRestoreSnapshotCalled());
    admin.disableTable(TEST_CLONE);
    assertTrue(admin.isTableDisabled(tableName));
    deleteTable(admin, TEST_CLONE);

    // Test restore operation
    cp.resetStates();
    admin.restoreSnapshot(TEST_SNAPSHOT);
    assertTrue("Coprocessor should have been called on snapshot restore",
      cp.wasRestoreSnapshotCalled());
    assertFalse("Coprocessor clone should not have been called on snapshot restore",
      cp.wasCloneSnapshotCalled());

    admin.deleteSnapshot(TEST_SNAPSHOT);
    assertTrue("Coprocessor should have been called on snapshot delete",
      cp.wasDeleteSnapshotCalled());
  } finally {
    deleteTable(admin, tableName);
  }
}