Search in sources :

Example 1 with NamenodeCommand

use of org.apache.hadoop.hdfs.server.protocol.NamenodeCommand in project hadoop by apache.

the class FSNamesystem method startCheckpoint.

NamenodeCommand startCheckpoint(NamenodeRegistration backupNode, NamenodeRegistration activeNamenode) throws IOException {
    checkOperation(OperationCategory.CHECKPOINT);
    writeLock();
    try {
        checkOperation(OperationCategory.CHECKPOINT);
        checkNameNodeSafeMode("Checkpoint not started");
        LOG.info("Start checkpoint for " + backupNode.getAddress());
        NamenodeCommand cmd = getFSImage().startCheckpoint(backupNode, activeNamenode, getEffectiveLayoutVersion());
        getEditLog().logSync();
        return cmd;
    } finally {
        writeUnlock("startCheckpoint");
    }
}
Also used : NamenodeCommand(org.apache.hadoop.hdfs.server.protocol.NamenodeCommand)

Example 2 with NamenodeCommand

use of org.apache.hadoop.hdfs.server.protocol.NamenodeCommand in project hadoop by apache.

the class Checkpointer method doCheckpoint.

/**
   * Create a new checkpoint
   */
void doCheckpoint() throws IOException {
    BackupImage bnImage = getFSImage();
    NNStorage bnStorage = bnImage.getStorage();
    long startTime = monotonicNow();
    bnImage.freezeNamespaceAtNextRoll();
    NamenodeCommand cmd = getRemoteNamenodeProxy().startCheckpoint(backupNode.getRegistration());
    CheckpointCommand cpCmd = null;
    switch(cmd.getAction()) {
        case NamenodeProtocol.ACT_SHUTDOWN:
            shutdown();
            throw new IOException("Name-node " + backupNode.nnRpcAddress + " requested shutdown.");
        case NamenodeProtocol.ACT_CHECKPOINT:
            cpCmd = (CheckpointCommand) cmd;
            break;
        default:
            throw new IOException("Unsupported NamenodeCommand: " + cmd.getAction());
    }
    bnImage.waitUntilNamespaceFrozen();
    CheckpointSignature sig = cpCmd.getSignature();
    // Make sure we're talking to the same NN!
    sig.validateStorageInfo(bnImage);
    long lastApplied = bnImage.getLastAppliedTxId();
    LOG.debug("Doing checkpoint. Last applied: " + lastApplied);
    RemoteEditLogManifest manifest = getRemoteNamenodeProxy().getEditLogManifest(bnImage.getLastAppliedTxId() + 1);
    boolean needReloadImage = false;
    if (!manifest.getLogs().isEmpty()) {
        RemoteEditLog firstRemoteLog = manifest.getLogs().get(0);
        // to download and load the image.
        if (firstRemoteLog.getStartTxId() > lastApplied + 1) {
            LOG.info("Unable to roll forward using only logs. Downloading " + "image with txid " + sig.mostRecentCheckpointTxId);
            MD5Hash downloadedHash = TransferFsImage.downloadImageToStorage(backupNode.nnHttpAddress, sig.mostRecentCheckpointTxId, bnStorage, true, false);
            bnImage.saveDigestAndRenameCheckpointImage(NameNodeFile.IMAGE, sig.mostRecentCheckpointTxId, downloadedHash);
            lastApplied = sig.mostRecentCheckpointTxId;
            needReloadImage = true;
        }
        if (firstRemoteLog.getStartTxId() > lastApplied + 1) {
            throw new IOException("No logs to roll forward from " + lastApplied);
        }
        // get edits files
        for (RemoteEditLog log : manifest.getLogs()) {
            TransferFsImage.downloadEditsToStorage(backupNode.nnHttpAddress, log, bnStorage);
        }
        if (needReloadImage) {
            LOG.info("Loading image with txid " + sig.mostRecentCheckpointTxId);
            File file = bnStorage.findImageFile(NameNodeFile.IMAGE, sig.mostRecentCheckpointTxId);
            bnImage.reloadFromImageFile(file, backupNode.getNamesystem());
        }
        rollForwardByApplyingLogs(manifest, bnImage, backupNode.getNamesystem());
    }
    long txid = bnImage.getLastAppliedTxId();
    backupNode.namesystem.writeLock();
    try {
        backupNode.namesystem.setImageLoaded();
        if (backupNode.namesystem.getBlocksTotal() > 0) {
            long completeBlocksTotal = backupNode.namesystem.getCompleteBlocksTotal();
            backupNode.namesystem.getBlockManager().setBlockTotal(completeBlocksTotal);
        }
        bnImage.saveFSImageInAllDirs(backupNode.getNamesystem(), txid);
        if (!backupNode.namenode.isRollingUpgrade()) {
            bnImage.updateStorageVersion();
        }
    } finally {
        backupNode.namesystem.writeUnlock("doCheckpoint");
    }
    if (cpCmd.needToReturnImage()) {
        TransferFsImage.uploadImageFromStorage(backupNode.nnHttpAddress, conf, bnStorage, NameNodeFile.IMAGE, txid);
    }
    getRemoteNamenodeProxy().endCheckpoint(backupNode.getRegistration(), sig);
    if (backupNode.getRole() == NamenodeRole.BACKUP) {
        bnImage.convergeJournalSpool();
    }
    // keep registration up to date
    backupNode.setRegistration();
    long imageSize = bnImage.getStorage().getFsImageName(txid).length();
    LOG.info("Checkpoint completed in " + (monotonicNow() - startTime) / 1000 + " seconds." + " New Image Size: " + imageSize);
}
Also used : CheckpointCommand(org.apache.hadoop.hdfs.server.protocol.CheckpointCommand) RemoteEditLogManifest(org.apache.hadoop.hdfs.server.protocol.RemoteEditLogManifest) MD5Hash(org.apache.hadoop.io.MD5Hash) IOException(java.io.IOException) RemoteEditLog(org.apache.hadoop.hdfs.server.protocol.RemoteEditLog) File(java.io.File) NameNodeFile(org.apache.hadoop.hdfs.server.namenode.NNStorage.NameNodeFile) NamenodeCommand(org.apache.hadoop.hdfs.server.protocol.NamenodeCommand)

