Search in sources :

Example 31 with StorageDirectory

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

the class FSImage method saveDigestAndRenameCheckpointImage.

/**
   * This is called by the 2NN after having downloaded an image, and by
   * the NN after having received a new image from the 2NN. It
   * renames the image from fsimage_N.ckpt to fsimage_N and also
   * saves the related .md5 file into place.
   */
public synchronized void saveDigestAndRenameCheckpointImage(NameNodeFile nnf, long txid, MD5Hash digest) throws IOException {
    // Write and rename MD5 file
    List<StorageDirectory> badSds = Lists.newArrayList();
    for (StorageDirectory sd : storage.dirIterable(NameNodeDirType.IMAGE)) {
        File imageFile = NNStorage.getImageFile(sd, nnf, txid);
        try {
            MD5FileUtils.saveMD5File(imageFile, digest);
        } catch (IOException ioe) {
            badSds.add(sd);
        }
    }
    storage.reportErrorsOnDirectories(badSds);
    CheckpointFaultInjector.getInstance().afterMD5Rename();
    // Rename image from tmp file
    renameCheckpoint(txid, NameNodeFile.IMAGE_NEW, nnf, false);
    // from now on
    if (txid > storage.getMostRecentCheckpointTxId()) {
        storage.setMostRecentCheckpointInfo(txid, Time.now());
    }
}
Also used : StorageDirectory(org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory) IOException(java.io.IOException) NameNodeFile(org.apache.hadoop.hdfs.server.namenode.NNStorage.NameNodeFile) FSImageFile(org.apache.hadoop.hdfs.server.namenode.FSImageStorageInspector.FSImageFile) File(java.io.File)

Example 32 with StorageDirectory

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

the class FSImage method saveFSImageInAllDirs.

private synchronized void saveFSImageInAllDirs(FSNamesystem source, NameNodeFile nnf, long txid, Canceler canceler) throws IOException {
    StartupProgress prog = NameNode.getStartupProgress();
    prog.beginPhase(Phase.SAVING_CHECKPOINT);
    if (storage.getNumStorageDirs(NameNodeDirType.IMAGE) == 0) {
        throw new IOException("No image directories available!");
    }
    if (canceler == null) {
        canceler = new Canceler();
    }
    SaveNamespaceContext ctx = new SaveNamespaceContext(source, txid, canceler);
    try {
        List<Thread> saveThreads = new ArrayList<Thread>();
        // save images into current
        for (Iterator<StorageDirectory> it = storage.dirIterator(NameNodeDirType.IMAGE); it.hasNext(); ) {
            StorageDirectory sd = it.next();
            FSImageSaver saver = new FSImageSaver(ctx, sd, nnf);
            Thread saveThread = new Thread(saver, saver.toString());
            saveThreads.add(saveThread);
            saveThread.start();
        }
        waitForThreads(saveThreads);
        saveThreads.clear();
        storage.reportErrorsOnDirectories(ctx.getErrorSDs());
        if (storage.getNumStorageDirs(NameNodeDirType.IMAGE) == 0) {
            throw new IOException("Failed to save in any storage directories while saving namespace.");
        }
        if (canceler.isCancelled()) {
            deleteCancelledCheckpoint(txid);
            // throws
            ctx.checkCancelled();
            assert false : "should have thrown above!";
        }
        renameCheckpoint(txid, NameNodeFile.IMAGE_NEW, nnf, false);
        // Since we now have a new checkpoint, we can clean up some
        // old edit logs and checkpoints.
        purgeOldStorage(nnf);
        archivalManager.purgeCheckpoints(NameNodeFile.IMAGE_NEW);
    } finally {
        // Notify any threads waiting on the checkpoint to be canceled
        // that it is complete.
        ctx.markComplete();
        ctx = null;
    }
    prog.endPhase(Phase.SAVING_CHECKPOINT);
}
Also used : Canceler(org.apache.hadoop.hdfs.util.Canceler) ArrayList(java.util.ArrayList) IOException(java.io.IOException) StorageDirectory(org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory) StartupProgress(org.apache.hadoop.hdfs.server.namenode.startupprogress.StartupProgress)

Example 33 with StorageDirectory

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

the class FSImage method doUpgrade.

void doUpgrade(FSNamesystem target) throws IOException {
    checkUpgrade();
    // load the latest image
    // Do upgrade for each directory
    this.loadFSImage(target, StartupOption.UPGRADE, null);
    target.checkRollingUpgrade("upgrade namenode");
    long oldCTime = storage.getCTime();
    // generate new cTime for the state
    storage.cTime = now();
    int oldLV = storage.getLayoutVersion();
    storage.layoutVersion = HdfsServerConstants.NAMENODE_LAYOUT_VERSION;
    List<StorageDirectory> errorSDs = Collections.synchronizedList(new ArrayList<StorageDirectory>());
    assert !editLog.isSegmentOpen() : "Edits log must not be open.";
    LOG.info("Starting upgrade of local storage directories." + "\n   old LV = " + oldLV + "; old CTime = " + oldCTime + ".\n   new LV = " + storage.getLayoutVersion() + "; new CTime = " + storage.getCTime());
    // Do upgrade for each directory
    for (Iterator<StorageDirectory> it = storage.dirIterator(false); it.hasNext(); ) {
        StorageDirectory sd = it.next();
        try {
            NNUpgradeUtil.doPreUpgrade(conf, sd);
        } catch (Exception e) {
            LOG.error("Failed to move aside pre-upgrade storage " + "in image directory " + sd.getRoot(), e);
            errorSDs.add(sd);
            continue;
        }
    }
    if (target.isHaEnabled()) {
        editLog.doPreUpgradeOfSharedLog();
    }
    storage.reportErrorsOnDirectories(errorSDs);
    errorSDs.clear();
    saveFSImageInAllDirs(target, editLog.getLastWrittenTxId());
    // upgrade shared edit storage first
    if (target.isHaEnabled()) {
        editLog.doUpgradeOfSharedLog();
    }
    for (Iterator<StorageDirectory> it = storage.dirIterator(false); it.hasNext(); ) {
        StorageDirectory sd = it.next();
        try {
            NNUpgradeUtil.doUpgrade(sd, storage);
        } catch (IOException ioe) {
            errorSDs.add(sd);
            continue;
        }
    }
    storage.reportErrorsOnDirectories(errorSDs);
    isUpgradeFinalized = false;
    if (!storage.getRemovedStorageDirs().isEmpty()) {
        // during upgrade, it's a fatal error to fail any storage directory
        throw new IOException("Upgrade failed in " + storage.getRemovedStorageDirs().size() + " storage directory(ies), previously logged.");
    }
}
Also used : StorageDirectory(org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) InconsistentFSStateException(org.apache.hadoop.hdfs.server.common.InconsistentFSStateException) IOException(java.io.IOException)

