@ThreadSafe public interface JournalSystem
createJournal(Master)
method. Once all state machines are added,
start()
the journal system. The journal system starts in secondary mode, meaning it will
not accept writes, but will apply journal entries to keep state machine states up to date with
previously written journal entries.
To enable writes, the journal system may be changed to
primary mode, where all state machines will first be caught up fully with the latest journal
updates, then begin to accept writes. Note that as a performance optimization, the journal system
does not apply journal entries to state machines while in primary mode. Instead, the state
machine states must be directly modified by RPC handlers.
The journal system may also be changed from primary to secondary mode. This transition is done by
resetting all state machines and re-building them by catching up on the journal.
Example usage:
JournalSystem journalSystem = new JournalSystemImpl(); if (!journalSystem.isFormatted()) { journalSystem.format(); } Journal blockMasterJournal = journalSystem.createJournal(blockMaster); Journal fileSystemMasterJournal = journalSystem.createJournal(fileSystemMaster); // The journal system always starts in secondary mode. It must be transitioned to primary mode // before it can write entries. journalSystem.start(); journalSystem.setPrimary(true); try (JournalContext c = blockMasterJournal.createJournalContext()) { c.append(exampleBlockJournalEntry); } // At this point, the journal entry is persistently committed to the journal and will be applied // asynchronously to the in-memory state of all secondary masters. try (JournalContext c = fileSystemMasterJournal.createJournalContext()) { c.append(exampleFileSystemJournalEntry); } // Transition to a secondary journal. In this mode, the journal will apply entries to the masters // as they are committed to the log. journalSystem.setPrimary(false);
Modifier and Type | Interface and Description |
---|---|
static class |
JournalSystem.Builder
Builder for constructing a journal system.
|
static class |
JournalSystem.Mode
The mode of the journal system.
|
Modifier and Type | Method and Description |
---|---|
void |
addJournalSink(Master master,
JournalSink journalSink) |
void |
checkpoint()
Creates a checkpoint in the primary master journal system.
|
Journal |
createJournal(Master master)
Creates a journal for the given state machine.
|
void |
format()
Formats the journal system.
|
void |
gainPrimacy()
Transitions the journal to primary mode.
|
Set<JournalSink> |
getJournalSinks(Master master) |
boolean |
isEmpty()
Returns whether the journal is formatted and has not had any entries written to it yet.
|
boolean |
isFormatted() |
void |
losePrimacy()
Transitions the journal to secondary mode.
|
void |
removeJournalSink(Master master,
JournalSink journalSink) |
void |
start()
Starts the journal system.
|
void |
stop()
Stops the journal system.
|
Journal createJournal(Master master)
Journaled#processJournalEntry(JournalEntry)
and
Journaled.resetState()
to keep the state machine's state in sync with
the entries written to the journal.master
- the master to create the journal forJournal
void start() throws InterruptedException, IOException
InterruptedException
IOException
void stop() throws InterruptedException, IOException
InterruptedException
IOException
void gainPrimacy()
void losePrimacy()
void format() throws IOException
IOException
boolean isFormatted() throws IOException
IOException
void addJournalSink(Master master, JournalSink journalSink)
master
- the master for which to add the journal sinkjournalSink
- the journal sink to addvoid removeJournalSink(Master master, JournalSink journalSink)
master
- the master from which to remove the journal sinkjournalSink
- the journal sink to removeSet<JournalSink> getJournalSinks(@Nullable Master master)
master
- the master to get the journal sinks for, or null to get all sinksJournalSink
for the given master, or all sinks if master is nullboolean isEmpty()
void checkpoint() throws IOException
IOException
Copyright © 2023. All Rights Reserved.