public class FsLogStorage extends Object implements LogStorage
| Modifier and Type | Field and Description |
|---|---|
protected FsLogStorageConfiguration |
config |
protected FsLogSegment |
currentSegment |
protected ReadResultProcessor |
defaultReadResultProcessor |
protected int |
dirtySegmentId |
static org.slf4j.Logger |
LOG |
protected FsLogSegments |
logSegments
Readable log segments
|
protected int |
state |
protected static int |
STATE_CLOSED |
protected static int |
STATE_CREATED |
protected static int |
STATE_OPENED |
OP_RESULT_BLOCK_SIZE_TOO_BIG, OP_RESULT_INSUFFICIENT_BUFFER_CAPACITY, OP_RESULT_INVALID_ADDR, OP_RESULT_NO_DATA| Constructor and Description |
|---|
FsLogStorage(FsLogStorageConfiguration cfg,
MetricsManager metricsManager,
int partitionId) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addressCheck(int segmentId,
int segmentOffset) |
long |
append(ByteBuffer buffer)
Writes a block containing one or multiple log entries in the storage and returns the address at
which the block has been written.
|
protected void |
applyTruncatedFileIfExists(File logDir) |
protected void |
checkConsistency() |
void |
close()
Close the storage.
|
protected void |
deleteBackupFilesIfExist(File logDir) |
protected void |
ensureNotOpenedStorage() |
protected void |
ensureOpenedStorage() |
void |
flush()
Flushes all appended blocks to ensure that all blocks are written completely.
|
FsLogStorageConfiguration |
getConfig() |
long |
getFirstBlockAddress()
Returns the address of the first block in the storage or -1 if the storage is currently empty.
|
protected int |
getSegmentId(File file) |
protected void |
initLogSegments(File logDir) |
boolean |
isByteAddressable() |
boolean |
isClosed() |
boolean |
isOpen() |
protected void |
markSegmentAsDirty(FsLogSegment segment) |
protected void |
onSegmentFilled() |
void |
open()
Open the storage.
|
long |
read(ByteBuffer readBuffer,
long addr)
Naive implementation of the
LogStorage.read(ByteBuffer, long, ReadResultProcessor) method. |
long |
read(ByteBuffer readBuffer,
long addr,
ReadResultProcessor processor)
Reads bytes into the read buffer starting at addr and process the read bytes with the help of
the processor.
|
protected boolean |
shouldApplyTruncatedSegment(File logDir,
File truncatedFile,
int truncatedSegmentId) |
void |
truncate(long address)
Truncates the log up to the given address.
|
protected void |
truncateLogSegment(int segmentId,
int size)
Creates a truncated backup file of given segment.
|
public static final org.slf4j.Logger LOG
protected static final int STATE_CREATED
protected static final int STATE_OPENED
protected static final int STATE_CLOSED
protected final FsLogStorageConfiguration config
protected final ReadResultProcessor defaultReadResultProcessor
protected FsLogSegments logSegments
protected FsLogSegment currentSegment
protected int dirtySegmentId
protected volatile int state
public FsLogStorage(FsLogStorageConfiguration cfg, MetricsManager metricsManager, int partitionId)
public boolean isByteAddressable()
isByteAddressable in interface LogStoragepublic long append(ByteBuffer buffer)
LogStorageStorage implementations must guarantee eventually atomicity. When this method returns, either all the bytes must be written or none at all.
The caller of this method must guarantee that the provided block contains unfragmented log entries.
append in interface LogStoragebuffer - the buffer containing a block of log entries to be written into storageprotected void onSegmentFilled()
public void truncate(long address)
LogStoragetruncate in interface LogStorageaddress - The address at which to truncate the log.protected void addressCheck(int segmentId,
int segmentOffset)
protected void truncateLogSegment(int segmentId,
int size)
public long read(ByteBuffer readBuffer, long addr)
LogStorageLogStorage.read(ByteBuffer, long, ReadResultProcessor) method. Does
not process the bytes which are read.
Returns an operation result status code which is either
LogStorage.OP_RESULT_INVALID_ADDR: in case the provided address does not exist
LogStorage.OP_RESULT_NO_DATA: in case no data is (yet) available at that address
LogStorage.OP_RESULT_INSUFFICIENT_BUFFER_CAPACITY: in case the storage is block addressable
and the provided buffer does not have sufficient capacity to read a whole block
Buffer.position() and Buffer.limit().
This method is invoked concurrently by consumer threads of the log.
read in interface LogStoragereadBuffer - the buffer to read intoaddr - the address in the underlying storage from which bytes should be readpublic long read(ByteBuffer readBuffer, long addr, ReadResultProcessor processor)
LogStorageReturns an operation result status code which is either
LogStorage.OP_RESULT_INVALID_ADDR: in case the provided address does not exist
LogStorage.OP_RESULT_NO_DATA: in case no data is (yet) available at that address
LogStorage.OP_RESULT_INSUFFICIENT_BUFFER_CAPACITY: in case the storage is block addressable
and the provided buffer does not have sufficient capacity to read a whole block
Buffer.position() and Buffer.limit().
This method is invoked concurrently by consumer threads of the log.
read in interface LogStoragereadBuffer - the buffer to read intoaddr - the address in the underlying storage from which bytes should be readprocessor - the processor to process the buffer and the read resultpublic void open()
LogStorageopen in interface LogStorageprotected void initLogSegments(File logDir)
protected void checkConsistency()
protected void deleteBackupFilesIfExist(File logDir)
protected void applyTruncatedFileIfExists(File logDir)
protected boolean shouldApplyTruncatedSegment(File logDir, File truncatedFile, int truncatedSegmentId)
public void close()
LogStorageclose in interface LogStoragepublic void flush()
throws Exception
LogStorageLogStorage.append(ByteBuffer) guarantees that all blocks
are written immediately.flush in interface LogStorageException - if fails to flush all blocksprotected void markSegmentAsDirty(FsLogSegment segment)
public FsLogStorageConfiguration getConfig()
public long getFirstBlockAddress()
LogStoragegetFirstBlockAddress in interface LogStorageprotected void ensureOpenedStorage()
protected void ensureNotOpenedStorage()
public boolean isOpen()
isOpen in interface LogStoragetrue, if the storage is open.public boolean isClosed()
isClosed in interface LogStorageprotected int getSegmentId(File file)
Copyright © 2017–2018 camunda services GmbH. All rights reserved.