Java 类org.apache.hadoop.hbase.snapshot.RestoreSnapshotHelper 实例源码

项目:ditb    文件:TableSnapshotScanner.java   
private void init() throws IOException {
  final RestoreSnapshotHelper.RestoreMetaChanges meta =
    RestoreSnapshotHelper.copySnapshotForScanner(
      conf, fs, rootDir, restoreDir, snapshotName);
  final List<HRegionInfo> restoredRegions = meta.getRegionsToAdd();

  htd = meta.getTableDescriptor();
  regions = new ArrayList<HRegionInfo>(restoredRegions.size());
  for (HRegionInfo hri: restoredRegions) {
    if (CellUtil.overlappingKeys(scan.getStartRow(), scan.getStopRow(),
        hri.getStartKey(), hri.getEndKey())) {
      regions.add(hri);
    }
  }

  // sort for regions according to startKey.
  Collections.sort(regions);
  initScanMetrics(scan);
}
项目:hbase    文件:TableSnapshotInputFormatImpl.java   
/**
 * Configures the job to use TableSnapshotInputFormat to read from a snapshot.
 * @param conf the job to configure
 * @param snapshotName the name of the snapshot to read from
 * @param restoreDir a temporary directory to restore the snapshot into. Current user should
 * have write permissions to this directory, and this should not be a subdirectory of rootdir.
 * After the job is finished, restoreDir can be deleted.
 * @param numSplitsPerRegion how many input splits to generate per one region
 * @param splitAlgo SplitAlgorithm to be used when generating InputSplits
 * @throws IOException if an error occurs
 */
public static void setInput(Configuration conf, String snapshotName, Path restoreDir,
                            RegionSplitter.SplitAlgorithm splitAlgo, int numSplitsPerRegion)
        throws IOException {
  conf.set(SNAPSHOT_NAME_KEY, snapshotName);
  if (numSplitsPerRegion < 1) {
    throw new IllegalArgumentException("numSplits must be >= 1, " +
            "illegal numSplits : " + numSplitsPerRegion);
  }
  if (splitAlgo == null && numSplitsPerRegion > 1) {
    throw new IllegalArgumentException("Split algo can't be null when numSplits > 1");
  }
  if (splitAlgo != null) {
    conf.set(SPLIT_ALGO, splitAlgo.getClass().getName());
  }
  conf.setInt(NUM_SPLITS_PER_REGION, numSplitsPerRegion);
  Path rootDir = FSUtils.getRootDir(conf);
  FileSystem fs = rootDir.getFileSystem(conf);

  restoreDir = new Path(restoreDir, UUID.randomUUID().toString());

  // TODO: restore from record readers to parallelize.
  RestoreSnapshotHelper.copySnapshotForScanner(conf, fs, rootDir, restoreDir, snapshotName);

  conf.set(RESTORE_DIR_KEY, restoreDir.toString());
}
项目:pbase    文件:TableSnapshotScanner.java   
private void init() throws IOException {
  Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotName, rootDir);
  SnapshotDescription snapshotDesc = SnapshotDescriptionUtils.readSnapshotInfo(fs, snapshotDir);
  SnapshotManifest manifest = SnapshotManifest.open(conf, fs, snapshotDir, snapshotDesc);

  // load table descriptor
  htd = manifest.getTableDescriptor();

  List<SnapshotRegionManifest> regionManifests = manifest.getRegionManifests();
  if (regionManifests == null) {
    throw new IllegalArgumentException("Snapshot seems empty");
  }

  regions = new ArrayList<HRegionInfo>(regionManifests.size());
  for (SnapshotRegionManifest regionManifest : regionManifests) {
    // load region descriptor
    HRegionInfo hri = HRegionInfo.convert(regionManifest.getRegionInfo());

    if (CellUtil.overlappingKeys(scan.getStartRow(), scan.getStopRow(),
        hri.getStartKey(), hri.getEndKey())) {
      regions.add(hri);
    }
  }

  // sort for regions according to startKey.
  Collections.sort(regions);

  initScanMetrics(scan);

  RestoreSnapshotHelper.copySnapshotForScanner(conf, fs,
    rootDir, restoreDir, snapshotName);
}
项目:pbase    文件:TableSnapshotInputFormatImpl.java   
/**
 * Configures the job to use TableSnapshotInputFormat to read from a snapshot.
 * @param conf the job to configuration
 * @param snapshotName the name of the snapshot to read from
 * @param restoreDir a temporary directory to restore the snapshot into. Current user should
 * have write permissions to this directory, and this should not be a subdirectory of rootdir.
 * After the job is finished, restoreDir can be deleted.
 * @throws IOException if an error occurs
 */
public static void setInput(Configuration conf, String snapshotName, Path restoreDir)
    throws IOException {
  conf.set(SNAPSHOT_NAME_KEY, snapshotName);

  Path rootDir = FSUtils.getRootDir(conf);
  FileSystem fs = rootDir.getFileSystem(conf);

  restoreDir = new Path(restoreDir, UUID.randomUUID().toString());

  // TODO: restore from record readers to parallelize.
  RestoreSnapshotHelper.copySnapshotForScanner(conf, fs, rootDir, restoreDir, snapshotName);

  conf.set(RESTORE_DIR_KEY, restoreDir.toString());
}
项目:HIndex    文件:TableSnapshotScanner.java   
private void init() throws IOException {
  Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotName, rootDir);

  //load table descriptor
  htd = FSTableDescriptors.getTableDescriptorFromFs(fs, snapshotDir);

  Set<String> snapshotRegionNames
    = SnapshotReferenceUtil.getSnapshotRegionNames(fs, snapshotDir);
  if (snapshotRegionNames == null) {
    throw new IllegalArgumentException("Snapshot seems empty");
  }

  regions = new ArrayList<HRegionInfo>(snapshotRegionNames.size());
  for (String regionName : snapshotRegionNames) {
    // load region descriptor
    Path regionDir = new Path(snapshotDir, regionName);
    HRegionInfo hri = HRegionFileSystem.loadRegionInfoFileContent(fs,
        regionDir);

    if (CellUtil.overlappingKeys(scan.getStartRow(), scan.getStopRow(),
        hri.getStartKey(), hri.getEndKey())) {
      regions.add(hri);
    }
  }

  // sort for regions according to startKey.
  Collections.sort(regions);

  initScanMetrics(scan);

  RestoreSnapshotHelper.copySnapshotForScanner(conf, fs,
    rootDir, restoreDir, snapshotName);
}
项目:HIndex    文件:TableSnapshotInputFormatImpl.java   
/**
 * Configures the job to use TableSnapshotInputFormat to read from a snapshot.
 * @param conf the job to configure
 * @param snapshotName the name of the snapshot to read from
 * @param restoreDir a temporary directory to restore the snapshot into. Current user should
 * have write permissions to this directory, and this should not be a subdirectory of rootdir.
 * After the job is finished, restoreDir can be deleted.
 * @throws IOException if an error occurs
 */
public static void setInput(Configuration conf, String snapshotName, Path restoreDir)
    throws IOException {
  conf.set(SNAPSHOT_NAME_KEY, snapshotName);

  Path rootDir = new Path(conf.get(HConstants.HBASE_DIR));
  FileSystem fs = rootDir.getFileSystem(conf);

  restoreDir = new Path(restoreDir, UUID.randomUUID().toString());

  // TODO: restore from record readers to parallelize.
  RestoreSnapshotHelper.copySnapshotForScanner(conf, fs, rootDir, restoreDir, snapshotName);

  conf.set(TABLE_DIR_KEY, restoreDir.toString());
}
项目:hbase    文件:TableSnapshotScanner.java   
private void openWithRestoringSnapshot() throws IOException {
  final RestoreSnapshotHelper.RestoreMetaChanges meta =
      RestoreSnapshotHelper.copySnapshotForScanner(conf, fs, rootDir, restoreDir, snapshotName);
  final List<RegionInfo> restoredRegions = meta.getRegionsToAdd();

  htd = meta.getTableDescriptor();
  regions = new ArrayList<>(restoredRegions.size());
  restoredRegions.stream().filter(this::isValidRegion).sorted().forEach(r -> regions.add(r));
}
项目:hbase    文件:RestoreSnapshotProcedure.java   
/**
 * 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,
            modifiedTableDescriptor,
      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);
  }
}
项目:hbase    文件:RestoreSnapshotProcedure.java   
private void restoreSnapshotAcl(final MasterProcedureEnv env) throws IOException {
  if (restoreAcl && snapshot.hasUsersAndPermissions() && snapshot.getUsersAndPermissions() != null
      && SnapshotDescriptionUtils
          .isSecurityAvailable(env.getMasterServices().getConfiguration())) {
    // restore acl of snapshot to table.
    RestoreSnapshotHelper.restoreSnapshotAcl(snapshot, TableName.valueOf(snapshot.getTable()),
      env.getMasterServices().getConfiguration());
  }
}
项目:hbase    文件:CloneSnapshotProcedure.java   
private void restoreSnapshotAcl(MasterProcedureEnv env) throws IOException {
  Configuration conf = env.getMasterServices().getConfiguration();
  if (restoreAcl && snapshot.hasUsersAndPermissions() && snapshot.getUsersAndPermissions() != null
      && SnapshotDescriptionUtils.isSecurityAvailable(conf)) {
    RestoreSnapshotHelper.restoreSnapshotAcl(snapshot, tableDescriptor.getTableName(), conf);
  }
}
项目:hbase    文件:CloneSnapshotProcedure.java   
/**
 * Add regions to hbase:meta table.
 * @param env MasterProcedureEnv
 * @throws IOException
 */
