FileJournalManager implements JournalManager { @Override public void doPreUpgrade() throws IOException { LOG.info("Starting upgrade of edits directory " + sd.getRoot()); try { NNUpgradeUtil.doPreUpgrade(conf, sd); } catch (IOException ioe) { LOG.error("Failed to move aside pre-upgrade storage " + "in image directory " + sd.getRoot(), ioe); throw ioe; } } FileJournalManager(Configuration conf, StorageDirectory sd,
      StorageErrorReporter errorReporter); @Override void close(); @Override void format(NamespaceInfo ns, boolean force); @Override boolean hasSomeData(); @Override synchronized EditLogOutputStream startLogSegment(long txid,
      int layoutVersion); @Override synchronized void finalizeLogSegment(long firstTxId, long lastTxId); @VisibleForTesting StorageDirectory getStorageDirectory(); @Override synchronized void setOutputBufferCapacity(int size); long getLastReadableTxId(); void setLastReadableTxId(long id); @Override void purgeLogsOlderThan(long minTxIdToKeep); List<RemoteEditLog> getRemoteEditLogs(long firstTxId,
      boolean inProgressOk); static List<EditLogFile> matchEditLogs(File logDir); synchronized void selectInputStreams(
      Collection<EditLogInputStream> streams,
      long fromTxnId, boolean inProgressOk); @Override synchronized void selectInputStreams(
      Collection<EditLogInputStream> streams, long fromTxId,
      boolean inProgressOk, boolean onlyDurableTxns); @Override synchronized void recoverUnfinalizedSegments(); List<EditLogFile> getLogFiles(long fromTxId); EditLogFile getLogFile(long startTxId); EditLogFile getLogFile(long startTxId, boolean inProgressOk); static EditLogFile getLogFile(File dir, long startTxId); static EditLogFile getLogFile(File dir, long startTxId,
      boolean inProgressOk); @Override String toString(); @Override void doPreUpgrade(); @Override void doUpgrade(Storage storage); @Override void doFinalize(); @Override boolean canRollBack(StorageInfo storage, StorageInfo prevStorage,
      int targetLayoutVersion); @Override void doRollback(); @Override void discardSegments(long startTxid); @Override long getJournalCTime();  }
@Test public void testDoPreUpgradeIOError() throws IOException { File storageDir = new File(TestEditLog.TEST_DIR, "preupgradeioerror"); List<URI> editUris = Collections.singletonList(storageDir.toURI()); NNStorage storage = setupEdits(editUris, 5); StorageDirectory sd = storage.dirIterator(NameNodeDirType.EDITS).next(); assertNotNull(sd); FileUtil.setWritable(storageDir, false); FileJournalManager jm = null; try { jm = new FileJournalManager(conf, sd, storage); exception.expect(IOException.class); if (NativeCodeLoader.isNativeCodeLoaded()) { exception.expectMessage("failure in native rename"); } jm.doPreUpgrade(); } finally { IOUtils.cleanupWithLogger(LOG, jm); FileUtil.setWritable(storageDir, true); FileUtil.fullyDelete(storageDir); } }