diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 6a5d9ce4db6..fbd1d596c03 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -245,6 +245,9 @@ Trunk (Unreleased) HDFS-5715. Use Snapshot ID to indicate the corresponding Snapshot for a FileDiff/DirectoryDiff. (jing9) + HDFS-5721. sharedEditsImage in Namenode#initializeSharedEdits() should be + closed before method returns. (Ted Yu via junping_du) + OPTIMIZATIONS HDFS-5349. DNA_CACHE and DNA_UNCACHE should be by blockId only. (cmccabe) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java index f5cda802c8a..8a9cbd1b5e2 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java @@ -619,8 +619,14 @@ public class FSNamesystem implements Namesystem, FSClusterStats, long loadStart = now(); String nameserviceId = DFSUtil.getNamenodeNameServiceId(conf); - namesystem.loadFSImage(startOpt, fsImage, - HAUtil.isHAEnabled(conf, nameserviceId)); + try { + namesystem.loadFSImage(startOpt, fsImage, + HAUtil.isHAEnabled(conf, nameserviceId)); + } catch (IOException ioe) { + LOG.warn("Encountered exception loading fsimage", ioe); + fsImage.close(); + throw ioe; + } long timeTakenToLoadFSImage = now() - loadStart; LOG.info("Finished loading FSImage in " + timeTakenToLoadFSImage + " msecs"); NameNodeMetrics nnMetrics = NameNode.getNameNodeMetrics(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java index 4b2bd66d1ff..12e26f1fdb9 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java @@ -816,14 +816,20 @@ public class NameNode implements NameNodeStatusMXBean { System.out.println("Formatting using clusterid: " + clusterId); FSImage fsImage = new FSImage(conf, nameDirsToFormat, editDirsToFormat); - FSNamesystem fsn = new FSNamesystem(conf, fsImage); - fsImage.getEditLog().initJournalsForWrite(); - - if (!fsImage.confirmFormat(force, isInteractive)) { - return true; // aborted + try { + FSNamesystem fsn = new FSNamesystem(conf, fsImage); + fsImage.getEditLog().initJournalsForWrite(); + + if (!fsImage.confirmFormat(force, isInteractive)) { + return true; // aborted + } + + fsImage.format(fsn, clusterId); + } catch (IOException ioe) { + LOG.warn("Encountered exception during format: ", ioe); + fsImage.close(); + throw ioe; } - - fsImage.format(fsn, clusterId); return false; } @@ -897,6 +903,7 @@ public class NameNode implements NameNodeStatusMXBean { } NNStorage existingStorage = null; + FSImage sharedEditsImage = null; try { FSNamesystem fsns = FSNamesystem.loadFromDisk(getConfigurationWithoutSharedEdits(conf)); @@ -906,7 +913,7 @@ public class NameNode implements NameNodeStatusMXBean { List sharedEditsDirs = FSNamesystem.getSharedEditsDirs(conf); - FSImage sharedEditsImage = new FSImage(conf, + sharedEditsImage = new FSImage(conf, Lists.newArrayList(), sharedEditsDirs); sharedEditsImage.getEditLog().initJournalsForWrite(); @@ -934,6 +941,13 @@ public class NameNode implements NameNodeStatusMXBean { LOG.error("Could not initialize shared edits dir", ioe); return true; // aborted } finally { + if (sharedEditsImage != null) { + try { + sharedEditsImage.close(); + } catch (IOException ioe) { + LOG.warn("Could not close sharedEditsImage", ioe); + } + } // Have to unlock storage explicitly for the case when we're running in a // unit test, which runs in the same JVM as NNs. if (existingStorage != null) { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/BootstrapStandby.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/BootstrapStandby.java index 484eb45cc0f..ac0761d41f8 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/BootstrapStandby.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/BootstrapStandby.java @@ -190,24 +190,29 @@ public class BootstrapStandby implements Tool, Configurable { // Load the newly formatted image, using all of the directories (including shared // edits) FSImage image = new FSImage(conf); - image.getStorage().setStorageInfo(storage); - image.initEditLog(); - assert image.getEditLog().isOpenForRead() : + try { + image.getStorage().setStorageInfo(storage); + image.initEditLog(); + assert image.getEditLog().isOpenForRead() : "Expected edit log to be open for read"; - - // Ensure that we have enough edits already in the shared directory to - // start up from the last checkpoint on the active. - if (!checkLogsAvailableForRead(image, imageTxId, curTxId)) { - return ERR_CODE_LOGS_UNAVAILABLE; - } - - image.getStorage().writeTransactionIdFileToStorage(curTxId); - // Download that checkpoint into our storage directories. - MD5Hash hash = TransferFsImage.downloadImageToStorage( + // Ensure that we have enough edits already in the shared directory to + // start up from the last checkpoint on the active. + if (!checkLogsAvailableForRead(image, imageTxId, curTxId)) { + return ERR_CODE_LOGS_UNAVAILABLE; + } + + image.getStorage().writeTransactionIdFileToStorage(curTxId); + + // Download that checkpoint into our storage directories. + MD5Hash hash = TransferFsImage.downloadImageToStorage( otherHttpAddr, imageTxId, storage, true); - image.saveDigestAndRenameCheckpointImage(imageTxId, hash); + image.saveDigestAndRenameCheckpointImage(imageTxId, hash); + } catch (IOException ioe) { + image.close(); + throw ioe; + } return 0; }