FileJournalManager implements JournalManager { @Override synchronized public void finalizeLogSegment(long firstTxId, long lastTxId) throws IOException { File inprogressFile = NNStorage.getInProgressEditsFile(sd, firstTxId); File dstFile = NNStorage.getFinalizedEditsFile( sd, firstTxId, lastTxId); LOG.info("Finalizing edits file " + inprogressFile + " -> " + dstFile); Preconditions.checkState(!dstFile.exists(), "Can't finalize edits file " + inprogressFile + " since finalized file " + "already exists"); try { NativeIO.renameTo(inprogressFile, dstFile); } catch (IOException e) { errorReporter.reportErrorOnFile(dstFile); throw new IllegalStateException("Unable to finalize edits file " + inprogressFile, e); } if (inprogressFile.equals(currentInProgress)) { currentInProgress = null; } } FileJournalManager(Configuration conf, StorageDirectory sd,
      StorageErrorReporter errorReporter); @Override void close(); @Override void format(NamespaceInfo ns); @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); @Override void purgeLogsOlderThan(long minTxIdToKeep); List<RemoteEditLog> getRemoteEditLogs(long firstTxId,
      boolean inProgressOk); static List<EditLogFile> matchEditLogs(File logDir); @Override synchronized void selectInputStreams(
      Collection<EditLogInputStream> streams, long fromTxId,
      boolean inProgressOk); @Override synchronized void recoverUnfinalizedSegments(); List<EditLogFile> getLogFiles(long fromTxId); EditLogFile getLogFile(long startTxId); static EditLogFile getLogFile(File dir, long startTxId); @Override String toString(); @Override void discardSegments(long startTxid); @Override void doPreUpgrade(); @Override void doUpgrade(Storage storage); @Override void doFinalize(); @Override boolean canRollBack(StorageInfo storage, StorageInfo prevStorage,
      int targetLayoutVersion); @Override void doRollback(); @Override long getJournalCTime();  }
@Test(expected=IllegalStateException.class) public void testFinalizeErrorReportedToNNStorage() throws IOException, InterruptedException { File f = new File(TestEditLog.TEST_DIR + "/filejournaltestError"); NNStorage storage = setupEdits(Collections.<URI>singletonList(f.toURI()), 10, new AbortSpec(10, 0)); StorageDirectory sd = storage.dirIterator(NameNodeDirType.EDITS).next(); FileJournalManager jm = new FileJournalManager(conf, sd, storage); String sdRootPath = sd.getRoot().getAbsolutePath(); FileUtil.chmod(sdRootPath, "-w", true); try { jm.finalizeLogSegment(0, 1); } finally { FileUtil.chmod(sdRootPath, "+w", true); assertTrue(storage.getRemovedStorageDirs().contains(sd)); } }