private void addRegionsToMeta(final MasterProcedureEnv env) throws IOException {
  newRegions = CreateTableProcedure.addTableToMeta(env, tableDescriptor, newRegions);

  // TODO: parentsToChildrenPairMap is always empty, which makes updateMetaParentRegions()
  // a no-op. This part seems unnecessary. Figure out. - Appy 12/21/17
  RestoreSnapshotHelper.RestoreMetaChanges metaChanges =
      new RestoreSnapshotHelper.RestoreMetaChanges(
              tableDescriptor, parentsToChildrenPairMap);
  metaChanges.updateMetaParentRegions(env.getMasterServices().getConnection(), newRegions);
}
项目:hbase    文件:VerifyReplication.java   
private void restoreSnapshotForPeerCluster(Configuration conf, String peerQuorumAddress)
    throws IOException {
  Configuration peerConf =
      HBaseConfiguration.createClusterConf(conf, peerQuorumAddress, PEER_CONFIG_PREFIX);
  FileSystem.setDefaultUri(peerConf, peerFSAddress);
  FSUtils.setRootDir(peerConf, new Path(peerFSAddress, peerHBaseRootAddress));
  FileSystem fs = FileSystem.get(peerConf);
  RestoreSnapshotHelper.copySnapshotForScanner(peerConf, fs, FSUtils.getRootDir(peerConf),
    new Path(peerFSAddress, peerSnapshotTmpDir), peerSnapshotName);
}
项目:PyroDB    文件:TableSnapshotScanner.java   
private void init() throws IOException {
  Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotName, rootDir);
  SnapshotDescription snapshotDesc = SnapshotDescriptionUtils.readSnapshotInfo(fs, snapshotDir);
  SnapshotManifest manifest = SnapshotManifest.open(conf, fs, snapshotDir, snapshotDesc);

  // load table descriptor
  htd = manifest.getTableDescriptor();

  List<SnapshotRegionManifest> regionManifests = manifest.getRegionManifests();
  if (regionManifests == null) {
    throw new IllegalArgumentException("Snapshot seems empty");
  }

  regions = new ArrayList<HRegionInfo>(regionManifests.size());
  for (SnapshotRegionManifest regionManifest : regionManifests) {
    // load region descriptor
    HRegionInfo hri = HRegionInfo.convert(regionManifest.getRegionInfo());

    if (CellUtil.overlappingKeys(scan.getStartRow(), scan.getStopRow(),
        hri.getStartKey(), hri.getEndKey())) {
      regions.add(hri);
    }
  }

  // sort for regions according to startKey.
  Collections.sort(regions);

  initScanMetrics(scan);

  RestoreSnapshotHelper.copySnapshotForScanner(conf, fs,
    rootDir, restoreDir, snapshotName);
}
项目:PyroDB    文件:TableSnapshotInputFormatImpl.java   
/**
 * Configures the job to use TableSnapshotInputFormat to read from a snapshot.
 * @param conf the job to configuration
 * @param snapshotName the name of the snapshot to read from
 * @param restoreDir a temporary directory to restore the snapshot into. Current user should
 * have write permissions to this directory, and this should not be a subdirectory of rootdir.
 * After the job is finished, restoreDir can be deleted.
 * @throws IOException if an error occurs
 */
public static void setInput(Configuration conf, String snapshotName, Path restoreDir)
    throws IOException {
  conf.set(SNAPSHOT_NAME_KEY, snapshotName);

  Path rootDir = FSUtils.getRootDir(conf);
  FileSystem fs = rootDir.getFileSystem(conf);

  restoreDir = new Path(restoreDir, UUID.randomUUID().toString());

  // TODO: restore from record readers to parallelize.
  RestoreSnapshotHelper.copySnapshotForScanner(conf, fs, rootDir, restoreDir, snapshotName);

  conf.set(TABLE_DIR_KEY, restoreDir.toString());
}
项目:ditb    文件:RestoreSnapshotHandler.java   
/**
 * The restore table is executed in place.
 *  - The on-disk data will be restored - reference files are put in place without moving data
 *  -  [if something fail here: you need to delete the table and re-run the restore]
 *  - hbase:meta will be updated
 *  -  [if something fail here: you need to run hbck to fix hbase:meta entries]
 * The passed in list gets changed in this method
 */
@Override
protected void handleTableOperation(List<HRegionInfo> hris) throws IOException {
  MasterFileSystem fileSystemManager = masterServices.getMasterFileSystem();
  Connection conn = masterServices.getConnection();
  FileSystem fs = fileSystemManager.getFileSystem();
  Path rootDir = fileSystemManager.getRootDir();
  TableName tableName = hTableDescriptor.getTableName();

  try {
    // 1. Update descriptor
    this.masterServices.getTableDescriptors().add(hTableDescriptor);

    // 2. Execute the on-disk Restore
    LOG.debug("Starting restore snapshot=" + ClientSnapshotDescriptionUtils.toString(snapshot));
    Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshot, rootDir);
    SnapshotManifest manifest = SnapshotManifest.open(masterServices.getConfiguration(), fs,
                                                      snapshotDir, snapshot);
    RestoreSnapshotHelper restoreHelper = new RestoreSnapshotHelper(
        masterServices.getConfiguration(), fs, manifest,
        this.hTableDescriptor, rootDir, monitor, status);
    RestoreSnapshotHelper.RestoreMetaChanges metaChanges = restoreHelper.restoreHdfsRegions();

    // 3. Forces all the RegionStates to be offline
    //
    // The AssignmentManager keeps all the region states around
    // with no possibility to remove them, until the master is restarted.
    // This means that a region marked as SPLIT before the restore will never be assigned again.
    // To avoid having all states around all the regions are switched to the OFFLINE state,
    // which is the same state that the regions will be after a delete table.
    forceRegionsOffline(metaChanges);

    // 4. Applies changes to hbase:meta
    status.setStatus("Preparing to restore each region");

    // 4.1 Removes the current set of regions from META
    //
    // By removing also the regions to restore (the ones present both in the snapshot
    // and in the current state) we ensure that no extra fields are present in META
    // e.g. with a simple add addRegionToMeta() the splitA and splitB attributes
    // not overwritten/removed, so you end up with old informations
    // that are not correct after the restore.
    List<HRegionInfo> hrisToRemove = new LinkedList<HRegionInfo>();
    if (metaChanges.hasRegionsToRemove()) hrisToRemove.addAll(metaChanges.getRegionsToRemove());
    MetaTableAccessor.deleteRegions(conn, hrisToRemove);

    // 4.2 Add the new set of regions to META
    //
    // At this point the old regions are no longer present in META.
    // and the set of regions present in the snapshot will be written to META.
    // All the information in hbase:meta are coming from the .regioninfo of each region present
    // in the snapshot folder.
    hris.clear();
    if (metaChanges.hasRegionsToAdd()) hris.addAll(metaChanges.getRegionsToAdd());
    MetaTableAccessor.addRegionsToMeta(conn, hris, hTableDescriptor.getRegionReplication());
    if (metaChanges.hasRegionsToRestore()) {
      MetaTableAccessor.overwriteRegions(conn, metaChanges.getRegionsToRestore(),
        hTableDescriptor.getRegionReplication());
    }
    metaChanges.updateMetaParentRegions(this.server.getConnection(), hris);

    // At this point the restore is complete. Next step is enabling the table.
    LOG.info("Restore snapshot=" + ClientSnapshotDescriptionUtils.toString(snapshot) +
      " on table=" + tableName + " completed!");
  } catch (IOException e) {
    String msg = "restore snapshot=" + ClientSnapshotDescriptionUtils.toString(snapshot)
        + " failed. Try re-running the restore command.";
    LOG.error(msg, e);
    monitor.receive(new ForeignException(masterServices.getServerName().toString(), e));
    throw new RestoreSnapshotException(msg, e);
  }
}
项目:ditb    文件:RestoreSnapshotHandler.java   
private void forceRegionsOffline(final RestoreSnapshotHelper.RestoreMetaChanges metaChanges) {
  forceRegionsOffline(metaChanges.getRegionsToAdd());
  forceRegionsOffline(metaChanges.getRegionsToRestore());
  forceRegionsOffline(metaChanges.getRegionsToRemove());
}
项目:ditb    文件:MultiTableSnapshotInputFormatImpl.java   
void restoreSnapshot(Configuration conf, String snapshotName, Path rootDir, Path restoreDir,
    FileSystem fs) throws IOException {
  RestoreSnapshotHelper.copySnapshotForScanner(conf, fs, rootDir, restoreDir, snapshotName);
}
项目:LCIndex-HBase-0.94.16    文件:SnapshotManager.java   
/**
 * Restore the specified snapshot
 * @param reqSnapshot
 * @throws IOException
 */
