Search in sources :

Example 6 with CatchupFuture

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());
}
Also used : CatchupFuture(alluxio.master.journal.CatchupFuture) HashMap(java.util.HashMap) JournalContext(alluxio.master.journal.JournalContext) ExpectedException(org.junit.rules.ExpectedException) NoopMaster(alluxio.master.NoopMaster) Test(org.junit.Test)

Aggregations

CatchupFuture (alluxio.master.journal.CatchupFuture)6 NoopMaster (alluxio.master.NoopMaster)4 JournalContext (alluxio.master.journal.JournalContext)4 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 ExpectedException (org.junit.rules.ExpectedException)2 AlluxioURI (alluxio.AlluxioURI)1 AlluxioException (alluxio.exception.AlluxioException)1 BackupException (alluxio.exception.BackupException)1 LockResource (alluxio.resource.LockResource)1 BackupStatus (alluxio.wire.BackupStatus)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1