Search in sources :

Example 1 with RestoreSnapshotHelper

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

the class RestoreSnapshotProcedure method restoreSnapshot.

/**
   * Execute the on-disk Restore
   * @param env MasterProcedureEnv
   * @throws IOException
   **/
private void restoreSnapshot(final MasterProcedureEnv env) throws IOException {
    MasterFileSystem fileSystemManager = env.getMasterServices().getMasterFileSystem();
    FileSystem fs = fileSystemManager.getFileSystem();
    Path rootDir = fileSystemManager.getRootDir();
    final ForeignExceptionDispatcher monitorException = new ForeignExceptionDispatcher();
    LOG.info("Starting restore snapshot=" + ClientSnapshotDescriptionUtils.toString(snapshot));
    try {
        Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshot, rootDir);
        SnapshotManifest manifest = SnapshotManifest.open(env.getMasterServices().getConfiguration(), fs, snapshotDir, snapshot);
        RestoreSnapshotHelper restoreHelper = new RestoreSnapshotHelper(env.getMasterServices().getConfiguration(), fs, manifest, modifiedHTableDescriptor, rootDir, monitorException, getMonitorStatus());
        RestoreSnapshotHelper.RestoreMetaChanges metaChanges = restoreHelper.restoreHdfsRegions();
        regionsToRestore = metaChanges.getRegionsToRestore();
        regionsToRemove = metaChanges.getRegionsToRemove();
        regionsToAdd = metaChanges.getRegionsToAdd();
        parentsToChildrenPairMap = metaChanges.getParentToChildrenPairMap();
    } catch (IOException e) {
        String msg = "restore snapshot=" + ClientSnapshotDescriptionUtils.toString(snapshot) + " failed in on-disk restore. Try re-running the restore command.";
        LOG.error(msg, e);
        monitorException.receive(new ForeignException(env.getMasterServices().getServerName().toString(), e));
        throw new IOException(msg, e);
    }
}
Also used : MasterFileSystem(org.apache.hadoop.hbase.master.MasterFileSystem) Path(org.apache.hadoop.fs.Path) SnapshotManifest(org.apache.hadoop.hbase.snapshot.SnapshotManifest) FileSystem(org.apache.hadoop.fs.FileSystem) MasterFileSystem(org.apache.hadoop.hbase.master.MasterFileSystem) ForeignException(org.apache.hadoop.hbase.errorhandling.ForeignException) RestoreSnapshotHelper(org.apache.hadoop.hbase.snapshot.RestoreSnapshotHelper) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) ForeignExceptionDispatcher(org.apache.hadoop.hbase.errorhandling.ForeignExceptionDispatcher)

Example 2 with RestoreSnapshotHelper

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

the class CloneSnapshotProcedure method createFilesystemLayout.

/**
   * Create regions in file system.
   * @param env MasterProcedureEnv
   * @throws IOException
   */