public void restoreSnapshot(SnapshotDescription reqSnapshot) throws IOException {
  FileSystem fs = master.getMasterFileSystem().getFileSystem();
  Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(reqSnapshot, rootDir);
  MasterCoprocessorHost cpHost = master.getCoprocessorHost();

  // check if the snapshot exists
  if (!fs.exists(snapshotDir)) {
    LOG.error("A Snapshot named '" + reqSnapshot.getName() + "' does not exist.");
    throw new SnapshotDoesNotExistException(reqSnapshot);
  }

  // read snapshot information
  SnapshotDescription fsSnapshot = SnapshotDescriptionUtils.readSnapshotInfo(fs, snapshotDir);
  HTableDescriptor snapshotTableDesc = FSTableDescriptors.getTableDescriptor(fs, snapshotDir);
  String tableName = reqSnapshot.getTable();

  // stop tracking "abandoned" handlers
  cleanupSentinels();

  // Verify snapshot validity
  SnapshotReferenceUtil.verifySnapshot(master.getConfiguration(), fs, snapshotDir, fsSnapshot);

  // Execute the restore/clone operation
  if (MetaReader.tableExists(master.getCatalogTracker(), tableName)) {
    if (master.getAssignmentManager().getZKTable().isEnabledTable(fsSnapshot.getTable())) {
      throw new UnsupportedOperationException("Table '" +
        fsSnapshot.getTable() + "' must be disabled in order to perform a restore operation.");
    }

    // call coproc pre hook
    if (cpHost != null) {
      cpHost.preRestoreSnapshot(reqSnapshot, snapshotTableDesc);
    }
    restoreSnapshot(fsSnapshot, snapshotTableDesc);
    LOG.info("Restore snapshot=" + fsSnapshot.getName() + " as table=" + tableName);

    if (cpHost != null) {
      cpHost.postRestoreSnapshot(reqSnapshot, snapshotTableDesc);
    }
  } else {
    HTableDescriptor htd = RestoreSnapshotHelper.cloneTableSchema(snapshotTableDesc,
                                                       Bytes.toBytes(tableName));
    if (cpHost != null) {
      cpHost.preCloneSnapshot(reqSnapshot, htd);
    }
    cloneSnapshot(fsSnapshot, htd);
    LOG.info("Clone snapshot=" + fsSnapshot.getName() + " as table=" + tableName);

    if (cpHost != null) {
      cpHost.postCloneSnapshot(reqSnapshot, htd);
    }
  }
}
项目:LCIndex-HBase-0.94.16    文件:RestoreSnapshotHandler.java   
/**
 * The restore table is executed in place.
 *  - The on-disk data will be restored - reference files are put in place without moving data
 *  -  [if something fail here: you need to delete the table and re-run the restore]
 *  - META will be updated
 *  -  [if something fail here: you need to run hbck to fix META entries]
 * The passed in list gets changed in this method
 */
@Override
protected void handleTableOperation(List<HRegionInfo> hris) throws IOException {
  MasterFileSystem fileSystemManager = masterServices.getMasterFileSystem();
  CatalogTracker catalogTracker = masterServices.getCatalogTracker();
  FileSystem fs = fileSystemManager.getFileSystem();
  Path rootDir = fileSystemManager.getRootDir();
  byte[] tableName = hTableDescriptor.getName();
  Path tableDir = HTableDescriptor.getTableDir(rootDir, tableName);

  try {
    // 1. Update descriptor
    this.masterServices.getTableDescriptors().add(hTableDescriptor);

    // 2. Execute the on-disk Restore
    LOG.debug("Starting restore snapshot=" + SnapshotDescriptionUtils.toString(snapshot));
    Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshot, rootDir);
    RestoreSnapshotHelper restoreHelper = new RestoreSnapshotHelper(
        masterServices.getConfiguration(), fs,
        snapshot, snapshotDir, hTableDescriptor, tableDir, monitor, status);
    RestoreSnapshotHelper.RestoreMetaChanges metaChanges = restoreHelper.restoreHdfsRegions();

    // 3. Forces all the RegionStates to be offline
    //
    // The AssignmentManager keeps all the region states around
    // with no possibility to remove them, until the master is restarted.
    // This means that a region marked as SPLIT before the restore will never be assigned again.
    // To avoid having all states around all the regions are switched to the OFFLINE state,
    // which is the same state that the regions will be after a delete table.
    forceRegionsOffline(metaChanges);
    forceRegionsOffline(metaChanges);

    // 4. Applies changes to .META.

    // 4.1 Removes the current set of regions from META
    //
    // By removing also the regions to restore (the ones present both in the snapshot
    // and in the current state) we ensure that no extra fields are present in META
    // e.g. with a simple add addRegionToMeta() the splitA and splitB attributes
    // not overwritten/removed, so you end up with old informations
    // that are not correct after the restore.
    List<HRegionInfo> hrisToRemove = new LinkedList<HRegionInfo>();
    if (metaChanges.hasRegionsToRemove()) hrisToRemove.addAll(metaChanges.getRegionsToRemove());
    MetaEditor.deleteRegions(catalogTracker, hrisToRemove);

    // 4.2 Add the new set of regions to META
    //
    // At this point the old regions are no longer present in META.
    // and the set of regions present in the snapshot will be written to META.
    // All the information in META are coming from the .regioninfo of each region present
    // in the snapshot folder.
    hris.clear();
    if (metaChanges.hasRegionsToAdd()) hris.addAll(metaChanges.getRegionsToAdd());
    MetaEditor.addRegionsToMeta(catalogTracker, hris);
    if (metaChanges.hasRegionsToRestore()) {
      MetaEditor.overwriteRegions(catalogTracker, metaChanges.getRegionsToRestore());
    }
    metaChanges.updateMetaParentRegions(catalogTracker, hris);

    // At this point the restore is complete. Next step is enabling the table.
    LOG.info("Restore snapshot=" + SnapshotDescriptionUtils.toString(snapshot) + " on table=" +
      Bytes.toString(tableName) + " completed!");
  } catch (IOException e) {
    String msg = "restore snapshot=" + SnapshotDescriptionUtils.toString(snapshot)
        + " failed. Try re-running the restore command.";
    LOG.error(msg, e);
    monitor.receive(new ForeignException(masterServices.getServerName().toString(), e));
    throw new RestoreSnapshotException(msg, e);
  } finally {
    this.stopped = true;
  }
}
项目:LCIndex-HBase-0.94.16    文件:RestoreSnapshotHandler.java   
private void forceRegionsOffline(final RestoreSnapshotHelper.RestoreMetaChanges metaChanges) {
  forceRegionsOffline(metaChanges.getRegionsToAdd());
  forceRegionsOffline(metaChanges.getRegionsToRestore());
  forceRegionsOffline(metaChanges.getRegionsToRemove());
}
项目:pbase    文件:SnapshotManager.java   
/**
 * Restore the specified snapshot
 * @param reqSnapshot
 * @throws IOException
 */
