public class RocksDBLogStorage extends Object implements LogStorage, Describer
| 限定符和类型 | 类和说明 |
|---|---|
protected static class |
RocksDBLogStorage.EmptyWriteContext
An empty write context
|
static interface |
RocksDBLogStorage.WriteContext
A write context
|
Describer.DefaultPrinter, Describer.Printer| 限定符和类型 | 字段和说明 |
|---|---|
static byte[] |
FIRST_LOG_IDX_KEY
First log index and last log index key in configuration column family.
|
| 构造器和说明 |
|---|
RocksDBLogStorage(String path,
RaftOptions raftOptions) |
| 限定符和类型 | 方法和说明 |
|---|---|
int |
appendEntries(List<LogEntry> entries)
Append entries to log, return append success number.
|
boolean |
appendEntry(LogEntry entry)
Append entries to log.
|
static org.rocksdb.ColumnFamilyOptions |
createColumnFamilyOptions() |
static org.rocksdb.DBOptions |
createDBOptions() |
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 byte[] FIRST_LOG_IDX_KEY
public RocksDBLogStorage(String path, RaftOptions raftOptions)
public static org.rocksdb.DBOptions createDBOptions()
public static org.rocksdb.ColumnFamilyOptions createColumnFamilyOptions()
public boolean init(LogStorageOptions opts)
Lifecycleinit 在接口中 Lifecycle<LogStorageOptions>public void shutdown()
Lifecycleshutdown 在接口中 Lifecycle<LogStorageOptions>public long getFirstLogIndex()
LogStoragegetFirstLogIndex 在接口中 LogStoragepublic long getLastLogIndex()
LogStoragegetLastLogIndex 在接口中 LogStoragepublic LogEntry getEntry(long index)
LogStoragegetEntry 在接口中 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 在接口中 LogStoragepublic boolean appendEntry(LogEntry entry)
LogStorageappendEntry 在接口中 LogStoragepublic int appendEntries(List<LogEntry> entries)
LogStorageappendEntries 在接口中 LogStoragepublic boolean truncatePrefix(long firstIndexKept)
LogStoragetruncatePrefix 在接口中 LogStoragepublic boolean truncateSuffix(long lastIndexKept)
LogStoragetruncateSuffix 在接口中 LogStoragepublic boolean reset(long nextLogIndex)
LogStoragereset 在接口中 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
protected 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 © 2021. All rights reserved.