Java Code Examples for org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory#getPreviousTmp()

The following examples show how to use org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory#getPreviousTmp() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NNUpgradeUtil.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Perform any steps that must succeed across all storage dirs/JournalManagers
 * involved in an upgrade before proceeding onto the actual upgrade stage. If
 * a call to any JM's or local storage dir's doPreUpgrade method fails, then
 * doUpgrade will not be called for any JM. The existing current dir is
 * renamed to previous.tmp, and then a new, empty current dir is created.
 *
 * @param conf configuration for creating {@link EditLogFileOutputStream}
 * @param sd the storage directory to perform the pre-upgrade procedure.
 * @throws IOException in the event of error
 */
static void doPreUpgrade(Configuration conf, StorageDirectory sd)
    throws IOException {
  LOG.info("Starting upgrade of storage directory " + sd.getRoot());

  // rename current to tmp
  renameCurToTmp(sd);

  final File curDir = sd.getCurrentDir();
  final File tmpDir = sd.getPreviousTmp();
  List<String> fileNameList = IOUtils.listDirectory(tmpDir, new FilenameFilter() {
    @Override
    public boolean accept(File dir, String name) {
      return dir.equals(tmpDir)
          && name.startsWith(NNStorage.NameNodeFile.EDITS.getName());
    }
  });

  for (String s : fileNameList) {
    File prevFile = new File(tmpDir, s);
    File newFile = new File(curDir, prevFile.getName());
    Files.createLink(newFile.toPath(), prevFile.toPath());
  }
}
 
Example 2
Source File: NNUpgradeUtil.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Rename the existing current dir to previous.tmp, and create a new empty
 * current dir.
 */
public static void renameCurToTmp(StorageDirectory sd) throws IOException {
  File curDir = sd.getCurrentDir();
  File prevDir = sd.getPreviousDir();
  final File tmpDir = sd.getPreviousTmp();

  Preconditions.checkState(curDir.exists(),
      "Current directory must exist for preupgrade.");
  Preconditions.checkState(!prevDir.exists(),
      "Previous directory must not exist for preupgrade.");
  Preconditions.checkState(!tmpDir.exists(),
      "Previous.tmp directory must not exist for preupgrade."
          + "Consider restarting for recovery.");

  // rename current to tmp
  NNStorage.rename(curDir, tmpDir);

  if (!curDir.mkdir()) {
    throw new IOException("Cannot create directory " + curDir);
  }
}
 
Example 3
Source File: NNUpgradeUtil.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Perform the upgrade of the storage dir to the given storage info. The new
 * storage info is written into the current directory, and the previous.tmp
 * directory is renamed to previous.
 * 
 * @param sd the storage directory to upgrade
 * @param storage info about the new upgraded versions.
 * @throws IOException in the event of error
 */
public static void doUpgrade(StorageDirectory sd, Storage storage)
    throws IOException {
  LOG.info("Performing upgrade of storage directory " + sd.getRoot());
  try {
    // Write the version file, since saveFsImage only makes the
    // fsimage_<txid>, and the directory is otherwise empty.
    storage.writeProperties(sd);

    File prevDir = sd.getPreviousDir();
    File tmpDir = sd.getPreviousTmp();
    Preconditions.checkState(!prevDir.exists(),
        "previous directory must not exist for upgrade.");
    Preconditions.checkState(tmpDir.exists(),
        "previous.tmp directory must exist for upgrade.");

    // rename tmp to previous
    NNStorage.rename(tmpDir, prevDir);
  } catch (IOException ioe) {
    LOG.error("Unable to rename temp to previous for " + sd.getRoot(), ioe);
    throw ioe;
  }
}
 
Example 4
Source File: NNUpgradeUtil.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Rename the existing current dir to previous.tmp, and create a new empty
 * current dir.
 */
public static void renameCurToTmp(StorageDirectory sd) throws IOException {
  File curDir = sd.getCurrentDir();
  File prevDir = sd.getPreviousDir();
  final File tmpDir = sd.getPreviousTmp();

  Preconditions.checkState(curDir.exists(),
      "Current directory must exist for preupgrade.");
  Preconditions.checkState(!prevDir.exists(),
      "Previous directory must not exist for preupgrade.");
  Preconditions.checkState(!tmpDir.exists(),
      "Previous.tmp directory must not exist for preupgrade."
          + "Consider restarting for recovery.");

  // rename current to tmp
  NNStorage.rename(curDir, tmpDir);

  if (!curDir.mkdir()) {
    throw new IOException("Cannot create directory " + curDir);
  }
}
 
Example 5
Source File: NNUpgradeUtil.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Perform the upgrade of the storage dir to the given storage info. The new
 * storage info is written into the current directory, and the previous.tmp
 * directory is renamed to previous.
 * 
 * @param sd the storage directory to upgrade
 * @param storage info about the new upgraded versions.
 * @throws IOException in the event of error
 */
public static void doUpgrade(StorageDirectory sd, Storage storage)
    throws IOException {
  LOG.info("Performing upgrade of storage directory " + sd.getRoot());
  try {
    // Write the version file, since saveFsImage only makes the
    // fsimage_<txid>, and the directory is otherwise empty.
    storage.writeProperties(sd);

    File prevDir = sd.getPreviousDir();
    File tmpDir = sd.getPreviousTmp();
    Preconditions.checkState(!prevDir.exists(),
        "previous directory must not exist for upgrade.");
    Preconditions.checkState(tmpDir.exists(),
        "previous.tmp directory must exist for upgrade.");

    // rename tmp to previous
    NNStorage.rename(tmpDir, prevDir);
  } catch (IOException ioe) {
    LOG.error("Unable to rename temp to previous for " + sd.getRoot(), ioe);
    throw ioe;
  }
}
 
Example 6
Source File: NNUpgradeUtil.java    From big-c with Apache License 2.0 3 votes vote down vote up
/**
 * Perform any steps that must succeed across all storage dirs/JournalManagers
 * involved in an upgrade before proceeding onto the actual upgrade stage. If
 * a call to any JM's or local storage dir's doPreUpgrade method fails, then
 * doUpgrade will not be called for any JM. The existing current dir is
 * renamed to previous.tmp, and then a new, empty current dir is created.
 *
 * @param conf configuration for creating {@link EditLogFileOutputStream}
 * @param sd the storage directory to perform the pre-upgrade procedure.
 * @throws IOException in the event of error
 */
static void doPreUpgrade(Configuration conf, StorageDirectory sd)
    throws IOException {
  LOG.info("Starting upgrade of storage directory " + sd.getRoot());

  // rename current to tmp
  renameCurToTmp(sd);

  final File curDir = sd.getCurrentDir();
  final File tmpDir = sd.getPreviousTmp();
  List<String> fileNameList = IOUtils.listDirectory(tmpDir, new FilenameFilter() {
    @Override
    public boolean accept(File dir, String name) {
      return dir.equals(tmpDir)
          && name.startsWith(NNStorage.NameNodeFile.EDITS.getName());
    }
  });

  for (String s : fileNameList) {
    File prevFile = new File(tmpDir, s);
    File newFile = new File(curDir, prevFile.getName());
    Files.createLink(newFile.toPath(), prevFile.toPath());
  }
}