public void restoreSnapshot(SnapshotDescription reqSnapshot) throws IOException {
  FileSystem fs = master.getMasterFileSystem().getFileSystem();
  Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(reqSnapshot, rootDir);
  MasterCoprocessorHost cpHost = master.getMasterCoprocessorHost();

  // check if the snapshot exists
  if (!fs.exists(snapshotDir)) {
    LOG.error("A Snapshot named '" + reqSnapshot.getName() + "' does not exist.");
    throw new SnapshotDoesNotExistException(reqSnapshot);
  }

  // read snapshot information
  SnapshotDescription fsSnapshot = SnapshotDescriptionUtils.readSnapshotInfo(fs, snapshotDir);
  SnapshotManifest manifest = SnapshotManifest.open(master.getConfiguration(), fs,
      snapshotDir, fsSnapshot);
  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
  if (MetaTableAccessor.tableExists(master.getConnection(), tableName)) {
    if (master.getAssignmentManager().getTableStateManager().isTableState(
        TableName.valueOf(fsSnapshot.getTable()), ZooKeeperProtos.Table.State.ENABLED)) {
      throw new UnsupportedOperationException("Table '" +
          TableName.valueOf(fsSnapshot.getTable()) + "' must be disabled in order to " +
          "perform a restore operation" +
          ".");
    }

    // call coproc pre hook
    if (cpHost != null) {
      cpHost.preRestoreSnapshot(reqSnapshot, snapshotTableDesc);
    }
    restoreSnapshot(fsSnapshot, snapshotTableDesc);
    LOG.info("Restore snapshot=" + fsSnapshot.getName() + " as table=" + tableName);

    if (cpHost != null) {
      cpHost.postRestoreSnapshot(reqSnapshot, snapshotTableDesc);
    }
  } else {
    HTableDescriptor htd = RestoreSnapshotHelper.cloneTableSchema(snapshotTableDesc, tableName);
    if (cpHost != null) {
      cpHost.preCloneSnapshot(reqSnapshot, htd);
    }
    cloneSnapshot(fsSnapshot, htd);
    LOG.info("Clone snapshot=" + fsSnapshot.getName() + " as table=" + tableName);

    if (cpHost != null) {
      cpHost.postCloneSnapshot(reqSnapshot, htd);
    }
  }
}
项目:pbase    文件:RestoreSnapshotHandler.java   
/**
 * The restore table is executed in place.
 *  - The on-disk data will be restored - reference files are put in place without moving data
 *  -  [if something fail here: you need to delete the table and re-run the restore]
 *  - hbase:meta will be updated
 *  -  [if something fail here: you need to run hbck to fix hbase:meta entries]
 * The passed in list gets changed in this method
 */
@Override
protected void handleTableOperation(List<HRegionInfo> hris) throws IOException {
  MasterFileSystem fileSystemManager = masterServices.getMasterFileSystem();
  Connection conn = masterServices.getConnection();
  FileSystem fs = fileSystemManager.getFileSystem();
  Path rootDir = fileSystemManager.getRootDir();
  TableName tableName = hTableDescriptor.getTableName();

  try {
    // 1. Update descriptor
    this.masterServices.getTableDescriptors().add(hTableDescriptor);

    // 2. Execute the on-disk Restore
    LOG.debug("Starting restore snapshot=" + ClientSnapshotDescriptionUtils.toString(snapshot));
    Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshot, rootDir);
    SnapshotManifest manifest = SnapshotManifest.open(masterServices.getConfiguration(), fs,
                                                      snapshotDir, snapshot);
    RestoreSnapshotHelper restoreHelper = new RestoreSnapshotHelper(
        masterServices.getConfiguration(), fs, manifest,
        this.hTableDescriptor, rootDir, monitor, status);
    RestoreSnapshotHelper.RestoreMetaChanges metaChanges = restoreHelper.restoreHdfsRegions();

    // 3. Forces all the RegionStates to be offline
    //
    // The AssignmentManager keeps all the region states around
    // with no possibility to remove them, until the master is restarted.
    // This means that a region marked as SPLIT before the restore will never be assigned again.
    // To avoid having all states around all the regions are switched to the OFFLINE state,
    // which is the same state that the regions will be after a delete table.
    forceRegionsOffline(metaChanges);

    // 4. Applies changes to hbase:meta
    status.setStatus("Preparing to restore each region");

    // 4.1 Removes the current set of regions from META
    //
    // By removing also the regions to restore (the ones present both in the snapshot
    // and in the current state) we ensure that no extra fields are present in META
    // e.g. with a simple add addRegionToMeta() the splitA and splitB attributes
    // not overwritten/removed, so you end up with old informations
    // that are not correct after the restore.
    List<HRegionInfo> hrisToRemove = new LinkedList<HRegionInfo>();
    if (metaChanges.hasRegionsToRemove()) hrisToRemove.addAll(metaChanges.getRegionsToRemove());
    MetaTableAccessor.deleteRegions(conn, hrisToRemove);

    // 4.2 Add the new set of regions to META
    //
    // At this point the old regions are no longer present in META.
    // and the set of regions present in the snapshot will be written to META.
    // All the information in hbase:meta are coming from the .regioninfo of each region present
    // in the snapshot folder.
    hris.clear();
    if (metaChanges.hasRegionsToAdd()) hris.addAll(metaChanges.getRegionsToAdd());
    MetaTableAccessor.addRegionsToMeta(conn, hris);
    if (metaChanges.hasRegionsToRestore()) {
      MetaTableAccessor.overwriteRegions(conn, metaChanges.getRegionsToRestore());
    }
    metaChanges.updateMetaParentRegions(this.server.getConnection(), hris);

    // At this point the restore is complete. Next step is enabling the table.
    LOG.info("Restore snapshot=" + ClientSnapshotDescriptionUtils.toString(snapshot) +
      " on table=" + tableName + " completed!");
  } catch (IOException e) {
    String msg = "restore snapshot=" + ClientSnapshotDescriptionUtils.toString(snapshot)
        + " failed. Try re-running the restore command.";
    LOG.error(msg, e);
    monitor.receive(new ForeignException(masterServices.getServerName().toString(), e));
    throw new RestoreSnapshotException(msg, e);
  }
}
项目:pbase    文件:RestoreSnapshotHandler.java   
private void forceRegionsOffline(final RestoreSnapshotHelper.RestoreMetaChanges metaChanges) {
  forceRegionsOffline(metaChanges.getRegionsToAdd());
  forceRegionsOffline(metaChanges.getRegionsToRestore());
  forceRegionsOffline(metaChanges.getRegionsToRemove());
}
项目:HIndex    文件:SnapshotManager.java   
/**
 * Restore the specified snapshot
 * @param reqSnapshot
 * @throws IOException
 */
public void restoreSnapshot(SnapshotDescription reqSnapshot) throws IOException {
  FileSystem fs = master.getMasterFileSystem().getFileSystem();
  Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(reqSnapshot, rootDir);
  MasterCoprocessorHost cpHost = master.getCoprocessorHost();

  // check if the snapshot exists
  if (!fs.exists(snapshotDir)) {
    LOG.error("A Snapshot named '" + reqSnapshot.getName() + "' does not exist.");
    throw new SnapshotDoesNotExistException(reqSnapshot);
  }

  // read snapshot information
  SnapshotDescription fsSnapshot = SnapshotDescriptionUtils.readSnapshotInfo(fs, snapshotDir);
  HTableDescriptor snapshotTableDesc =
      FSTableDescriptors.getTableDescriptorFromFs(fs, snapshotDir);
  TableName tableName = TableName.valueOf(reqSnapshot.getTable());

  // stop tracking "abandoned" handlers
  cleanupSentinels();

  // Verify snapshot validity
  SnapshotReferenceUtil.verifySnapshot(master.getConfiguration(), fs, snapshotDir, fsSnapshot);

  // Execute the restore/clone operation
  if (MetaReader.tableExists(master.getCatalogTracker(), tableName)) {
    if (master.getAssignmentManager().getZKTable().isEnabledTable(
        TableName.valueOf(fsSnapshot.getTable()))) {
      throw new UnsupportedOperationException("Table '" +
          TableName.valueOf(fsSnapshot.getTable()) + "' must be disabled in order to " +
          "perform a restore operation" +
          ".");
    }

    // call coproc pre hook
    if (cpHost != null) {
      cpHost.preRestoreSnapshot(reqSnapshot, snapshotTableDesc);
    }
    restoreSnapshot(fsSnapshot, snapshotTableDesc);
    LOG.info("Restore snapshot=" + fsSnapshot.getName() + " as table=" + tableName);

    if (cpHost != null) {
      cpHost.postRestoreSnapshot(reqSnapshot, snapshotTableDesc);
    }
  } else {
    HTableDescriptor htd = RestoreSnapshotHelper.cloneTableSchema(snapshotTableDesc, tableName);
    if (cpHost != null) {
      cpHost.preCloneSnapshot(reqSnapshot, htd);
    }
    cloneSnapshot(fsSnapshot, htd);
    LOG.info("Clone snapshot=" + fsSnapshot.getName() + " as table=" + tableName);

    if (cpHost != null) {
      cpHost.postCloneSnapshot(reqSnapshot, htd);
    }
  }
}
项目:HIndex    文件:RestoreSnapshotHandler.java   
/**
 * The restore table is executed in place.
 *  - The on-disk data will be restored - reference files are put in place without moving data
 *  -  [if something fail here: you need to delete the table and re-run the restore]
 *  - hbase:meta will be updated
 *  -  [if something fail here: you need to run hbck to fix hbase:meta entries]
 * The passed in list gets changed in this method
 */