Example 3 with NamenodeCommand

use of org.apache.hadoop.hdfs.server.protocol.NamenodeCommand in project hadoop by apache.

the class NameNodeRpcServer method startCheckpoint.

// NamenodeProtocol
@Override
public NamenodeCommand startCheckpoint(NamenodeRegistration registration) throws IOException {
    checkNNStartup();
    namesystem.checkSuperuserPrivilege();
    verifyRequest(registration);
    if (!nn.isRole(NamenodeRole.NAMENODE))
        throw new IOException("Only an ACTIVE node can invoke startCheckpoint.");
    CacheEntryWithPayload cacheEntry = RetryCache.waitForCompletion(retryCache, null);
    if (cacheEntry != null && cacheEntry.isSuccess()) {
        return (NamenodeCommand) cacheEntry.getPayload();
    }
    NamenodeCommand ret = null;
    try {
        ret = namesystem.startCheckpoint(registration, nn.setRegistration());
    } finally {
        RetryCache.setState(cacheEntry, ret != null, ret);
    }
    return ret;
}
Also used : IOException(java.io.IOException) CacheEntryWithPayload(org.apache.hadoop.ipc.RetryCache.CacheEntryWithPayload) NamenodeCommand(org.apache.hadoop.hdfs.server.protocol.NamenodeCommand)

Aggregations

NamenodeCommand (org.apache.hadoop.hdfs.server.protocol.NamenodeCommand)3 IOException (java.io.IOException)2 File (java.io.File)1 NameNodeFile (org.apache.hadoop.hdfs.server.namenode.NNStorage.NameNodeFile)1 CheckpointCommand (org.apache.hadoop.hdfs.server.protocol.CheckpointCommand)1 RemoteEditLog (org.apache.hadoop.hdfs.server.protocol.RemoteEditLog)1 RemoteEditLogManifest (org.apache.hadoop.hdfs.server.protocol.RemoteEditLogManifest)1 MD5Hash (org.apache.hadoop.io.MD5Hash)1 CacheEntryWithPayload (org.apache.hadoop.ipc.RetryCache.CacheEntryWithPayload)1