/** * Creates a new instance of {@link UfsJournal}. * * @param location the location for this journal * @param stateMachine the state machine to manage * @param ufs the under file system * @param quietPeriodMs the amount of time to wait to pass without seeing a new journal entry when * gaining primacy */ UfsJournal(URI location, JournalEntryStateMachine stateMachine, UnderFileSystem ufs, long quietPeriodMs) { mLocation = URIUtils.appendPathOrDie(location, VERSION); mMaster = stateMachine; mUfs = ufs; mQuietPeriodMs = quietPeriodMs; mLogDir = URIUtils.appendPathOrDie(mLocation, LOG_DIRNAME); mCheckpointDir = URIUtils.appendPathOrDie(mLocation, CHECKPOINT_DIRNAME); mTmpDir = URIUtils.appendPathOrDie(mLocation, TMP_DIRNAME); mState = State.SECONDARY; }
/** * @param logNumber the log number to get the path for * @return the location of the completed log for a particular log number */ private URI getCompletedLogV0(long logNumber) { return URIUtils .appendPathOrDie(mCompletedLogsV0, String.format("%s.%020d", "log", logNumber)); }
/** * Encodes a checkpoint location under the checkpoint directory. * * @param journal the UFS journal instance * @param end the end sequence number (exclusive) * @return the location */ static URI encodeCheckpointFileLocation(UfsJournal journal, long end) { String filename = String.format("0x%x-0x%x", 0, end); URI location = URIUtils.appendPathOrDie(journal.getCheckpointDir(), filename); return location; }
/** * Encodes a temporary location under the temporary directory. * * @param journal the UFS journal instance* * @return the location */ static URI encodeTemporaryCheckpointFileLocation(UfsJournal journal) { return URIUtils.appendPathOrDie(journal.getTmpDir(), UUID.randomUUID().toString()); }
/** * Encodes a log location under the log directory. * * @param journal the UFS journal instance * @param start the start sequence number (inclusive) * @param end the end sequence number (exclusive) * @return the location */ static URI encodeLogFileLocation(UfsJournal journal, long start, long end) { String filename = String.format("0x%x-0x%x", start, end); URI location = URIUtils.appendPathOrDie(journal.getLogDir(), filename); return location; }
/** * Renames checkpoint. * * @param sequenceNumber the sequence number */ private void renameCheckpoint(long sequenceNumber) throws IOException { URI dst = URIUtils.appendPathOrDie(mCheckpointsV1, String.format("0x0-0x%x", sequenceNumber)); if (!mUfs.renameFile(mCheckpointV0.toString(), dst.toString()) && !mUfs .exists(dst.toString())) { throw new IOException( String.format("Failed to rename %s to %s.", mCheckpointV0.toString(), dst.toString())); } }
/** * Decodes a temporary checkpoint file name into a {@link UfsJournalFile}. * * @param journal the UFS journal instance * @param filename the temporary checkpoint file name * @return the instance of {@link UfsJournalFile} */ static UfsJournalFile decodeTemporaryCheckpointFile(UfsJournal journal, String filename) { URI location = URIUtils.appendPathOrDie(journal.getTmpDir(), filename); return UfsJournalFile.createTmpCheckpointFile(location); }
@Override public UfsJournal createJournal(JournalEntryStateMachine master) { UfsJournal journal = new UfsJournal(URIUtils.appendPathOrDie(mBase, master.getName()), master, mQuietTimeMs); mJournals.put(master.getName(), journal); return journal; }
private Upgrader(String master, AlluxioConfiguration alluxioConf) { mMaster = master; mAlluxioConf = alluxioConf; mJournalV0 = (new alluxio.master.journalv0.MutableJournal.Factory( getJournalLocation(sJournalDirectoryV0))).create(master); mJournalV1 = new UfsJournal(getJournalLocation(ServerConfiguration .get(PropertyKey.MASTER_JOURNAL_FOLDER)), new NoopMaster(master), 0); mUfs = UnderFileSystem.Factory.create(sJournalDirectoryV0, alluxioConf); mCheckpointV0 = URIUtils.appendPathOrDie(mJournalV0.getLocation(), "checkpoint.data"); mCompletedLogsV0 = URIUtils.appendPathOrDie(mJournalV0.getLocation(), "completed"); mCheckpointsV1 = URIUtils.appendPathOrDie(mJournalV1.getLocation(), "checkpoints"); mLogsV1 = URIUtils.appendPathOrDie(mJournalV1.getLocation(), "logs"); }
@Before public void before() throws Exception { mJournal = new UfsJournal(URIUtils.appendPathOrDie(new URI(mFolder.newFolder().getAbsolutePath()), "FileSystemMaster"), new NoopMaster(), 0); }
@Before public void before() throws Exception { mJournal = new UfsJournal(URIUtils.appendPathOrDie(new URI(mFolder.newFolder().getAbsolutePath()), "FileSystemMaster"), new NoopMaster(), 0); }
@Before public void before() throws Exception { mLocation = URIUtils.appendPathOrDie(new URI(mFolder.newFolder().getAbsolutePath()), "master"); mJournal = new UfsJournal(mLocation, new NoopMaster(), 0); }
@Before public void before() throws Exception { URI location = URIUtils .appendPathOrDie(new URI(mFolder.newFolder().getAbsolutePath()), "FileSystemMaster"); mUfs = Mockito.spy(UnderFileSystem.Factory.create(location, ServerConfiguration.global())); mJournal = new UfsJournal(location, new NoopMaster(), mUfs, 0); }
@Before public void before() throws Exception { URI location = URIUtils .appendPathOrDie(new URI(mFolder.newFolder().getAbsolutePath()), "FileSystemMaster"); mUfs = Mockito.spy(UnderFileSystem.Factory.create(location, ServerConfiguration.global())); mJournal = new UfsJournal(location, new NoopMaster(), mUfs, 0); }
@Before public void before() throws Exception { URI location = URIUtils .appendPathOrDie(new URI(mFolder.newFolder().getAbsolutePath()), "FileSystemMaster"); mUfs = Mockito.spy(UnderFileSystem.Factory.create(location, ServerConfiguration.global())); mJournal = new UfsJournal(location, new NoopMaster(), mUfs, 0); }
@Before public void before() throws Exception { URI location = URIUtils .appendPathOrDie(new URI(mFolder.newFolder().getAbsolutePath()), "FileSystemMaster"); mUfs = Mockito.spy(UnderFileSystem.Factory.create(location, ServerConfiguration.global())); mJournal = new UfsJournal(location, new NoopMaster(), mUfs, 0); }
/** * A new journal writer completes the current log. */ @Test public void completeCurrentLog() throws Exception { long startSN = 0x10; long endSN = 0x20; mJournal.getUfs().create( UfsJournalFile.encodeLogFileLocation(mJournal, startSN, UfsJournal.UNKNOWN_SEQUENCE_NUMBER) .toString()).close(); new UfsJournalLogWriter(mJournal, 0x20).close(); UfsJournalSnapshot snapshot = UfsJournalSnapshot.getSnapshot(mJournal); String expectedLog = URIUtils.appendPathOrDie(mJournal.getLogDir(), String.format("0x%x-0x%x", startSN, endSN)) .toString(); Assert.assertEquals(1, snapshot.getLogs().size()); Assert.assertEquals(expectedLog, snapshot.getLogs().get(0).getLocation().toString()); Assert.assertTrue(UfsJournalSnapshot.getCurrentLog(mJournal) == null); }
/** * Encodes/decodes incomplete log file names. */ @Test public void incompleteLogFilename() throws Exception { String location = UfsJournalFile.encodeLogFileLocation(mJournal, 0x10, UfsJournal.UNKNOWN_SEQUENCE_NUMBER) .toString(); String expectedFilename = "0x10-0x" + Long.toHexString(UfsJournal.UNKNOWN_SEQUENCE_NUMBER); Assert.assertEquals(URIUtils.appendPathOrDie(mJournal.getLogDir(), expectedFilename).toString(), location); UfsJournalFile file = UfsJournalFile.decodeLogFile(mJournal, expectedFilename); Assert.assertTrue(file.isIncompleteLog()); Assert.assertEquals(0x10, file.getStart()); Assert.assertEquals(UfsJournal.UNKNOWN_SEQUENCE_NUMBER, file.getEnd()); Assert.assertEquals(location, file.getLocation().toString()); }
/** * Encodes/decodes completed log file names. */ @Test public void completedLogFilename() throws Exception { String location = UfsJournalFile.encodeLogFileLocation(mJournal, 0x10, 0x100).toString(); Assert.assertEquals(URIUtils.appendPathOrDie(mJournal.getLogDir(), "0x10-0x100").toString(), location); UfsJournalFile file = UfsJournalFile.decodeLogFile(mJournal, "0x10-0x100"); Assert.assertTrue(file.isCompletedLog()); Assert.assertEquals(0x10, file.getStart()); Assert.assertEquals(0x100, file.getEnd()); Assert.assertEquals(location, file.getLocation().toString()); }
/** * Encodes/decodes checkpoint filename. */ @Test public void checkpointFilename() throws Exception { String location = UfsJournalFile.encodeCheckpointFileLocation(mJournal, 0x10).toString(); String expectedFilename = "0x0-0x10"; Assert.assertEquals( URIUtils.appendPathOrDie(mJournal.getCheckpointDir(), expectedFilename).toString(), location); UfsJournalFile file = UfsJournalFile.decodeCheckpointFile(mJournal, expectedFilename); Assert.assertTrue(file.isCheckpoint()); Assert.assertEquals(0x0, file.getStart()); Assert.assertEquals(0x10, file.getEnd()); Assert.assertEquals(location, file.getLocation().toString()); }