@Override
protected void handleTableOperation(List<HRegionInfo> hris) throws IOException {
  MasterFileSystem fileSystemManager = masterServices.getMasterFileSystem();
  CatalogTracker catalogTracker = masterServices.getCatalogTracker();
  FileSystem fs = fileSystemManager.getFileSystem();
  Path rootDir = fileSystemManager.getRootDir();
  TableName tableName = hTableDescriptor.getTableName();

  try {
    // 1. Update descriptor
    this.masterServices.getTableDescriptors().add(hTableDescriptor);

    // 2. Execute the on-disk Restore
    LOG.debug("Starting restore snapshot=" + ClientSnapshotDescriptionUtils.toString(snapshot));
    Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshot, rootDir);
    RestoreSnapshotHelper restoreHelper = new RestoreSnapshotHelper(
        masterServices.getConfiguration(), fs,
        snapshot, snapshotDir, hTableDescriptor, rootDir, monitor, status);
    RestoreSnapshotHelper.RestoreMetaChanges metaChanges = restoreHelper.restoreHdfsRegions();

    // 3. Forces all the RegionStates to be offline
    //
    // The AssignmentManager keeps all the region states around
    // with no possibility to remove them, until the master is restarted.
    // This means that a region marked as SPLIT before the restore will never be assigned again.
    // To avoid having all states around all the regions are switched to the OFFLINE state,
    // which is the same state that the regions will be after a delete table.
    forceRegionsOffline(metaChanges);

    // 4. Applies changes to hbase:meta
    status.setStatus("Preparing to restore each region");

    // 4.1 Removes the current set of regions from META
    //
    // By removing also the regions to restore (the ones present both in the snapshot
    // and in the current state) we ensure that no extra fields are present in META
    // e.g. with a simple add addRegionToMeta() the splitA and splitB attributes
    // not overwritten/removed, so you end up with old informations
    // that are not correct after the restore.
    List<HRegionInfo> hrisToRemove = new LinkedList<HRegionInfo>();
    if (metaChanges.hasRegionsToRemove()) hrisToRemove.addAll(metaChanges.getRegionsToRemove());
    MetaEditor.deleteRegions(catalogTracker, hrisToRemove);

    // 4.2 Add the new set of regions to META
    //
    // At this point the old regions are no longer present in META.
    // and the set of regions present in the snapshot will be written to META.
    // All the information in hbase:meta are coming from the .regioninfo of each region present
    // in the snapshot folder.
    hris.clear();
    if (metaChanges.hasRegionsToAdd()) hris.addAll(metaChanges.getRegionsToAdd());
    MetaEditor.addRegionsToMeta(catalogTracker, hris);
    if (metaChanges.hasRegionsToRestore()) {
      MetaEditor.overwriteRegions(catalogTracker, metaChanges.getRegionsToRestore());
    }
    metaChanges.updateMetaParentRegions(catalogTracker, hris);

    // At this point the restore is complete. Next step is enabling the table.
    LOG.info("Restore snapshot=" + ClientSnapshotDescriptionUtils.toString(snapshot) +
      " on table=" + tableName + " completed!");
  } catch (IOException e) {
    String msg = "restore snapshot=" + ClientSnapshotDescriptionUtils.toString(snapshot)
        + " failed. Try re-running the restore command.";
    LOG.error(msg, e);
    monitor.receive(new ForeignException(masterServices.getServerName().toString(), e));
    throw new RestoreSnapshotException(msg, e);
  }
}
项目:HIndex    文件:RestoreSnapshotHandler.java   
private void forceRegionsOffline(final RestoreSnapshotHelper.RestoreMetaChanges metaChanges) {
  forceRegionsOffline(metaChanges.getRegionsToAdd());
  forceRegionsOffline(metaChanges.getRegionsToRestore());
  forceRegionsOffline(metaChanges.getRegionsToRemove());
}
项目:IRIndex    文件:SnapshotManager.java   
/**
 * Restore the specified snapshot
 * @param reqSnapshot
 * @throws IOException
 */
public void restoreSnapshot(SnapshotDescription reqSnapshot) throws IOException {
  FileSystem fs = master.getMasterFileSystem().getFileSystem();
  Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(reqSnapshot, rootDir);
  MasterCoprocessorHost cpHost = master.getCoprocessorHost();

  // check if the snapshot exists
  if (!fs.exists(snapshotDir)) {
    LOG.error("A Snapshot named '" + reqSnapshot.getName() + "' does not exist.");
    throw new SnapshotDoesNotExistException(reqSnapshot);
  }

  // read snapshot information
  SnapshotDescription fsSnapshot = SnapshotDescriptionUtils.readSnapshotInfo(fs, snapshotDir);
  HTableDescriptor snapshotTableDesc = FSTableDescriptors.getTableDescriptor(fs, snapshotDir);
  String tableName = reqSnapshot.getTable();

  // stop tracking "abandoned" handlers
  cleanupSentinels();

  // Verify snapshot validity
  SnapshotReferenceUtil.verifySnapshot(master.getConfiguration(), fs, snapshotDir, fsSnapshot);

  // Execute the restore/clone operation
  if (MetaReader.tableExists(master.getCatalogTracker(), tableName)) {
    if (master.getAssignmentManager().getZKTable().isEnabledTable(fsSnapshot.getTable())) {
      throw new UnsupportedOperationException("Table '" +
        fsSnapshot.getTable() + "' must be disabled in order to perform a restore operation.");
    }

    // call coproc pre hook
    if (cpHost != null) {
      cpHost.preRestoreSnapshot(reqSnapshot, snapshotTableDesc);
    }
    restoreSnapshot(fsSnapshot, snapshotTableDesc);
    LOG.info("Restore snapshot=" + fsSnapshot.getName() + " as table=" + tableName);

    if (cpHost != null) {
      cpHost.postRestoreSnapshot(reqSnapshot, snapshotTableDesc);
    }
  } else {
    HTableDescriptor htd = RestoreSnapshotHelper.cloneTableSchema(snapshotTableDesc,
                                                       Bytes.toBytes(tableName));
    if (cpHost != null) {
      cpHost.preCloneSnapshot(reqSnapshot, htd);
    }
    cloneSnapshot(fsSnapshot, htd);
    LOG.info("Clone snapshot=" + fsSnapshot.getName() + " as table=" + tableName);

    if (cpHost != null) {
      cpHost.postCloneSnapshot(reqSnapshot, htd);
    }
  }
}
项目:IRIndex    文件:RestoreSnapshotHandler.java   
/**
 * The restore table is executed in place.
 *  - The on-disk data will be restored - reference files are put in place without moving data
 *  -  [if something fail here: you need to delete the table and re-run the restore]
 *  - META will be updated
 *  -  [if something fail here: you need to run hbck to fix META entries]
 * The passed in list gets changed in this method
 */
