@ThreadSafe public interface JournalSystem
createJournal(Master)
method. Once all state machines are added,
start()
the journal system. The journal system starts in standby 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 standby 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 standby 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 standby masters. try (JournalContext c = fileSystemMasterJournal.createJournalContext()) { c.append(exampleFileSystemJournalEntry); } // Transition to a standby 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) |
CatchupFuture |
catchup(Map<String,Long> journalSequenceNumbers)
Initiates a catching up of journals to given sequences.
|
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.
|
Map<String,Long> |
getCurrentSequenceNumbers()
Used to get the current state from a leader journal system.
|
default Map<ServiceType,GrpcService> |
getJournalServices() |
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 standby mode.
|
void |
removeJournalSink(Master master,
JournalSink journalSink) |
void |
resume()
Resumes applying for all journals.
|
void |
start()
Starts the journal system.
|
void |
stop()
Stops the journal system.
|
void |
suspend(Runnable interruptCallback)
Suspends applying for all journals.
|
default void |
waitForCatchup()
Waits for the journal catchup to finish when the process starts.
|
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 suspend(Runnable interruptCallback) throws IOException
interruptCallback
- the callback function to be invoked when the suspension is interruptedIOException
void resume() throws IOException
IOException
CatchupFuture catchup(Map<String,Long> journalSequenceNumbers) throws IOException
journalSequenceNumbers
- sequence to advance per each journalIOException
default void waitForCatchup()
Map<String,Long> getCurrentSequenceNumbers()
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
default Map<ServiceType,GrpcService> getJournalServices()
Copyright © 2023. All Rights Reserved.