Search in sources :

Example 1 with SnapshotDoesNotExistException

use of org.apache.hadoop.hbase.snapshot.SnapshotDoesNotExistException in project hbase by apache.

the class SnapshotManager method deleteSnapshot.

/**
   * Delete the specified snapshot
   * @param snapshot
   * @throws SnapshotDoesNotExistException If the specified snapshot does not exist.
   * @throws IOException For filesystem IOExceptions
   */
public void deleteSnapshot(SnapshotDescription snapshot) throws SnapshotDoesNotExistException, IOException {
    // check to see if it is completed
    if (!isSnapshotCompleted(snapshot)) {
        throw new SnapshotDoesNotExistException(ProtobufUtil.createSnapshotDesc(snapshot));
    }
    String snapshotName = snapshot.getName();
    // first create the snapshot description and check to see if it exists
    FileSystem fs = master.getMasterFileSystem().getFileSystem();
    Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotName, rootDir);
    // Get snapshot info from file system. The one passed as parameter is a "fake" snapshotInfo with
    // just the "name" and it does not contains the "real" snapshot information
    snapshot = SnapshotDescriptionUtils.readSnapshotInfo(fs, snapshotDir);
    // call coproc pre hook
    MasterCoprocessorHost cpHost = master.getMasterCoprocessorHost();
    if (cpHost != null) {
        cpHost.preDeleteSnapshot(snapshot);
    }
    LOG.debug("Deleting snapshot: " + snapshotName);
    // delete the existing snapshot
    if (!fs.delete(snapshotDir, true)) {
        throw new HBaseSnapshotException("Failed to delete snapshot directory: " + snapshotDir);
    }
    // call coproc post hook
    if (cpHost != null) {
        cpHost.postDeleteSnapshot(snapshot);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) MasterCoprocessorHost(org.apache.hadoop.hbase.master.MasterCoprocessorHost) FileSystem(org.apache.hadoop.fs.FileSystem) MasterFileSystem(org.apache.hadoop.hbase.master.MasterFileSystem) HBaseSnapshotException(org.apache.hadoop.hbase.snapshot.HBaseSnapshotException) SnapshotDoesNotExistException(org.apache.hadoop.hbase.snapshot.SnapshotDoesNotExistException)

Example 2 with SnapshotDoesNotExistException

use of org.apache.hadoop.hbase.snapshot.SnapshotDoesNotExistException in project hbase by apache.

the class TestSnapshotFromClient method testListTableSnapshots.

