Search in sources :

Example 1 with SnapshotDescription

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

the class MasterRpcServices method getCompletedSnapshots.

/**
   * List the currently available/stored snapshots. Any in-progress snapshots are ignored
   */
@Override
public GetCompletedSnapshotsResponse getCompletedSnapshots(RpcController controller, GetCompletedSnapshotsRequest request) throws ServiceException {
    try {
        master.checkInitialized();
        GetCompletedSnapshotsResponse.Builder builder = GetCompletedSnapshotsResponse.newBuilder();
        List<SnapshotDescription> snapshots = master.snapshotManager.getCompletedSnapshots();
        // convert to protobuf
        for (SnapshotDescription snapshot : snapshots) {
            builder.addSnapshots(snapshot);
        }
        return builder.build();
    } catch (IOException e) {
        throw new ServiceException(e);
    }
}
Also used : GetCompletedSnapshotsResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetCompletedSnapshotsResponse) ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) SnapshotDescription(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.SnapshotDescription) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException)

Example 2 with SnapshotDescription

use of org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.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.HBaseProtos.SnapshotDescription) IOException(java.io.IOException)

Example 3 with SnapshotDescription

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

the class ExportSnapshot method verifySnapshot.

private void verifySnapshot(final Configuration baseConf, final FileSystem fs, final Path rootDir, final Path snapshotDir) throws IOException {
    // Update the conf with the current root dir, since may be a different cluster
    Configuration conf = new Configuration(baseConf);
    FSUtils.setRootDir(conf, rootDir);
    FSUtils.setFsDefault(conf, FSUtils.getRootDir(conf));
    SnapshotDescription snapshotDesc = SnapshotDescriptionUtils.readSnapshotInfo(fs, snapshotDir);
    SnapshotReferenceUtil.verifySnapshot(conf, fs, snapshotDir, snapshotDesc);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) SnapshotDescription(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.SnapshotDescription)

Example 4 with SnapshotDescription

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

the class ExportSnapshot method getSnapshotFiles.

// ==========================================================================
//  Input Format
// ==========================================================================
/**
   * Extract the list of files (HFiles/WALs) to copy using Map-Reduce.
   * @return list of files referenced by the snapshot (pair of path and size)
   */
private static List<Pair<SnapshotFileInfo, Long>> getSnapshotFiles(final Configuration conf, final FileSystem fs, final Path snapshotDir) throws IOException {
    SnapshotDescription snapshotDesc = SnapshotDescriptionUtils.readSnapshotInfo(fs, snapshotDir);
    final List<Pair<SnapshotFileInfo, Long>> files = new ArrayList<>();
    final TableName table = TableName.valueOf(snapshotDesc.getTable());
    // Get snapshot files
    LOG.info("Loading Snapshot '" + snapshotDesc.getName() + "' hfile list");
    SnapshotReferenceUtil.visitReferencedFiles(conf, fs, snapshotDir, snapshotDesc, new SnapshotReferenceUtil.SnapshotVisitor() {

        @Override
        public void storeFile(final HRegionInfo regionInfo, final String family, final SnapshotRegionManifest.StoreFile storeFile) throws IOException {
            // for storeFile.hasReference() case, copied as part of the manifest
            if (!storeFile.hasReference()) {
                String region = regionInfo.getEncodedName();
                String hfile = storeFile.getName();
                Path path = HFileLink.createPath(table, region, family, hfile);
                SnapshotFileInfo fileInfo = SnapshotFileInfo.newBuilder().setType(SnapshotFileInfo.Type.HFILE).setHfile(path.toString()).build();
                long size;
                if (storeFile.hasFileSize()) {
                    size = storeFile.getFileSize();
                } else {
                    size = HFileLink.buildFromHFileLinkPattern(conf, path).getFileStatus(fs).getLen();
                }
                files.add(new Pair<>(fileInfo, size));
            }
        }
    });
    return files;
}
Also used : Path(org.apache.hadoop.fs.Path) ArrayList(java.util.ArrayList) SnapshotRegionManifest(org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotRegionManifest) SnapshotDescription(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.SnapshotDescription) IOException(java.io.IOException) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) SnapshotFileInfo(org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotFileInfo) Pair(org.apache.hadoop.hbase.util.Pair)

Example 5 with SnapshotDescription

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

the class RestoreSnapshotHelper method copySnapshotForScanner.

/**
   * Copy the snapshot files for a snapshot scanner, discards meta changes.
   * @param conf
   * @param fs
   * @param rootDir
   * @param restoreDir
   * @param snapshotName
   * @throws IOException
   */
public static RestoreMetaChanges copySnapshotForScanner(Configuration conf, FileSystem fs, Path rootDir, Path restoreDir, String snapshotName) throws IOException {
    // ensure that restore dir is not under root dir
    if (!restoreDir.getFileSystem(conf).getUri().equals(rootDir.getFileSystem(conf).getUri())) {
        throw new IllegalArgumentException("Filesystems for restore directory and HBase root " + "directory should be the same");
    }
    if (restoreDir.toUri().getPath().startsWith(rootDir.toUri().getPath())) {
        throw new IllegalArgumentException("Restore directory cannot be a sub directory of HBase " + "root directory. RootDir: " + rootDir + ", restoreDir: " + restoreDir);
    }
    Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotName, rootDir);
    SnapshotDescription snapshotDesc = SnapshotDescriptionUtils.readSnapshotInfo(fs, snapshotDir);
    SnapshotManifest manifest = SnapshotManifest.open(conf, fs, snapshotDir, snapshotDesc);
    MonitoredTask status = TaskMonitor.get().createStatus("Restoring  snapshot '" + snapshotName + "' to directory " + restoreDir);
    ForeignExceptionDispatcher monitor = new ForeignExceptionDispatcher();
    // we send createBackRefs=false so that restored hfiles do not create back reference links
    // in the base hbase root dir.
    RestoreSnapshotHelper helper = new RestoreSnapshotHelper(conf, fs, manifest, manifest.getTableDescriptor(), restoreDir, monitor, status, false);
    // TODO: parallelize.
    RestoreMetaChanges metaChanges = helper.restoreHdfsRegions();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Restored table dir:" + restoreDir);
        FSUtils.logFileSystemState(fs, restoreDir, LOG);
    }
    return metaChanges;
}
Also used : Path(org.apache.hadoop.fs.Path) SnapshotDescription(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.SnapshotDescription) ForeignExceptionDispatcher(org.apache.hadoop.hbase.errorhandling.ForeignExceptionDispatcher) MonitoredTask(org.apache.hadoop.hbase.monitoring.MonitoredTask)

Aggregations

SnapshotDescription (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.SnapshotDescription)27 Path (org.apache.hadoop.fs.Path)15 IOException (java.io.IOException)13 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)8 Test (org.junit.Test)7 FileSystem (org.apache.hadoop.fs.FileSystem)5 FileNotFoundException (java.io.FileNotFoundException)4 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)4 TableName (org.apache.hadoop.hbase.TableName)4 SnapshotRegionManifest (org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotRegionManifest)4 MasterFileSystem (org.apache.hadoop.hbase.master.MasterFileSystem)3 InterruptedIOException (java.io.InterruptedIOException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Configuration (org.apache.hadoop.conf.Configuration)2 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)2 FileStatus (org.apache.hadoop.fs.FileStatus)2 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)2 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)2 Admin (org.apache.hadoop.hbase.client.Admin)2