Search in sources :

Example 6 with SnapshotDescription

use of org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription in project hbase by apache.

the class SnapshotManager method toSnapshotDescription.

private SnapshotDescription toSnapshotDescription(ProcedureDescription desc) throws IOException {
    SnapshotDescription.Builder builder = SnapshotDescription.newBuilder();
    if (!desc.hasInstance()) {
        throw new IOException("Snapshot name is not defined: " + desc.toString());
    }
    String snapshotName = desc.getInstance();
    List<NameStringPair> props = desc.getConfigurationList();
    String table = null;
    for (NameStringPair prop : props) {
        if ("table".equalsIgnoreCase(prop.getName())) {
            table = prop.getValue();
        }
    }
    if (table == null) {
        throw new IOException("Snapshot table is not defined: " + desc.toString());
    }
    TableName tableName = TableName.valueOf(table);
    builder.setTable(tableName.getNameAsString());
    builder.setName(snapshotName);
    builder.setType(SnapshotDescription.Type.FLUSH);
    return builder.build();
}
Also used : TableName(org.apache.hadoop.hbase.TableName) NameStringPair(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.NameStringPair) SnapshotDescription(org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription) IOException(java.io.IOException)

Example 7 with SnapshotDescription

use of org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription in project hbase by apache.

the class SnapshotManager method getCompletedSnapshots.

/**
 * Gets the list of all completed snapshots.
 * @param snapshotDir snapshot directory
 * @param withCpCall Whether to call CP hooks
 * @return list of SnapshotDescriptions
 * @throws IOException File system exception
 */
private List<SnapshotDescription> getCompletedSnapshots(Path snapshotDir, boolean withCpCall) throws IOException {
    List<SnapshotDescription> snapshotDescs = new ArrayList<>();
    // first create the snapshot root path and check to see if it exists
    FileSystem fs = master.getMasterFileSystem().getFileSystem();
    if (snapshotDir == null)
        snapshotDir = SnapshotDescriptionUtils.getSnapshotsDir(rootDir);
    // if there are no snapshots, return an empty list
    if (!fs.exists(snapshotDir)) {
        return snapshotDescs;
    }
    // ignore all the snapshots in progress
    FileStatus[] snapshots = fs.listStatus(snapshotDir, new SnapshotDescriptionUtils.CompletedSnaphotDirectoriesFilter(fs));
    MasterCoprocessorHost cpHost = master.getMasterCoprocessorHost();
    withCpCall = withCpCall && cpHost != null;
    // loop through all the completed snapshots
    for (FileStatus snapshot : snapshots) {
        Path info = new Path(snapshot.getPath(), SnapshotDescriptionUtils.SNAPSHOTINFO_FILE);
        // if the snapshot is bad
        if (!fs.exists(info)) {
            LOG.error("Snapshot information for " + snapshot.getPath() + " doesn't exist");
            continue;
        }
        FSDataInputStream in = null;
        try {
            in = fs.open(info);
            SnapshotDescription desc = SnapshotDescription.parseFrom(in);
            org.apache.hadoop.hbase.client.SnapshotDescription descPOJO = (withCpCall) ? ProtobufUtil.createSnapshotDesc(desc) : null;
            if (withCpCall) {
                try {
                    cpHost.preListSnapshot(descPOJO);
                } catch (AccessDeniedException e) {
                    LOG.warn("Current user does not have access to " + desc.getName() + " snapshot. " + "Either you should be owner of this snapshot or admin user.");
                    // Skip this and try for next snapshot
                    continue;
                }
            }
            snapshotDescs.add(desc);
            // call coproc post hook
            if (withCpCall) {
                cpHost.postListSnapshot(descPOJO);
            }
        } catch (IOException e) {
            LOG.warn("Found a corrupted snapshot " + snapshot.getPath(), e);
        } finally {
            if (in != null) {
                in.close();
            }
        }
    }
    return snapshotDescs;
}
Also used : Path(org.apache.hadoop.fs.Path) MasterCoprocessorHost(org.apache.hadoop.hbase.master.MasterCoprocessorHost) AccessDeniedException(org.apache.hadoop.hbase.security.AccessDeniedException) FileStatus(org.apache.hadoop.fs.FileStatus) ClientSnapshotDescriptionUtils(org.apache.hadoop.hbase.snapshot.ClientSnapshotDescriptionUtils) SnapshotDescriptionUtils(org.apache.hadoop.hbase.snapshot.SnapshotDescriptionUtils) ArrayList(java.util.ArrayList) SnapshotDescription(org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription) IOException(java.io.IOException) FileSystem(org.apache.hadoop.fs.FileSystem) MasterFileSystem(org.apache.hadoop.hbase.master.MasterFileSystem) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream)

Example 8 with SnapshotDescription

