use of alluxio.master.journal.CatchupFuture in project alluxio by Alluxio.
the class RaftJournalTest method gainPrimacyDuringCatchup.
@Test
public void gainPrimacyDuringCatchup() throws Exception {
// Create a counting master implementation that counts how many journal entries it processed.
CountingDummyFileSystemMaster countingMaster = new CountingDummyFileSystemMaster();
mFollowerJournalSystem.createJournal(countingMaster);
// Using a large entry count for catching transition while in-progress.
final int entryCount = 100;
// Suspend follower journal system.
mFollowerJournalSystem.suspend(null);
// Create entries on the leader journal context.
// These will be replicated to follower journal context once resumed.
ForkJoinPool.commonPool().submit(() -> {
try (JournalContext journalContext = mLeaderJournalSystem.createJournal(new NoopMaster()).createJournalContext()) {
for (int i = 0; i < entryCount; i++) {
journalContext.append(alluxio.proto.journal.Journal.JournalEntry.newBuilder().setInodeLastModificationTime(File.InodeLastModificationTimeEntry.newBuilder().setId(i).build()).build());
}
} catch (Exception e) {
Assert.fail(String.format("Failed while writing entries: %s", e.toString()));
}
}).get();
// Catch up follower journal to a large index to be able to transition while in progress.
Map<String, Long> backupSequences = new HashMap<>();
backupSequences.put("FileSystemMaster", (long) entryCount);
// Set delay for each internal processing of entries before initiating catch-up.
countingMaster.setApplyDelay(100);
CatchupFuture catchupFuture = mFollowerJournalSystem.catchup(backupSequences);
// Wait until advancing starts.
CommonUtils.waitFor("Advancing to start.", () -> countingMaster.getApplyCount() > 0, mWaitOptions);
// Gain primacy in follower journal
promoteFollower();
// Validate it catches up.
CommonUtils.waitFor("Old olf follower to catch up.", () -> countingMaster.getApplyCount() == entryCount, mWaitOptions);
// Follower should no longer be suspended after becoming primary.
Assert.assertFalse(mFollowerJournalSystem.isSuspended());
}
Aggregations