Example 34 with StorageDirectory

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

the class TestJournalNodeSync method testMultipleJournalsMissingLogs.

@Test(timeout = 30000)
public void testMultipleJournalsMissingLogs() throws Exception {
    File firstJournalDir = jCluster.getJournalDir(0, jid);
    File firstJournalCurrentDir = new StorageDirectory(firstJournalDir).getCurrentDir();
    File secondJournalDir = jCluster.getJournalDir(1, jid);
    StorageDirectory sd = new StorageDirectory(secondJournalDir);
    File secondJournalCurrentDir = sd.getCurrentDir();
    // Generate some edit logs and delete one log from two journals.
    long firstTxId = generateEditLog();
    generateEditLog();
    List<File> missingLogs = Lists.newArrayList();
    missingLogs.add(deleteEditLog(firstJournalCurrentDir, firstTxId));
    missingLogs.add(deleteEditLog(secondJournalCurrentDir, firstTxId));
    GenericTestUtils.waitFor(editLogExists(missingLogs), 500, 10000);
}
Also used : StorageDirectory(org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory) File(java.io.File) FileJournalManager.getLogFile(org.apache.hadoop.hdfs.server.namenode.FileJournalManager.getLogFile) EditLogFile(org.apache.hadoop.hdfs.server.namenode.FileJournalManager.EditLogFile) Test(org.junit.Test)

Example 35 with StorageDirectory

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

the class TestJournalNodeSync method testRandomJournalMissingLogs.

// Test JournalNode Sync by randomly deleting edit logs from one or two of
// the journals.
@Test(timeout = 60000)
public void testRandomJournalMissingLogs() throws Exception {
    Random randomJournal = new Random();
    List<File> journalCurrentDirs = Lists.newArrayList();
    for (int i = 0; i < 3; i++) {
        journalCurrentDirs.add(new StorageDirectory(jCluster.getJournalDir(i, jid)).getCurrentDir());
    }
    int count = 0;
    long lastStartTxId;
    int journalIndex;
    List<File> missingLogs = Lists.newArrayList();
    while (count < 5) {
        lastStartTxId = generateEditLog();
        // Delete the last edit log segment from randomly selected journal node
        journalIndex = randomJournal.nextInt(3);
        missingLogs.add(deleteEditLog(journalCurrentDirs.get(journalIndex), lastStartTxId));
        // Delete the last edit log segment from two journals for some logs
        if (count % 2 == 0) {
            journalIndex = (journalIndex + 1) % 3;
            missingLogs.add(deleteEditLog(journalCurrentDirs.get(journalIndex), lastStartTxId));
        }
        count++;
    }
    GenericTestUtils.waitFor(editLogExists(missingLogs), 500, 30000);
}
Also used : Random(java.util.Random) StorageDirectory(org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory) File(java.io.File) FileJournalManager.getLogFile(org.apache.hadoop.hdfs.server.namenode.FileJournalManager.getLogFile) EditLogFile(org.apache.hadoop.hdfs.server.namenode.FileJournalManager.EditLogFile) Test(org.junit.Test)

Aggregations

StorageDirectory (org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory)83 File (java.io.File)59 Test (org.junit.Test)45 RandomAccessFile (java.io.RandomAccessFile)29 IOException (java.io.IOException)24 Configuration (org.apache.hadoop.conf.Configuration)22 HdfsConfiguration (org.apache.hadoop.hdfs.HdfsConfiguration)21 MiniDFSCluster (org.apache.hadoop.hdfs.MiniDFSCluster)20 EditLogFile (org.apache.hadoop.hdfs.server.namenode.FileJournalManager.EditLogFile)19 NameNodeFile (org.apache.hadoop.hdfs.server.namenode.NNStorage.NameNodeFile)15 URI (java.net.URI)11 FileSystem (org.apache.hadoop.fs.FileSystem)11 Path (org.apache.hadoop.fs.Path)10 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)9 FSImageFile (org.apache.hadoop.hdfs.server.namenode.FSImageStorageInspector.FSImageFile)7 FileJournalManager.getLogFile (org.apache.hadoop.hdfs.server.namenode.FileJournalManager.getLogFile)6 InconsistentFSStateException (org.apache.hadoop.hdfs.server.common.InconsistentFSStateException)5 AbortSpec (org.apache.hadoop.hdfs.server.namenode.TestEditLog.AbortSpec)5 ArrayList (java.util.ArrayList)4 StorageState (org.apache.hadoop.hdfs.server.common.Storage.StorageState)4