java.lang.Object
org.jgroups.protocols.raft.FileBasedLog
- All Implemented Interfaces:
Closeable,AutoCloseable,Log
- Direct Known Subclasses:
LevelDBLog
A
Log implementation stored in a file.- Since:
- 0.5.4
- Author:
- Pedro Ruivo
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongappend(long index, LogEntries entries) Append the entries starting at index.voidclose()longReturns the current commit index.commitIndex(long new_index) Sets commitIndex to a new valuelongReturns the current termcurrentTerm(long new_term) Sets the current termvoiddelete()Remove the persistent store, e.g.voiddeleteAllEntriesStartingFrom(long start_index) Delete all entries starting from start_index (including the entry at start_index).longReturns the index of the first log entryvoidforEach(ObjLongConsumer<LogEntry> function) Applies a function to all elements in range [first_appended .. last_appended]voidforEach(ObjLongConsumer<LogEntry> function, long start_index, long end_index) Applies function to all elements of the log in range [max(start_index,first_appended) .. min(last_appended,end_index)].get(long index) Gets the entry at start_index.Gets the snapshot from the logvoidCalled after the instance has been createdlongReturns the index of the last append entry
This value is set byLog.append(long,LogEntries)voidreinitializeTo(long index, LogEntry entry) Clears all entries and sets first_appended/last_appended/commit_index to index and appends entry at index.voidStores a snapshot in the log.longtoString()voidtruncate(long index_exclusive) Truncates the log up to (and excluding) index.booleanuseFsync()useFsync(boolean value) Do not cache a change (e.g.org.jgroups.AddressvotedFor()Returns the address of the candidate that this node voted for in the current termvotedFor(org.jgroups.Address member) Sets the address of the member this node voted for in the current term.
-
Constructor Details
-
FileBasedLog
public FileBasedLog()
-
-
Method Details
-
init
Description copied from interface:LogCalled after the instance has been created -
useFsync
Description copied from interface:LogDo not cache a change (e.g. AppendEntriesRequest, or setting the commit index), but force a write to disk (fsync), if true. -
useFsync
public boolean useFsync() -
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
delete
public void delete()Description copied from interface:LogRemove the persistent store, e.g. DB table, or file -
currentTerm
public long currentTerm()Description copied from interface:LogReturns the current term- Specified by:
currentTermin interfaceLog
-
currentTerm
Description copied from interface:LogSets the current term- Specified by:
currentTermin interfaceLog
-
votedFor
public org.jgroups.Address votedFor()Description copied from interface:LogReturns the address of the candidate that this node voted for in the current term -
votedFor
Description copied from interface:LogSets the address of the member this node voted for in the current term. Only invoked once per term -
commitIndex
public long commitIndex()Description copied from interface:LogReturns the current commit index. (May get removed as the RAFT paper has this as in-memory attribute)- Specified by:
commitIndexin interfaceLog
-
commitIndex
Description copied from interface:LogSets commitIndex to a new value- Specified by:
commitIndexin interfaceLog- Parameters:
new_index- The new index to set commitIndex to. May throw an exception if new_index > lastApplied()- Returns:
- the log
-
firstAppended
public long firstAppended()Description copied from interface:LogReturns the index of the first log entry- Specified by:
firstAppendedin interfaceLog
-
lastAppended
public long lastAppended()Description copied from interface:LogReturns the index of the last append entry
This value is set byLog.append(long,LogEntries)- Specified by:
lastAppendedin interfaceLog
-
setSnapshot
Description copied from interface:LogStores a snapshot in the log.- Specified by:
setSnapshotin interfaceLog- Parameters:
sn- The snapshot data
-
getSnapshot
Description copied from interface:LogGets the snapshot from the log- Specified by:
getSnapshotin interfaceLog- Returns:
- The snapshot, or null if not existing
-
append
Description copied from interface:LogAppend the entries starting at index. Advance last_appended by the number of entries appended.
If the operation fails, then last_appended needs to be the index of the last successful append. E.g. if last_appended is 1, and we attempt to appened 100 entries, but fail at 51, then last_appended must be 50 (not 1!). -
get
Description copied from interface:LogGets the entry at start_index. Updates current_term and last_appended accordingly -
truncate
public void truncate(long index_exclusive) Description copied from interface:LogTruncates the log up to (and excluding) index. All entries < index are removed. First = index. -
reinitializeTo
Description copied from interface:LogClears all entries and sets first_appended/last_appended/commit_index to index and appends entry at index. The next entry will be appended at last_appended+1.
Use when a snapshot has been received by a follower, after setting the snapshot, to basically create a new log- Specified by:
reinitializeToin interfaceLog- Parameters:
index- The new indexentry- The entry to append
-
deleteAllEntriesStartingFrom
public void deleteAllEntriesStartingFrom(long start_index) Description copied from interface:LogDelete all entries starting from start_index (including the entry at start_index). Updates current_term and last_appended accordingly- Specified by:
deleteAllEntriesStartingFromin interfaceLog- Parameters:
start_index-
-
forEach
Description copied from interface:LogApplies function to all elements of the log in range [max(start_index,first_appended) .. min(last_appended,end_index)]. -
forEach
Description copied from interface:LogApplies a function to all elements in range [first_appended .. last_appended] -
sizeInBytes
public long sizeInBytes()- Specified by:
sizeInBytesin interfaceLog
-
toString
-