FSImage implements Closeable { void format(FSNamesystem fsn, String clusterId) throws IOException { long fileCount = fsn.getTotalFiles(); Preconditions.checkState(fileCount == 1, "FSImage.format should be called with an uninitialized namesystem, has " + fileCount + " files"); NamespaceInfo ns = NNStorage.newNamespaceInfo(); LOG.info("Allocated new BlockPoolId: " + ns.getBlockPoolID()); ns.clusterID = clusterId; storage.format(ns); editLog.formatNonFileJournals(ns); saveFSImageInAllDirs(fsn, 0); } FSImage(Configuration conf); protected  FSImage(Configuration conf,
                    Collection<URI> imageDirs,
                    List<URI> editsDirs); static boolean recoverStorageDirs(StartupOption startOpt,
      NNStorage storage, Map<StorageDirectory, StorageState> dataDirStates); static void checkUpgrade(NNStorage storage); boolean hasRollbackFSImage(); FSEditLog getEditLog(); @VisibleForTesting void setEditLogForTesting(FSEditLog newLog); void initEditLog(StartupOption startOpt); long loadEdits(Iterable<EditLogInputStream> editStreams,
      FSNamesystem target); void saveLegacyOIVImage(FSNamesystem source, String targetDir,
      Canceler canceler); synchronized void updateStorageVersion(); synchronized void saveNamespace(FSNamesystem source); synchronized void saveNamespace(FSNamesystem source, NameNodeFile nnf,
      Canceler canceler); synchronized void saveDigestAndRenameCheckpointImage(NameNodeFile nnf,
      long txid, MD5Hash digest); @Override synchronized void close(); NNStorage getStorage(); int getLayoutVersion(); int getNamespaceID(); String getClusterID(); String getBlockPoolID(); synchronized long getLastAppliedTxId(); long getLastAppliedOrWrittenTxId(); void updateLastAppliedTxIdFromWritten(); long getMostRecentCheckpointTxId(); static final Log LOG; }
@Test public void testZeroBlockSize() throws Exception { final Configuration conf = new HdfsConfiguration(); String tarFile = System.getProperty("test.cache.data", "build/test/cache") + "/" + HADOOP_2_6_ZER0_BLOCK_SIZE_TGZ; String testDir = PathUtils.getTestDirName(getClass()); File dfsDir = new File(testDir, "image-with-zero-block-size"); if (dfsDir.exists() && !FileUtil.fullyDelete(dfsDir)) { throw new IOException("Could not delete dfs directory '" + dfsDir + "'"); } FileUtil.unTar(new File(tarFile), new File(testDir)); File nameDir = new File(dfsDir, "name"); GenericTestUtils.assertExists(nameDir); conf.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY, nameDir.getAbsolutePath()); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1) .format(false) .manageDataDfsDirs(false) .manageNameDfsDirs(false) .waitSafeMode(false) .build(); try { FileSystem fs = cluster.getFileSystem(); Path testPath = new Path("/tmp/zeroBlockFile"); assertTrue("File /tmp/zeroBlockFile doesn't exist ", fs.exists(testPath)); assertTrue("Name node didn't come up", cluster.isNameNodeUp(0)); } finally { cluster.shutdown(); FileUtil.fullyDelete(dfsDir); } }