@Override
protected void handleTableOperation(List<HRegionInfo> hris) throws IOException {
  MasterFileSystem fileSystemManager = masterServices.getMasterFileSystem();
  CatalogTracker catalogTracker = masterServices.getCatalogTracker();
  FileSystem fs = fileSystemManager.getFileSystem();
  Path rootDir = fileSystemManager.getRootDir();
  byte[] tableName = hTableDescriptor.getName();
  Path tableDir = HTableDescriptor.getTableDir(rootDir, tableName);

  try {
    // 1. Update descriptor
    this.masterServices.getTableDescriptors().add(hTableDescriptor);

    // 2. Execute the on-disk Restore
    LOG.debug("Starting restore snapshot=" + SnapshotDescriptionUtils.toString(snapshot));
    Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshot, rootDir);
    RestoreSnapshotHelper restoreHelper = new RestoreSnapshotHelper(
        masterServices.getConfiguration(), fs,
        snapshot, snapshotDir, hTableDescriptor, tableDir, monitor, status);
    RestoreSnapshotHelper.RestoreMetaChanges metaChanges = restoreHelper.restoreHdfsRegions();

    // 3. Forces all the RegionStates to be offline
    //
    // The AssignmentManager keeps all the region states around
    // with no possibility to remove them, until the master is restarted.
    // This means that a region marked as SPLIT before the restore will never be assigned again.
    // To avoid having all states around all the regions are switched to the OFFLINE state,
    // which is the same state that the regions will be after a delete table.
    forceRegionsOffline(metaChanges);
    forceRegionsOffline(metaChanges);

    // 4. Applies changes to .META.

    // 4.1 Removes the current set of regions from META
    //
    // By removing also the regions to restore (the ones present both in the snapshot
    // and in the current state) we ensure that no extra fields are present in META
    // e.g. with a simple add addRegionToMeta() the splitA and splitB attributes
    // not overwritten/removed, so you end up with old informations
    // that are not correct after the restore.
    List<HRegionInfo> hrisToRemove = new LinkedList<HRegionInfo>();
    if (metaChanges.hasRegionsToRemove()) hrisToRemove.addAll(metaChanges.getRegionsToRemove());
    MetaEditor.deleteRegions(catalogTracker, hrisToRemove);

    // 4.2 Add the new set of regions to META
    //
    // At this point the old regions are no longer present in META.
    // and the set of regions present in the snapshot will be written to META.
    // All the information in META are coming from the .regioninfo of each region present
    // in the snapshot folder.
    hris.clear();
    if (metaChanges.hasRegionsToAdd()) hris.addAll(metaChanges.getRegionsToAdd());
    MetaEditor.addRegionsToMeta(catalogTracker, hris);
    if (metaChanges.hasRegionsToRestore()) {
      MetaEditor.overwriteRegions(catalogTracker, metaChanges.getRegionsToRestore());
    }
    metaChanges.updateMetaParentRegions(catalogTracker, hris);

    // At this point the restore is complete. Next step is enabling the table.
    LOG.info("Restore snapshot=" + SnapshotDescriptionUtils.toString(snapshot) + " on table=" +
      Bytes.toString(tableName) + " completed!");
  } catch (IOException e) {
    String msg = "restore snapshot=" + SnapshotDescriptionUtils.toString(snapshot)
        + " failed. Try re-running the restore command.";
    LOG.error(msg, e);
    monitor.receive(new ForeignException(masterServices.getServerName().toString(), e));
    throw new RestoreSnapshotException(msg, e);
  } finally {
    this.stopped = true;
  }
}
项目:IRIndex    文件:RestoreSnapshotHandler.java   
private void forceRegionsOffline(final RestoreSnapshotHelper.RestoreMetaChanges metaChanges) {
  forceRegionsOffline(metaChanges.getRegionsToAdd());
  forceRegionsOffline(metaChanges.getRegionsToRestore());
  forceRegionsOffline(metaChanges.getRegionsToRemove());
}
项目:hbase    文件:RestoreSnapshotProcedure.java   
/**
 * Apply changes to hbase:meta
 * @param env MasterProcedureEnv
 * @throws IOException
 **/
private void updateMETA(final MasterProcedureEnv env) throws IOException {
  try {
    Connection conn = env.getMasterServices().getConnection();

    // 1. Prepare to restore
    getMonitorStatus().setStatus("Preparing to restore each region");

    // 2. Applies changes to hbase:meta
    // (2.1). Removes the current set of regions from META
    //
    // By removing also the regions to restore (the ones present both in the snapshot
    // and in the current state) we ensure that no extra fields are present in META
    // e.g. with a simple add addRegionToMeta() the splitA and splitB attributes
    // not overwritten/removed, so you end up with old informations
    // that are not correct after the restore.
    if (regionsToRemove != null) {
      MetaTableAccessor.deleteRegions(conn, regionsToRemove);
    }

    // (2.2). Add the new set of regions to META
    //
    // At this point the old regions are no longer present in META.
    // and the set of regions present in the snapshot will be written to META.
    // All the information in hbase:meta are coming from the .regioninfo of each region present
    // in the snapshot folder.
    if (regionsToAdd != null) {
      MetaTableAccessor.addRegionsToMeta(
        conn,
        regionsToAdd,
        modifiedTableDescriptor.getRegionReplication());
    }

    if (regionsToRestore != null) {
      MetaTableAccessor.overwriteRegions(
        conn,
        regionsToRestore,
        modifiedTableDescriptor.getRegionReplication());
    }

    RestoreSnapshotHelper.RestoreMetaChanges metaChanges =
      new RestoreSnapshotHelper.RestoreMetaChanges(
              modifiedTableDescriptor, parentsToChildrenPairMap);
    metaChanges.updateMetaParentRegions(conn, regionsToAdd);

    // At this point the restore is complete.
    LOG.info("Restore snapshot=" + ClientSnapshotDescriptionUtils.toString(snapshot) +
      " on table=" + getTableName() + " completed!");
  } catch (IOException e) {
    final ForeignExceptionDispatcher monitorException = new ForeignExceptionDispatcher();
    String msg = "restore snapshot=" + ClientSnapshotDescriptionUtils.toString(snapshot)
        + " failed in meta update. Try re-running the restore command.";
    LOG.error(msg, e);
    monitorException.receive(
      new ForeignException(env.getMasterServices().getServerName().toString(), e));
    throw new IOException(msg, e);
  }

  monitorStatus.markComplete("Restore snapshot '"+ snapshot.getName() +"'!");
  MetricsSnapshot metricsSnapshot = new MetricsSnapshot();
  metricsSnapshot.addSnapshotRestore(
    monitorStatus.getCompletionTimestamp() - monitorStatus.getStartTime());
}
项目:hbase    文件:TestTableSnapshotScanner.java   
@Test
public void testScannerWithRestoreScanner() throws Exception {
  setupCluster();
  TableName tableName = TableName.valueOf("testScanner");
  String snapshotName = "testScannerWithRestoreScanner";
  try {
    createTableAndSnapshot(UTIL, tableName, snapshotName, 50);
    Path restoreDir = UTIL.getDataTestDirOnTestFS(snapshotName);
    Scan scan = new Scan(bbb, yyy); // limit the scan

    Configuration conf = UTIL.getConfiguration();
    Path rootDir = FSUtils.getRootDir(conf);

    TableSnapshotScanner scanner0 =
        new TableSnapshotScanner(conf, restoreDir, snapshotName, scan);
    verifyScanner(scanner0, bbb, yyy);
    scanner0.close();

    // restore snapshot.
    RestoreSnapshotHelper.copySnapshotForScanner(conf, fs, rootDir, restoreDir, snapshotName);

    // scan the snapshot without restoring snapshot
    TableSnapshotScanner scanner =
        new TableSnapshotScanner(conf, rootDir, restoreDir, snapshotName, scan, true);
    verifyScanner(scanner, bbb, yyy);
    scanner.close();

    // check whether the snapshot has been deleted by the close of scanner.
    scanner = new TableSnapshotScanner(conf, rootDir, restoreDir, snapshotName, scan, true);
    verifyScanner(scanner, bbb, yyy);
    scanner.close();

    // restore snapshot again.
    RestoreSnapshotHelper.copySnapshotForScanner(conf, fs, rootDir, restoreDir, snapshotName);

    // check whether the snapshot has been deleted by the close of scanner.
    scanner = new TableSnapshotScanner(conf, rootDir, restoreDir, snapshotName, scan, true);
    verifyScanner(scanner, bbb, yyy);
    scanner.close();
  } finally {
    UTIL.getAdmin().deleteSnapshot(snapshotName);
    UTIL.deleteTable(tableName);
    tearDownCluster();
  }
}
项目:hbase    文件:MultiTableSnapshotInputFormatImpl.java   
void restoreSnapshot(Configuration conf, String snapshotName, Path rootDir, Path restoreDir,
    FileSystem fs) throws IOException {
  RestoreSnapshotHelper.copySnapshotForScanner(conf, fs, rootDir, restoreDir, snapshotName);
}
项目:PyroDB    文件:SnapshotManager.java   
/**
 * Restore the specified snapshot
 * @param reqSnapshot
 * @throws IOException
 */