@Test(timeout = 300000)
public void testListTableSnapshots() throws Exception {
    Admin admin = null;
    final TableName tableName = TableName.valueOf(name.getMethodName());
    try {
        admin = UTIL.getAdmin();
        HTableDescriptor htd = new HTableDescriptor(tableName);
        UTIL.createTable(htd, new byte[][] { TEST_FAM }, UTIL.getConfiguration());
        String table1Snapshot1 = "Table1Snapshot1";
        admin.snapshot(table1Snapshot1, TABLE_NAME);
        LOG.debug("Snapshot1 completed.");
        String table1Snapshot2 = "Table1Snapshot2";
        admin.snapshot(table1Snapshot2, TABLE_NAME);
        LOG.debug("Snapshot2 completed.");
        String table2Snapshot1 = "Table2Snapshot1";
        admin.snapshot(Bytes.toBytes(table2Snapshot1), tableName);
        LOG.debug(table2Snapshot1 + " completed.");
        List<SnapshotDescription> listTableSnapshots = admin.listTableSnapshots("test.*", ".*");
        List<String> listTableSnapshotNames = new ArrayList<>();
        assertEquals(3, listTableSnapshots.size());
        for (SnapshotDescription s : listTableSnapshots) {
            listTableSnapshotNames.add(s.getName());
        }
        assertTrue(listTableSnapshotNames.contains(table1Snapshot1));
        assertTrue(listTableSnapshotNames.contains(table1Snapshot2));
        assertTrue(listTableSnapshotNames.contains(table2Snapshot1));
    } finally {
        if (admin != null) {
            try {
                admin.deleteSnapshots("Table.*");
            } catch (SnapshotDoesNotExistException ignore) {
            }
            if (admin.tableExists(tableName)) {
                UTIL.deleteTable(tableName);
            }
            admin.close();
        }
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ArrayList(java.util.ArrayList) SnapshotDoesNotExistException(org.apache.hadoop.hbase.snapshot.SnapshotDoesNotExistException) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) Test(org.junit.Test)

Example 3 with SnapshotDoesNotExistException

use of org.apache.hadoop.hbase.snapshot.SnapshotDoesNotExistException in project hbase by apache.

the class SnapshotManager method restoreOrCloneSnapshot.

/**
   * Restore or Clone the specified snapshot
   * @param reqSnapshot
   * @param nonceKey unique identifier to prevent duplicated RPC
   * @throws IOException
   */
public long restoreOrCloneSnapshot(final SnapshotDescription reqSnapshot, final NonceKey nonceKey) throws IOException {
    FileSystem fs = master.getMasterFileSystem().getFileSystem();
    Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(reqSnapshot, rootDir);
    // check if the snapshot exists
    if (!fs.exists(snapshotDir)) {
        LOG.error("A Snapshot named '" + reqSnapshot.getName() + "' does not exist.");
        throw new SnapshotDoesNotExistException(ProtobufUtil.createSnapshotDesc(reqSnapshot));
    }
    // Get snapshot info from file system. The reqSnapshot is a "fake" snapshotInfo with
    // just the snapshot "name" and table name to restore. It does not contains the "real" snapshot
    // information.
    SnapshotDescription snapshot = SnapshotDescriptionUtils.readSnapshotInfo(fs, snapshotDir);
    SnapshotManifest manifest = SnapshotManifest.open(master.getConfiguration(), fs, snapshotDir, snapshot);
    HTableDescriptor snapshotTableDesc = manifest.getTableDescriptor();
    TableName tableName = TableName.valueOf(reqSnapshot.getTable());
    // stop tracking "abandoned" handlers
    cleanupSentinels();
    // Verify snapshot validity
    SnapshotReferenceUtil.verifySnapshot(master.getConfiguration(), fs, manifest);
    // Execute the restore/clone operation
    long procId;
    if (MetaTableAccessor.tableExists(master.getConnection(), tableName)) {
        procId = restoreSnapshot(reqSnapshot, tableName, snapshot, snapshotTableDesc, nonceKey);
    } else {
        procId = cloneSnapshot(reqSnapshot, tableName, snapshot, snapshotTableDesc, nonceKey);
    }
    return procId;
}
Also used : Path(org.apache.hadoop.fs.Path) SnapshotManifest(org.apache.hadoop.hbase.snapshot.SnapshotManifest) TableName(org.apache.hadoop.hbase.TableName) FileSystem(org.apache.hadoop.fs.FileSystem) MasterFileSystem(org.apache.hadoop.hbase.master.MasterFileSystem) SnapshotDescription(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.SnapshotDescription) SnapshotDoesNotExistException(org.apache.hadoop.hbase.snapshot.SnapshotDoesNotExistException) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Aggregations

SnapshotDoesNotExistException (org.apache.hadoop.hbase.snapshot.SnapshotDoesNotExistException)3 FileSystem (org.apache.hadoop.fs.FileSystem)2 Path (org.apache.hadoop.fs.Path)2 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)2 TableName (org.apache.hadoop.hbase.TableName)2 MasterFileSystem (org.apache.hadoop.hbase.master.MasterFileSystem)2 ArrayList (java.util.ArrayList)1 MasterCoprocessorHost (org.apache.hadoop.hbase.master.MasterCoprocessorHost)1 SnapshotDescription (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.SnapshotDescription)1 HBaseSnapshotException (org.apache.hadoop.hbase.snapshot.HBaseSnapshotException)1 SnapshotManifest (org.apache.hadoop.hbase.snapshot.SnapshotManifest)1 Test (org.junit.Test)1