public class RocksDBLogStorage extends Object implements LogStorage, Describer
| Modifier and Type | Class and Description |
|---|---|
protected static class |
RocksDBLogStorage.EmptyWriteContext
An empty write context
|
static interface |
RocksDBLogStorage.WriteContext
A write context
|
Describer.DefaultPrinter, Describer.Printer| Modifier and Type | Field and Description |
|---|---|
static byte[] |
FIRST_LOG_IDX_KEY
First log index and last log index key in configuration column family.
|
static String |
PART_ROCKSDB_OPTIONS_KEY |
| Constructor and Description |
|---|
RocksDBLogStorage(String path,
RaftOptions raftOptions) |
| Modifier and Type | Method and Description |
|---|---|
int |
appendEntries(List<LogEntry> entries)
Append entries to log, return append success number.
|
boolean |
appendEntry(LogEntry entry)
Append entries to log.
|
void |
describe(Describer.Printer out) |
LogEntry |
getEntry(long index)
Get logEntry by index.
|
long |
getFirstLogIndex()
Returns first log index in log.
|
protected byte[] |
getKeyBytes(long index) |
long |
getLastLogIndex()
Returns last log index in log.
|
long |
getTerm(long index)
Get logEntry's term by index.
|
protected byte[] |
getValueFromRocksDB(byte[] keyBytes) |
boolean |
init(LogStorageOptions opts)
Initialize the service.
|
protected boolean |
isSync() |
protected RocksDBLogStorage.WriteContext |
newWriteContext() |
protected byte[] |
onDataAppend(long logIndex,
byte[] value,
RocksDBLogStorage.WriteContext ctx)
Called before appending data entry.
|
protected byte[] |
onDataGet(long logIndex,
byte[] value)
Called after getting data from rocksdb.
|
protected boolean |
onInitLoaded()
Called after opening RocksDB and loading configuration into conf manager.
|
protected void |
onReset(long nextLogIndex)
Called after resetting db.
|
protected void |
onShutdown()
Called after closing db.
|
protected void |
onSync()
Called when sync data into file system.
|
protected void |
onTruncatePrefix(long startIndex,
long firstIndexKept)
Called after truncating prefix logs in rocksdb.
|
protected void |
onTruncateSuffix(long lastIndexKept)
Called after truncating suffix logs in rocksdb.
|
boolean |
reset(long nextLogIndex)
Drop all the existing logs and reset next log index to |next_log_index|.
|
void |
shutdown()
Dispose the resources for service.
|
boolean |
truncatePrefix(long firstIndexKept)
Delete logs from storage's head, [first_log_index, first_index_kept) will
be discarded.
|
boolean |
truncateSuffix(long lastIndexKept)
Delete uncommitted logs from storage's tail, (last_index_kept, last_log_index]
will be discarded.
|
public static final String PART_ROCKSDB_OPTIONS_KEY
public static final byte[] FIRST_LOG_IDX_KEY
public RocksDBLogStorage(String path, RaftOptions raftOptions)
public boolean init(LogStorageOptions opts)
Lifecycleinit in interface Lifecycle<LogStorageOptions>public void shutdown()
Lifecycleshutdown in interface Lifecycle<LogStorageOptions>public long getFirstLogIndex()
LogStoragegetFirstLogIndex in interface LogStoragepublic long getLastLogIndex()
LogStoragegetLastLogIndex in interface LogStoragepublic LogEntry getEntry(long index)
LogStoragegetEntry in interface LogStorageprotected byte[] getValueFromRocksDB(byte[] keyBytes)
throws org.rocksdb.RocksDBException
org.rocksdb.RocksDBExceptionprotected byte[] getKeyBytes(long index)
public long getTerm(long index)
LogStorageLogStorage.getEntry(long) to get the log id's term.getTerm in interface LogStoragepublic boolean appendEntry(LogEntry entry)
LogStorageappendEntry in interface LogStoragepublic int appendEntries(List<LogEntry> entries)
LogStorageappendEntries in interface LogStoragepublic boolean truncatePrefix(long firstIndexKept)
LogStoragetruncatePrefix in interface LogStoragepublic boolean truncateSuffix(long lastIndexKept)
LogStoragetruncateSuffix in interface LogStoragepublic boolean reset(long nextLogIndex)
LogStoragereset in interface LogStorageprotected boolean onInitLoaded()
protected void onShutdown()
protected void onReset(long nextLogIndex)
nextLogIndex - next log indexprotected void onTruncatePrefix(long startIndex,
long firstIndexKept)
throws org.rocksdb.RocksDBException,
IOException
startIndex - the start indexfirstIndexKept - the first index to keptorg.rocksdb.RocksDBExceptionIOExceptionprotected void onSync()
throws IOException,
InterruptedException
IOExceptionInterruptedExceptionprotected boolean isSync()
protected void onTruncateSuffix(long lastIndexKept)
throws org.rocksdb.RocksDBException,
IOException
lastIndexKept - the last index to keptorg.rocksdb.RocksDBExceptionIOExceptionprotected RocksDBLogStorage.WriteContext newWriteContext()
protected byte[] onDataAppend(long logIndex,
byte[] value,
RocksDBLogStorage.WriteContext ctx)
throws IOException,
InterruptedException
logIndex - the log indexvalue - the data value in log entry.IOExceptionInterruptedExceptionprotected byte[] onDataGet(long logIndex,
byte[] value)
throws IOException
logIndex - the log indexvalue - the value in rocksdbIOExceptionpublic void describe(Describer.Printer out)
Copyright © 2024. All rights reserved.