Search in sources :

Example 6 with InconsistentFSStateException

use of org.apache.hadoop.hdfs.server.common.InconsistentFSStateException in project hadoop by apache.

the class DataStorage method doRollback.

/** 
   * Rolling back to a snapshot in previous directory by moving it to current
   * directory.
   * Rollback procedure:
   * <br>
   * If previous directory exists:
   * <ol>
   * <li> Rename current to removed.tmp </li>
   * <li> Rename previous to current </li>
   * <li> Remove removed.tmp </li>
   * </ol>
   * 
   * If previous directory does not exist and the current version supports
   * federation, perform a simple rollback of layout version. This does not
   * involve saving/restoration of actual data.
   */
void doRollback(StorageDirectory sd, NamespaceInfo nsInfo) throws IOException {
    File prevDir = sd.getPreviousDir();
    // This is a regular startup or a post-federation rollback
    if (!prevDir.exists()) {
        if (DataNodeLayoutVersion.supports(LayoutVersion.Feature.FEDERATION, HdfsServerConstants.DATANODE_LAYOUT_VERSION)) {
            readProperties(sd, HdfsServerConstants.DATANODE_LAYOUT_VERSION);
            writeProperties(sd);
            LOG.info("Layout version rolled back to " + HdfsServerConstants.DATANODE_LAYOUT_VERSION + " for storage " + sd.getRoot());
        }
        return;
    }
    DataStorage prevInfo = new DataStorage();
    prevInfo.readPreviousVersionProperties(sd);
    // the namespace state or can be further upgraded to it.
    if (!(prevInfo.getLayoutVersion() >= HdfsServerConstants.DATANODE_LAYOUT_VERSION && // cannot rollback
    prevInfo.getCTime() <= nsInfo.getCTime()))
        throw new InconsistentFSStateException(sd.getRoot(), "Cannot rollback to a newer state.\nDatanode previous state: LV = " + prevInfo.getLayoutVersion() + " CTime = " + prevInfo.getCTime() + " is newer than the namespace state: LV = " + HdfsServerConstants.DATANODE_LAYOUT_VERSION + " CTime = " + nsInfo.getCTime());
    LOG.info("Rolling back storage directory " + sd.getRoot() + ".\n   target LV = " + HdfsServerConstants.DATANODE_LAYOUT_VERSION + "; target CTime = " + nsInfo.getCTime());
    File tmpDir = sd.getRemovedTmp();
    assert !tmpDir.exists() : "removed.tmp directory must not exist.";
    // rename current to tmp
    File curDir = sd.getCurrentDir();
    assert curDir.exists() : "Current directory must exist.";
    rename(curDir, tmpDir);
    // rename previous to current
    rename(prevDir, curDir);
    // delete tmp dir
    deleteDir(tmpDir);
    LOG.info("Rollback of " + sd.getRoot() + " is complete");
}
Also used : RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) InconsistentFSStateException(org.apache.hadoop.hdfs.server.common.InconsistentFSStateException)

Example 7 with InconsistentFSStateException

use of org.apache.hadoop.hdfs.server.common.InconsistentFSStateException in project hadoop by apache.

the class BackupImage method recoverCreateRead.

/**
   * Analyze backup storage directories for consistency.<br>
   * Recover from incomplete checkpoints if required.<br>
   * Read VERSION and fstime files if exist.<br>
   * Do not load image or edits.
   *
   * @throws IOException if the node should shutdown.
   */
void recoverCreateRead() throws IOException {
    for (Iterator<StorageDirectory> it = storage.dirIterator(); it.hasNext(); ) {
        StorageDirectory sd = it.next();
        StorageState curState;
        try {
            curState = sd.analyzeStorage(HdfsServerConstants.StartupOption.REGULAR, storage);
            // sd is locked but not opened
            switch(curState) {
                case NON_EXISTENT:
                    // fail if any of the configured storage dirs are inaccessible
                    throw new InconsistentFSStateException(sd.getRoot(), "checkpoint directory does not exist or is not accessible.");
                case NOT_FORMATTED:
                    // for backup node all directories may be unformatted initially
                    LOG.info("Storage directory " + sd.getRoot() + " is not formatted.");
                    LOG.info("Formatting ...");
                    // create empty current
                    sd.clearDirectory();
                    break;
                case NORMAL:
                    break;
                default:
                    // recovery is possible
                    sd.doRecover(curState);
            }
            if (curState != StorageState.NOT_FORMATTED) {
                // read and verify consistency with other directories
                storage.readProperties(sd);
            }
        } catch (IOException ioe) {
            sd.unlock();
            throw ioe;
        }
    }
}
Also used : StorageState(org.apache.hadoop.hdfs.server.common.Storage.StorageState) StorageDirectory(org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory) IOException(java.io.IOException) InconsistentFSStateException(org.apache.hadoop.hdfs.server.common.InconsistentFSStateException)

Example 8 with InconsistentFSStateException

use of org.apache.hadoop.hdfs.server.common.InconsistentFSStateException in project hadoop by apache.

the class FSImage method loadFSImageFile.

void loadFSImageFile(FSNamesystem target, MetaRecoveryContext recovery, FSImageFile imageFile, StartupOption startupOption) throws IOException {
    LOG.info("Planning to load image: " + imageFile);
    StorageDirectory sdForProperties = imageFile.sd;
    storage.readProperties(sdForProperties, startupOption);
    if (NameNodeLayoutVersion.supports(LayoutVersion.Feature.TXID_BASED_LAYOUT, getLayoutVersion())) {
        // For txid-based layout, we should have a .md5 file
        // next to the image file
        boolean isRollingRollback = RollingUpgradeStartupOption.ROLLBACK.matches(startupOption);
        loadFSImage(imageFile.getFile(), target, recovery, isRollingRollback);
    } else if (NameNodeLayoutVersion.supports(LayoutVersion.Feature.FSIMAGE_CHECKSUM, getLayoutVersion())) {
        // In 0.22, we have the checksum stored in the VERSION file.
        String md5 = storage.getDeprecatedProperty(NNStorage.DEPRECATED_MESSAGE_DIGEST_PROPERTY);
        if (md5 == null) {
            throw new InconsistentFSStateException(sdForProperties.getRoot(), "Message digest property " + NNStorage.DEPRECATED_MESSAGE_DIGEST_PROPERTY + " not set for storage directory " + sdForProperties.getRoot());
        }
        loadFSImage(imageFile.getFile(), new MD5Hash(md5), target, recovery, false);
    } else {
        // We don't have any record of the md5sum
        loadFSImage(imageFile.getFile(), null, target, recovery, false);
    }
}
Also used : MD5Hash(org.apache.hadoop.io.MD5Hash) StorageDirectory(org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory) InconsistentFSStateException(org.apache.hadoop.hdfs.server.common.InconsistentFSStateException)

Aggregations

InconsistentFSStateException (org.apache.hadoop.hdfs.server.common.InconsistentFSStateException)8 StorageDirectory (org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory)4 File (java.io.File)3 IOException (java.io.IOException)3 StorageState (org.apache.hadoop.hdfs.server.common.Storage.StorageState)3 RandomAccessFile (java.io.RandomAccessFile)1 URI (java.net.URI)1 HashMap (java.util.HashMap)1 MiniDFSCluster (org.apache.hadoop.hdfs.MiniDFSCluster)1 Util.fileAsURI (org.apache.hadoop.hdfs.server.common.Util.fileAsURI)1 NameNodeFile (org.apache.hadoop.hdfs.server.namenode.NNStorage.NameNodeFile)1 MD5Hash (org.apache.hadoop.io.MD5Hash)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Test (org.junit.Test)1