public class LogBlockIndex extends Object implements SnapshotSupport
Each Event has a position inside the stream. This position addresses it uniquely and is assigned when the entry is first published to the stream. The position never changes and is preserved through maintenance operations like compaction.
In order to read an event, the position must be translated into the "physical address" of the block in which it resides in storage. Then, the block can be scanned for the event position requested.
| Modifier and Type | Field and Description |
|---|---|
protected int |
capacity |
protected org.agrona.concurrent.AtomicBuffer |
indexBuffer |
protected long |
lastVirtualPosition |
| Constructor and Description |
|---|
LogBlockIndex(int capacity,
java.util.function.Function<Integer,org.agrona.concurrent.AtomicBuffer> bufferAllocator) |
| Modifier and Type | Method and Description |
|---|---|
int |
addBlock(long logPosition,
long storageAddr)
Invoked by the log Appender thread after it has first written one or more entries to a block.
|
int |
capacity() |
long |
getAddress(int idx) |
long |
getLogPosition(int idx) |
long |
lookupBlockAddress(long position)
Returns the physical address of the block in which the log entry identified by the provided
position resides.
|
long |
lookupBlockPosition(long position)
Returns the position of the first log entry of the the block in which the log entry identified
by the provided position resides.
|
protected int |
lookupIndex(long position)
Returns the index of the block in which the log entry identified by the provided position
resides.
|
protected int |
lookupOffset(long position)
Returns the offset of the block in which the log entry identified by the provided position
resides.
|
void |
recoverFromSnapshot(InputStream inputStream)
read a snapshot from the provided input stream.
|
void |
reset()
Set the snapshot in the initial state.
|
int |
size() |
long |
writeSnapshot(OutputStream outputStream)
write a snapshot to the provided output stream
|
protected final org.agrona.concurrent.AtomicBuffer indexBuffer
protected final int capacity
protected long lastVirtualPosition
public LogBlockIndex(int capacity,
java.util.function.Function<Integer,org.agrona.concurrent.AtomicBuffer> bufferAllocator)
public long lookupBlockAddress(long position)
position - a virtual log positionpublic long lookupBlockPosition(long position)
position - a virtual log positionprotected int lookupOffset(long position)
position - a virtual log positionprotected int lookupIndex(long position)
position - a virtual log positionpublic int addBlock(long logPosition,
long storageAddr)
logPosition - the virtual position of the block (equal or smaller to the v position of the
first entry in the block)storageAddr - the physical address of the block in the underlying storagepublic int size()
public int capacity()
public long getLogPosition(int idx)
public long getAddress(int idx)
public long writeSnapshot(OutputStream outputStream) throws Exception
SnapshotSupportwriteSnapshot in interface SnapshotSupportoutputStream - the stream to write toExceptionpublic void recoverFromSnapshot(InputStream inputStream) throws Exception
SnapshotSupportrecoverFromSnapshot in interface SnapshotSupportinputStream - the stream to read fromExceptionpublic void reset()
SnapshotSupportreset in interface SnapshotSupportCopyright © 2017–2018 camunda services GmbH. All rights reserved.