public void restoreSnapshot(SnapshotDescription reqSnapshot) throws IOException {
  FileSystem fs = master.getMasterFileSystem().getFileSystem();
  Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(reqSnapshot, rootDir);
  MasterCoprocessorHost cpHost = master.getMasterCoprocessorHost();

  // check if the snapshot exists
  if (!fs.exists(snapshotDir)) {
    LOG.error("A Snapshot named '" + reqSnapshot.getName() + "' does not exist.");
    throw new SnapshotDoesNotExistException(reqSnapshot);
  }

  // read snapshot information
  SnapshotDescription fsSnapshot = SnapshotDescriptionUtils.readSnapshotInfo(fs, snapshotDir);
  SnapshotManifest manifest = SnapshotManifest.open(master.getConfiguration(), fs,
      snapshotDir, fsSnapshot);
  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
  if (MetaReader.tableExists(master.getCatalogTracker(), tableName)) {
    if (master.getAssignmentManager().getTableStateManager().isTableState(
        TableName.valueOf(fsSnapshot.getTable()), ZooKeeperProtos.Table.State.ENABLED)) {
      throw new UnsupportedOperationException("Table '" +
          TableName.valueOf(fsSnapshot.getTable()) + "' must be disabled in order to " +
          "perform a restore operation" +
          ".");
    }

    // call coproc pre hook
    if (cpHost != null) {
      cpHost.preRestoreSnapshot(reqSnapshot, snapshotTableDesc);
    }
    restoreSnapshot(fsSnapshot, snapshotTableDesc);
    LOG.info("Restore snapshot=" + fsSnapshot.getName() + " as table=" + tableName);

    if (cpHost != null) {
      cpHost.postRestoreSnapshot(reqSnapshot, snapshotTableDesc);
    }
  } else {
    HTableDescriptor htd = RestoreSnapshotHelper.cloneTableSchema(snapshotTableDesc, tableName);
    if (cpHost != null) {
      cpHost.preCloneSnapshot(reqSnapshot, htd);
    }
    cloneSnapshot(fsSnapshot, htd);
    LOG.info("Clone snapshot=" + fsSnapshot.getName() + " as table=" + tableName);

    if (cpHost != null) {
      cpHost.postCloneSnapshot(reqSnapshot, htd);
    }
  }
}
项目:PyroDB    文件:RestoreSnapshotHandler.java   
/**
 * The restore table is executed in place.
 *  - The on-disk data will be restored - reference files are put in place without moving data
 *  -  [if something fail here: you need to delete the table and re-run the restore]
 *  - hbase:meta will be updated
 *  -  [if something fail here: you need to run hbck to fix hbase:meta entries]
 * The passed in list gets changed in this method
 */
@Override
protected void handleTableOperation(List<HRegionInfo> hris) throws IOException {
  MasterFileSystem fileSystemManager = masterServices.getMasterFileSystem();
  CatalogTracker catalogTracker = masterServices.getCatalogTracker();
  FileSystem fs = fileSystemManager.getFileSystem();
  Path rootDir = fileSystemManager.getRootDir();
  TableName tableName = hTableDescriptor.getTableName();

  try {
    // 1. Update descriptor
    this.masterServices.getTableDescriptors().add(hTableDescriptor);

    // 2. Execute the on-disk Restore
    LOG.debug("Starting restore snapshot=" + ClientSnapshotDescriptionUtils.toString(snapshot));
    Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshot, rootDir);
    SnapshotManifest manifest = SnapshotManifest.open(masterServices.getConfiguration(), fs,
                                                      snapshotDir, snapshot);
    RestoreSnapshotHelper restoreHelper = new RestoreSnapshotHelper(
        masterServices.getConfiguration(), fs, manifest,
        this.hTableDescriptor, rootDir, monitor, status);
    RestoreSnapshotHelper.RestoreMetaChanges metaChanges = restoreHelper.restoreHdfsRegions();

    // 3. Forces all the RegionStates to be offline
    //
    // The AssignmentManager keeps all the region states around
    // with no possibility to remove them, until the master is restarted.
    // This means that a region marked as SPLIT before the restore will never be assigned again.
    // To avoid having all states around all the regions are switched to the OFFLINE state,
    // which is the same state that the regions will be after a delete table.
    forceRegionsOffline(metaChanges);

    // 4. Applies changes to hbase:meta
    status.setStatus("Preparing to restore each region");

    // 4.1 Removes the current set of regions from META
    //
    // By removing also the regions to restore (the ones present both in the snapshot
    // and in the current state) we ensure that no extra fields are present in META
    // e.g. with a simple add addRegionToMeta() the splitA and splitB attributes
    // not overwritten/removed, so you end up with old informations
    // that are not correct after the restore.
    List<HRegionInfo> hrisToRemove = new LinkedList<HRegionInfo>();
    if (metaChanges.hasRegionsToRemove()) hrisToRemove.addAll(metaChanges.getRegionsToRemove());
    MetaEditor.deleteRegions(catalogTracker, hrisToRemove);

    // 4.2 Add the new set of regions to META
    //
    // At this point the old regions are no longer present in META.
    // and the set of regions present in the snapshot will be written to META.
    // All the information in hbase:meta are coming from the .regioninfo of each region present
    // in the snapshot folder.
    hris.clear();
    if (metaChanges.hasRegionsToAdd()) hris.addAll(metaChanges.getRegionsToAdd());
    MetaEditor.addRegionsToMeta(catalogTracker, hris);
    if (metaChanges.hasRegionsToRestore()) {
      MetaEditor.overwriteRegions(catalogTracker, metaChanges.getRegionsToRestore());
    }
    metaChanges.updateMetaParentRegions(catalogTracker, hris);

    // At this point the restore is complete. Next step is enabling the table.
    LOG.info("Restore snapshot=" + ClientSnapshotDescriptionUtils.toString(snapshot) +
      " on table=" + tableName + " completed!");
  } catch (IOException e) {
    String msg = "restore snapshot=" + ClientSnapshotDescriptionUtils.toString(snapshot)
        + " failed. Try re-running the restore command.";
    LOG.error(msg, e);
    monitor.receive(new ForeignException(masterServices.getServerName().toString(), e));
    throw new RestoreSnapshotException(msg, e);
  }
}
项目:PyroDB    文件:RestoreSnapshotHandler.java   
private void forceRegionsOffline(final RestoreSnapshotHelper.RestoreMetaChanges metaChanges) {
  forceRegionsOffline(metaChanges.getRegionsToAdd());
  forceRegionsOffline(metaChanges.getRegionsToRestore());
  forceRegionsOffline(metaChanges.getRegionsToRemove());
}
项目:c5    文件:SnapshotManager.java   
/**
 * Restore the specified snapshot
 * @param reqSnapshot
 * @throws IOException
 */
public void restoreSnapshot(SnapshotDescription reqSnapshot) throws IOException {
  FileSystem fs = master.getMasterFileSystem().getFileSystem();
  Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(reqSnapshot, rootDir);
  MasterCoprocessorHost cpHost = master.getCoprocessorHost();

  // check if the snapshot exists
  if (!fs.exists(snapshotDir)) {
    LOG.error("A Snapshot named '" + reqSnapshot.getName() + "' does not exist.");
    throw new SnapshotDoesNotExistException(reqSnapshot);
  }

  // read snapshot information
  SnapshotDescription fsSnapshot = SnapshotDescriptionUtils.readSnapshotInfo(fs, snapshotDir);
  HTableDescriptor snapshotTableDesc =
      FSTableDescriptors.getTableDescriptorFromFs(fs, snapshotDir);
  TableName tableName = TableName.valueOf(reqSnapshot.getTable());

  // stop tracking "abandoned" handlers
  cleanupSentinels();

  // Execute the restore/clone operation
  if (MetaReader.tableExists(master.getCatalogTracker(), tableName)) {
    if (master.getAssignmentManager().getZKTable().isEnabledTable(
        TableName.valueOf(fsSnapshot.getTable()))) {
      throw new UnsupportedOperationException("Table '" +
          TableName.valueOf(fsSnapshot.getTable()) + "' must be disabled in order to " +
          "perform a restore operation" +
          ".");
    }

    // call coproc pre hook
    if (cpHost != null) {
      cpHost.preRestoreSnapshot(reqSnapshot, snapshotTableDesc);
    }
    restoreSnapshot(fsSnapshot, snapshotTableDesc);
    LOG.info("Restore snapshot=" + fsSnapshot.getName() + " as table=" + tableName);

    if (cpHost != null) {
      cpHost.postRestoreSnapshot(reqSnapshot, snapshotTableDesc);
    }
  } else {
    HTableDescriptor htd = RestoreSnapshotHelper.cloneTableSchema(snapshotTableDesc, tableName);
    if (cpHost != null) {
      cpHost.preCloneSnapshot(reqSnapshot, htd);
    }
    cloneSnapshot(fsSnapshot, htd);
    LOG.info("Clone snapshot=" + fsSnapshot.getName() + " as table=" + tableName);

    if (cpHost != null) {
      cpHost.postCloneSnapshot(reqSnapshot, htd);
    }
  }
}
项目:c5    文件:RestoreSnapshotHandler.java   
/**
 * The restore table is executed in place.
 *  - The on-disk data will be restored - reference files are put in place without moving data
 *  -  [if something fail here: you need to delete the table and re-run the restore]
 *  - hbase:meta will be updated
 *  -  [if something fail here: you need to run hbck to fix hbase:meta entries]
 * The passed in list gets changed in this method
 */