private List<HRegionInfo> createFilesystemLayout(final MasterProcedureEnv env, final HTableDescriptor hTableDescriptor, final List<HRegionInfo> newRegions) throws IOException {
    return createFsLayout(env, hTableDescriptor, newRegions, new CreateHdfsRegions() {

        @Override
        public List<HRegionInfo> createHdfsRegions(final MasterProcedureEnv env, final Path tableRootDir, final TableName tableName, final List<HRegionInfo> newRegions) throws IOException {
            final MasterFileSystem mfs = env.getMasterServices().getMasterFileSystem();
            final FileSystem fs = mfs.getFileSystem();
            final Path rootDir = mfs.getRootDir();
            final Configuration conf = env.getMasterConfiguration();
            final ForeignExceptionDispatcher monitorException = new ForeignExceptionDispatcher();
            getMonitorStatus().setStatus("Clone snapshot - creating regions for table: " + tableName);
            try {
                // 1. Execute the on-disk Clone
                Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshot, rootDir);
                SnapshotManifest manifest = SnapshotManifest.open(conf, fs, snapshotDir, snapshot);
                RestoreSnapshotHelper restoreHelper = new RestoreSnapshotHelper(conf, fs, manifest, hTableDescriptor, tableRootDir, monitorException, monitorStatus);
                RestoreSnapshotHelper.RestoreMetaChanges metaChanges = restoreHelper.restoreHdfsRegions();
                // Clone operation should not have stuff to restore or remove
                Preconditions.checkArgument(!metaChanges.hasRegionsToRestore(), "A clone should not have regions to restore");
                Preconditions.checkArgument(!metaChanges.hasRegionsToRemove(), "A clone should not have regions to remove");
                // At this point the clone is complete. Next step is enabling the table.
                String msg = "Clone snapshot=" + snapshot.getName() + " on table=" + tableName + " completed!";
                LOG.info(msg);
                monitorStatus.setStatus(msg + " Waiting for table to be enabled...");
                // 2. Let the next step to add the regions to meta
                return metaChanges.getRegionsToAdd();
            } catch (Exception e) {
                String msg = "clone snapshot=" + ClientSnapshotDescriptionUtils.toString(snapshot) + " failed because " + e.getMessage();
                LOG.error(msg, e);
                IOException rse = new RestoreSnapshotException(msg, e, ProtobufUtil.createSnapshotDesc(snapshot));
                // these handlers aren't futures so we need to register the error here.
                monitorException.receive(new ForeignException("Master CloneSnapshotProcedure", rse));
                throw rse;
            }
        }
    });
}
Also used : Path(org.apache.hadoop.fs.Path) MasterFileSystem(org.apache.hadoop.hbase.master.MasterFileSystem) Configuration(org.apache.hadoop.conf.Configuration) CreateHdfsRegions(org.apache.hadoop.hbase.master.procedure.CreateTableProcedure.CreateHdfsRegions) IOException(java.io.IOException) ForeignExceptionDispatcher(org.apache.hadoop.hbase.errorhandling.ForeignExceptionDispatcher) RestoreSnapshotException(org.apache.hadoop.hbase.snapshot.RestoreSnapshotException) ForeignException(org.apache.hadoop.hbase.errorhandling.ForeignException) TableExistsException(org.apache.hadoop.hbase.TableExistsException) IOException(java.io.IOException) RestoreSnapshotException(org.apache.hadoop.hbase.snapshot.RestoreSnapshotException) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) SnapshotManifest(org.apache.hadoop.hbase.snapshot.SnapshotManifest) FileSystem(org.apache.hadoop.fs.FileSystem) MasterFileSystem(org.apache.hadoop.hbase.master.MasterFileSystem) ForeignException(org.apache.hadoop.hbase.errorhandling.ForeignException) ArrayList(java.util.ArrayList) List(java.util.List) RestoreSnapshotHelper(org.apache.hadoop.hbase.snapshot.RestoreSnapshotHelper)

Aggregations

IOException (java.io.IOException)2 FileSystem (org.apache.hadoop.fs.FileSystem)2 Path (org.apache.hadoop.fs.Path)2 ForeignException (org.apache.hadoop.hbase.errorhandling.ForeignException)2 ForeignExceptionDispatcher (org.apache.hadoop.hbase.errorhandling.ForeignExceptionDispatcher)2 MasterFileSystem (org.apache.hadoop.hbase.master.MasterFileSystem)2 RestoreSnapshotHelper (org.apache.hadoop.hbase.snapshot.RestoreSnapshotHelper)2 SnapshotManifest (org.apache.hadoop.hbase.snapshot.SnapshotManifest)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Configuration (org.apache.hadoop.conf.Configuration)1 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)1 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)1 TableExistsException (org.apache.hadoop.hbase.TableExistsException)1 TableName (org.apache.hadoop.hbase.TableName)1 CreateHdfsRegions (org.apache.hadoop.hbase.master.procedure.CreateTableProcedure.CreateHdfsRegions)1 RestoreSnapshotException (org.apache.hadoop.hbase.snapshot.RestoreSnapshotException)1