use of org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription 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, final boolean restoreAcl, String customSFT) 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);
    TableDescriptor snapshotTableDesc = manifest.getTableDescriptor();
    TableName tableName = TableName.valueOf(reqSnapshot.getTable());
    // sanity check the new table descriptor
    TableDescriptorChecker.sanityCheck(master.getConfiguration(), snapshotTableDesc);
    // stop tracking "abandoned" handlers
    cleanupSentinels();
    // Verify snapshot validity
    SnapshotReferenceUtil.verifySnapshot(master.getConfiguration(), fs, manifest);
    // Execute the restore/clone operation
    long procId;
    if (master.getTableDescriptors().exists(tableName)) {
        procId = restoreSnapshot(reqSnapshot, tableName, snapshot, snapshotTableDesc, nonceKey, restoreAcl);
    } else {
        procId = cloneSnapshot(reqSnapshot, tableName, snapshot, snapshotTableDesc, nonceKey, restoreAcl, customSFT);
    }
    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.SnapshotProtos.SnapshotDescription) SnapshotDoesNotExistException(org.apache.hadoop.hbase.snapshot.SnapshotDoesNotExistException) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor)

Example 9 with SnapshotDescription

use of org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription in project hbase by apache.

the class TestRestoreSnapshotHelper method restoreAndVerify.

private void restoreAndVerify(final String snapshotName, final String tableName) throws IOException {
    // Test Rolling-Upgrade like Snapshot.
    // half machines writing using v1 and the others using v2 format.
    SnapshotMock snapshotMock = createSnapshotMock();
    SnapshotMock.SnapshotBuilder builder = snapshotMock.createSnapshotV2("snapshot", tableName);
    builder.addRegionV1();
    builder.addRegionV2();
    builder.addRegionV2();
    builder.addRegionV1();
    Path snapshotDir = builder.commit();
    TableDescriptor htd = builder.getTableDescriptor();
    SnapshotDescription desc = builder.getSnapshotDescription();
    // Test clone a snapshot
    TableDescriptor htdClone = snapshotMock.createHtd("testtb-clone");
    testRestore(snapshotDir, desc, htdClone);
    verifyRestore(rootDir, htd, htdClone);
    // Test clone a clone ("link to link")
    SnapshotDescription cloneDesc = SnapshotDescription.newBuilder().setName("cloneSnapshot").setTable("testtb-clone").build();
    Path cloneDir = CommonFSUtils.getTableDir(rootDir, htdClone.getTableName());
    TableDescriptor htdClone2 = snapshotMock.createHtd("testtb-clone2");
    testRestore(cloneDir, cloneDesc, htdClone2);
    verifyRestore(rootDir, htd, htdClone2);
}
Also used : Path(org.apache.hadoop.fs.Path) SnapshotDescription(org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription) SnapshotMock(org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils.SnapshotMock) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor)

Example 10 with SnapshotDescription

use of org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription in project hbase by apache.

the class TestSnapshotDescriptionUtils method testCompleteSnapshotWithNoSnapshotDirectoryFailure.

/**
 * Test that we throw an exception if there is no working snapshot directory when we attempt to
 * 'complete' the snapshot
 * @throws Exception on failure
 */
@Test
public void testCompleteSnapshotWithNoSnapshotDirectoryFailure() throws Exception {
    Path snapshotDir = new Path(root, HConstants.SNAPSHOT_DIR_NAME);
    Path tmpDir = new Path(snapshotDir, ".tmp");
    Path workingDir = new Path(tmpDir, "not_a_snapshot");
    Configuration conf = new Configuration();
    FileSystem workingFs = workingDir.getFileSystem(conf);
    assertFalse("Already have working snapshot dir: " + workingDir + " but shouldn't. Test file leak?", fs.exists(workingDir));
    SnapshotDescription snapshot = SnapshotDescription.newBuilder().setName("snapshot").build();
    Path finishedDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshot, snapshotDir);
    try {
        SnapshotDescriptionUtils.completeSnapshot(finishedDir, workingDir, fs, workingFs, conf);
        fail("Shouldn't successfully complete move of a non-existent directory.");
    } catch (IOException e) {
        LOG.info("Correctly failed to move non-existant directory: " + e.getMessage());
    }
}
Also used : Path(org.apache.hadoop.fs.Path) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) Configuration(org.apache.hadoop.conf.Configuration) FileSystem(org.apache.hadoop.fs.FileSystem) SnapshotDescription(org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

SnapshotDescription (org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription)26 Path (org.apache.hadoop.fs.Path)16 IOException (java.io.IOException)12 FileSystem (org.apache.hadoop.fs.FileSystem)6 SnapshotRegionManifest (org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotRegionManifest)6 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)5 SnapshotManifest (org.apache.hadoop.hbase.snapshot.SnapshotManifest)5 Test (org.junit.Test)5 FileNotFoundException (java.io.FileNotFoundException)4 ArrayList (java.util.ArrayList)4 TableName (org.apache.hadoop.hbase.TableName)4 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)4 HashSet (java.util.HashSet)3 Configuration (org.apache.hadoop.conf.Configuration)3 FileStatus (org.apache.hadoop.fs.FileStatus)3 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)3 MasterFileSystem (org.apache.hadoop.hbase.master.MasterFileSystem)3 InterruptedIOException (java.io.InterruptedIOException)2 ExecutionException (java.util.concurrent.ExecutionException)2 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)2