@Override
protected void handleTableOperation(List<HRegionInfo> hris) throws IOException {
  MasterFileSystem fileSystemManager = masterServices.getMasterFileSystem();
  CatalogTracker catalogTracker = masterServices.getCatalogTracker();
  FileSystem fs = fileSystemManager.getFileSystem();
  Path rootDir = fileSystemManager.getRootDir();
  TableName tableName = hTableDescriptor.getTableName();

  try {
    // 1. Update descriptor
    this.masterServices.getTableDescriptors().add(hTableDescriptor);

    // 2. Execute the on-disk Restore
    LOG.debug("Starting restore snapshot=" + ClientSnapshotDescriptionUtils.toString(snapshot));
    Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshot, rootDir);
    RestoreSnapshotHelper restoreHelper = new RestoreSnapshotHelper(
        masterServices.getConfiguration(), fs,
        snapshot, snapshotDir, hTableDescriptor, rootDir, monitor, status);
    RestoreSnapshotHelper.RestoreMetaChanges metaChanges = restoreHelper.restoreHdfsRegions();

    // 3. Forces all the RegionStates to be offline
    //
    // The AssignmentManager keeps all the region states around
    // with no possibility to remove them, until the master is restarted.
    // This means that a region marked as SPLIT before the restore will never be assigned again.
    // To avoid having all states around all the regions are switched to the OFFLINE state,
    // which is the same state that the regions will be after a delete table.
    forceRegionsOffline(metaChanges);

    // 4. Applies changes to hbase:meta
    status.setStatus("Preparing to restore each region");

    // 4.1 Removes the current set of regions from META
    //
    // By removing also the regions to restore (the ones present both in the snapshot
    // and in the current state) we ensure that no extra fields are present in META
    // e.g. with a simple add addRegionToMeta() the splitA and splitB attributes
    // not overwritten/removed, so you end up with old informations
    // that are not correct after the restore.
    List<HRegionInfo> hrisToRemove = new LinkedList<HRegionInfo>();
    if (metaChanges.hasRegionsToRemove()) hrisToRemove.addAll(metaChanges.getRegionsToRemove());
    MetaEditor.deleteRegions(catalogTracker, hrisToRemove);

    // 4.2 Add the new set of regions to META
    //
    // At this point the old regions are no longer present in META.
    // and the set of regions present in the snapshot will be written to META.
    // All the information in hbase:meta are coming from the .regioninfo of each region present
    // in the snapshot folder.
    hris.clear();
    if (metaChanges.hasRegionsToAdd()) hris.addAll(metaChanges.getRegionsToAdd());
    MetaEditor.addRegionsToMeta(catalogTracker, hris);
    if (metaChanges.hasRegionsToRestore()) {
      MetaEditor.overwriteRegions(catalogTracker, metaChanges.getRegionsToRestore());
    }
    metaChanges.updateMetaParentRegions(catalogTracker, hris);

    // At this point the restore is complete. Next step is enabling the table.
    LOG.info("Restore snapshot=" + ClientSnapshotDescriptionUtils.toString(snapshot) +
      " on table=" + tableName + " completed!");
  } catch (IOException e) {
    String msg = "restore snapshot=" + ClientSnapshotDescriptionUtils.toString(snapshot)
        + " failed. Try re-running the restore command.";
    LOG.error(msg, e);
    monitor.receive(new ForeignException(masterServices.getServerName().toString(), e));
    throw new RestoreSnapshotException(msg, e);
  }
}
项目:c5    文件:RestoreSnapshotHandler.java   
private void forceRegionsOffline(final RestoreSnapshotHelper.RestoreMetaChanges metaChanges) {
  forceRegionsOffline(metaChanges.getRegionsToAdd());
  forceRegionsOffline(metaChanges.getRegionsToRestore());
  forceRegionsOffline(metaChanges.getRegionsToRemove());
}
项目:HBase-Research    文件:SnapshotManager.java   
/**
 * Restore the specified snapshot
 * @param reqSnapshot
 * @throws IOException
 */
public void restoreSnapshot(SnapshotDescription reqSnapshot) throws IOException {
  FileSystem fs = master.getMasterFileSystem().getFileSystem();
  Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(reqSnapshot, rootDir);
  MasterCoprocessorHost cpHost = master.getCoprocessorHost();

  // check if the snapshot exists
  if (!fs.exists(snapshotDir)) {
    LOG.error("A Snapshot named '" + reqSnapshot.getName() + "' does not exist.");
    throw new SnapshotDoesNotExistException(reqSnapshot);
  }

  // read snapshot information
  SnapshotDescription fsSnapshot = SnapshotDescriptionUtils.readSnapshotInfo(fs, snapshotDir);
  HTableDescriptor snapshotTableDesc = FSTableDescriptors.getTableDescriptor(fs, snapshotDir);
  String tableName = reqSnapshot.getTable();

  // stop tracking "abandoned" handlers
  cleanupSentinels();

  // Execute the restore/clone operation
  if (MetaReader.tableExists(master.getCatalogTracker(), tableName)) {
    if (master.getAssignmentManager().getZKTable().isEnabledTable(fsSnapshot.getTable())) {
      throw new UnsupportedOperationException("Table '" +
        fsSnapshot.getTable() + "' must be disabled in order to perform a restore operation.");
    }

    // call coproc pre hook
    if (cpHost != null) {
      cpHost.preRestoreSnapshot(reqSnapshot, snapshotTableDesc);
    }
    restoreSnapshot(fsSnapshot, snapshotTableDesc);
    LOG.info("Restore snapshot=" + fsSnapshot.getName() + " as table=" + tableName);

    if (cpHost != null) {
      cpHost.postRestoreSnapshot(reqSnapshot, snapshotTableDesc);
    }
  } else {
    HTableDescriptor htd = RestoreSnapshotHelper.cloneTableSchema(snapshotTableDesc,
                                                       Bytes.toBytes(tableName));
    if (cpHost != null) {
      cpHost.preCloneSnapshot(reqSnapshot, htd);
    }
    cloneSnapshot(fsSnapshot, htd);
    LOG.info("Clone snapshot=" + fsSnapshot.getName() + " as table=" + tableName);

    if (cpHost != null) {
      cpHost.postCloneSnapshot(reqSnapshot, htd);
    }
  }
}
项目:HBase-Research    文件:RestoreSnapshotHandler.java   
/**
 * The restore table is executed in place.
 *  - The on-disk data will be restored - reference files are put in place without moving data
 *  -  [if something fail here: you need to delete the table and re-run the restore]
 *  - META will be updated
 *  -  [if something fail here: you need to run hbck to fix META entries]
 * The passed in list gets changed in this method
 */
@Override
protected void handleTableOperation(List<HRegionInfo> hris) throws IOException {
  MasterFileSystem fileSystemManager = masterServices.getMasterFileSystem();
  CatalogTracker catalogTracker = masterServices.getCatalogTracker();
  FileSystem fs = fileSystemManager.getFileSystem();
  Path rootDir = fileSystemManager.getRootDir();
  byte[] tableName = hTableDescriptor.getName();
  Path tableDir = HTableDescriptor.getTableDir(rootDir, tableName);

  try {
    // 1. Update descriptor
    this.masterServices.getTableDescriptors().add(hTableDescriptor);

    // 2. Execute the on-disk Restore
    LOG.debug("Starting restore snapshot=" + SnapshotDescriptionUtils.toString(snapshot));
    Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshot, rootDir);
    RestoreSnapshotHelper restoreHelper = new RestoreSnapshotHelper(
        masterServices.getConfiguration(), fs,
        snapshot, snapshotDir, hTableDescriptor, tableDir, monitor, status);
    RestoreSnapshotHelper.RestoreMetaChanges metaChanges = restoreHelper.restoreHdfsRegions();

    // 3. Applies changes to .META.
    hris.clear();
    status.setStatus("Preparing to restore each region");
    if (metaChanges.hasRegionsToAdd()) hris.addAll(metaChanges.getRegionsToAdd());
    if (metaChanges.hasRegionsToRestore()) hris.addAll(metaChanges.getRegionsToRestore());
    List<HRegionInfo> hrisToRemove = metaChanges.getRegionsToRemove();
    MetaEditor.mutateRegions(catalogTracker, hrisToRemove, hris);

    // At this point the restore is complete. Next step is enabling the table.
    LOG.info("Restore snapshot=" + SnapshotDescriptionUtils.toString(snapshot) + " on table=" +
      Bytes.toString(tableName) + " completed!");
  } catch (IOException e) {
    String msg = "restore snapshot=" + SnapshotDescriptionUtils.toString(snapshot)
        + " failed. Try re-running the restore command.";
    LOG.error(msg, e);
    monitor.receive(new ForeignException(masterServices.getServerName().toString(), e));
    throw new RestoreSnapshotException(msg, e);
  } finally {
    this.stopped = true;
  }
}