public class LogBufferDescriptor
extends java.lang.Object
+----------------------------+ | Term 0 | +----------------------------+ | Term 1 | +----------------------------+ | Term 2 | +----------------------------+ | Log Meta Data | +----------------------------+
Modifier and Type | Field and Description |
---|---|
static int |
LOG_ACTIVE_TERM_COUNT_OFFSET
Offset within the log metadata where the active partition index is stored.
|
static int |
LOG_CORRELATION_ID_OFFSET
Offset within the log metadata which the correlation id is stored.
|
static int |
LOG_DEFAULT_FRAME_HEADER_LENGTH_OFFSET
Offset within the log metadata which the length field for the frame header is stored.
|
static int |
LOG_DEFAULT_FRAME_HEADER_MAX_LENGTH
Maximum length of a frame header.
|
static int |
LOG_DEFAULT_FRAME_HEADER_OFFSET
Offset at which the default frame headers begin.
|
static int |
LOG_END_OF_STREAM_POSITION_OFFSET
Offset within the log metadata where the position of the End of Stream is stored.
|
static int |
LOG_INITIAL_TERM_ID_OFFSET
Offset within the log metadata where the active term id is stored.
|
static int |
LOG_IS_CONNECTED_OFFSET
Offset within the log metadata where whether the log is connected or not is stored.
|
static int |
LOG_META_DATA_LENGTH
Total length of the log metadata buffer in bytes.
|
static int |
LOG_META_DATA_SECTION_INDEX
Section index for which buffer contains the log meta data.
|
static int |
LOG_MTU_LENGTH_OFFSET
Offset within the log metadata which the MTU length is stored.
|
static int |
LOG_PAGE_SIZE_OFFSET
Offset within the log metadata which the page size is stored.
|
static int |
LOG_TERM_LENGTH_OFFSET
Offset within the log metadata which the term length is stored.
|
static int |
PAGE_MAX_SIZE
Maximum page size
|
static int |
PAGE_MIN_SIZE
Minimum page size
|
static int |
PARTITION_COUNT
The number of partitions the log is divided into.
|
static int |
TERM_MAX_LENGTH
Maximum buffer length for a log term
|
static int |
TERM_MIN_LENGTH
Minimum buffer length for a log term
|
static int |
TERM_TAIL_COUNTERS_OFFSET
Offset within the metadata where the tail values are stored.
|
Constructor and Description |
---|
LogBufferDescriptor() |
Modifier and Type | Method and Description |
---|---|
static int |
activeTermCount(org.agrona.concurrent.UnsafeBuffer metadataBuffer)
Get the value of the active term count used by the producer of this log.
|
static void |
activeTermCount(org.agrona.concurrent.UnsafeBuffer metadataBuffer,
int termCount)
Set the value of the current active partition index for the producer.
|
static void |
activeTermCountOrdered(org.agrona.concurrent.UnsafeBuffer metadataBuffer,
int termCount)
Set the value of the current active term count for the producer using memory ordered semantics.
|
static void |
applyDefaultHeader(org.agrona.concurrent.UnsafeBuffer metadataBuffer,
org.agrona.concurrent.UnsafeBuffer termBuffer,
int termOffset)
Apply the default header for a message in a term.
|
static boolean |
casActiveTermCount(org.agrona.concurrent.UnsafeBuffer metadataBuffer,
int expectedTermCount,
int updateTermCount)
Compare and set the value of the current active term count.
|
static boolean |
casRawTail(org.agrona.concurrent.UnsafeBuffer metadataBuffer,
int partitionIndex,
long expectedRawTail,
long updateRawTail)
Compare and set the raw value of the tail for the given partition.
|
static void |
checkPageSize(int pageSize)
Check that page size is valid and alignment is valid.
|
static void |
checkTermLength(int termLength)
Check that term length is valid and alignment is valid.
|
static long |
computeLogLength(int termLength,
int filePageSize)
Compute the total length of a log file given the term length.
|
static long |
computePosition(int activeTermId,
int termOffset,
int positionBitsToShift,
int initialTermId)
Compute the current position in absolute number of bytes.
|
static long |
computeTermBeginPosition(int activeTermId,
int positionBitsToShift,
int initialTermId)
Compute the current position in absolute number of bytes for the beginning of a term.
|
static int |
computeTermIdFromPosition(long position,
int positionBitsToShift,
int initialTermId)
Compute the term id from a position.
|
static long |
correlationId(org.agrona.concurrent.UnsafeBuffer metadataBuffer)
Get the value of the correlation ID for this log relating to the command which created it.
|
static void |
correlationId(org.agrona.concurrent.UnsafeBuffer metadataBuffer,
long id)
Set the correlation ID used for this log relating to the command which created it.
|
static org.agrona.concurrent.UnsafeBuffer |
defaultFrameHeader(org.agrona.concurrent.UnsafeBuffer metadataBuffer)
Get a wrapper around the default frame header from the log meta data.
|
static long |
endOfStreamPosition(org.agrona.concurrent.UnsafeBuffer metadataBuffer)
Get the value of the end of stream position.
|
static void |
endOfStreamPosition(org.agrona.concurrent.UnsafeBuffer metadataBuffer,
long position)
Set the value of the end of stream position.
|
static int |
indexByPosition(long position,
int positionBitsToShift)
Determine the partition index given a stream position.
|
static int |
indexByTerm(int initialTermId,
int activeTermId)
Determine the partition index to be used given the initial term and active term ids.
|
static int |
indexByTermCount(long termCount)
Determine the partition index based on number of terms that have passed.
|
static void |
initialiseTailWithTermId(org.agrona.concurrent.UnsafeBuffer metadataBuffer,
int partitionIndex,
int termId)
Set the initial value for the termId in the upper bits of the tail counter.
|
static int |
initialTermId(org.agrona.concurrent.UnsafeBuffer metadataBuffer)
Get the value of the initial Term id used for this log.
|
static void |
initialTermId(org.agrona.concurrent.UnsafeBuffer metadataBuffer,
int initialTermId)
Set the initial term at which this log begins.
|
static boolean |
isConnected(org.agrona.concurrent.UnsafeBuffer metadataBuffer)
Get whether the log is considered connected or not by the driver.
|
static void |
isConnected(org.agrona.concurrent.UnsafeBuffer metadataBuffer,
boolean isConnected)
Set whether the log is considered connected or not by the driver.
|
static int |
mtuLength(org.agrona.concurrent.UnsafeBuffer metadataBuffer)
Get the value of the MTU length used for this log.
|
static void |
mtuLength(org.agrona.concurrent.UnsafeBuffer metadataBuffer,
int mtuLength)
Set the MTU length used for this log.
|
static int |
nextPartitionIndex(int currentIndex)
Rotate to the next partition in sequence for the term id.
|
static long |
packTail(int termId,
int termOffset)
Pack a termId and termOffset into a raw tail value.
|
static int |
pageSize(org.agrona.concurrent.UnsafeBuffer metadataBuffer)
Get the value of the page size used for this log.
|
static void |
pageSize(org.agrona.concurrent.UnsafeBuffer metadataBuffer,
int pageSize)
Set the page size used for this log.
|
static int |
positionBitsToShift(int termBufferLength)
Get the number of bits to shift when dividing or multiplying by the term buffer length.
|
static long |
rawTail(org.agrona.concurrent.UnsafeBuffer metadataBuffer,
int partitionIndex)
Get the raw value of the tail for the given partition.
|
static void |
rawTail(org.agrona.concurrent.UnsafeBuffer metadataBuffer,
int partitionIndex,
long rawTail)
Set the raw value of the tail for the given partition.
|
static long |
rawTailVolatile(org.agrona.concurrent.UnsafeBuffer metadataBuffer)
Get the raw value of the tail for the current active partition.
|
static long |
rawTailVolatile(org.agrona.concurrent.UnsafeBuffer metadataBuffer,
int partitionIndex)
Get the raw value of the tail for the given partition.
|
static void |
rawTailVolatile(org.agrona.concurrent.UnsafeBuffer metadataBuffer,
int partitionIndex,
long rawTail)
Set the raw value of the tail for the given partition.
|
static boolean |
rotateLog(org.agrona.concurrent.UnsafeBuffer metadataBuffer,
int termCount,
int termId)
Rotate the log and update the tail counter for the new term.
|
static void |
storeDefaultFrameHeader(org.agrona.concurrent.UnsafeBuffer metadataBuffer,
org.agrona.DirectBuffer defaultHeader)
Store the default frame header to the log meta data buffer.
|
static int |
termId(long rawTail)
Get the termId from a packed raw tail value.
|
static int |
termLength(org.agrona.concurrent.UnsafeBuffer metadataBuffer)
Get the value of the Term Length used for this log.
|
static void |
termLength(org.agrona.concurrent.UnsafeBuffer metadataBuffer,
int termLength)
Set the term length used for this log.
|
static int |
termOffset(long result)
The termOffset as a result of the append
|
static int |
termOffset(long rawTail,
long termLength)
Read the termOffset from a packed raw tail value.
|
public static final int PARTITION_COUNT
public static final int LOG_META_DATA_SECTION_INDEX
public static final int TERM_MIN_LENGTH
public static final int TERM_MAX_LENGTH
public static final int PAGE_MIN_SIZE
public static final int PAGE_MAX_SIZE
public static final int TERM_TAIL_COUNTERS_OFFSET
public static final int LOG_ACTIVE_TERM_COUNT_OFFSET
public static final int LOG_END_OF_STREAM_POSITION_OFFSET
public static final int LOG_IS_CONNECTED_OFFSET
public static final int LOG_INITIAL_TERM_ID_OFFSET
public static final int LOG_DEFAULT_FRAME_HEADER_LENGTH_OFFSET
public static final int LOG_MTU_LENGTH_OFFSET
public static final int LOG_CORRELATION_ID_OFFSET
public static final int LOG_TERM_LENGTH_OFFSET
public static final int LOG_PAGE_SIZE_OFFSET
public static final int LOG_DEFAULT_FRAME_HEADER_OFFSET
public static final int LOG_DEFAULT_FRAME_HEADER_MAX_LENGTH
public static final int LOG_META_DATA_LENGTH
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Tail Counter 0 | | | +---------------------------------------------------------------+ | Tail Counter 1 | | | +---------------------------------------------------------------+ | Tail Counter 2 | | | +---------------------------------------------------------------+ | Active Term Count | +---------------------------------------------------------------+ | Cache Line Padding ... ... | +---------------------------------------------------------------+ | End of Stream Position | | | +---------------------------------------------------------------+ | Is Connected | +---------------------------------------------------------------+ | Cache Line Padding ... ... | +---------------------------------------------------------------+ | Registration / Correlation ID | | | +---------------------------------------------------------------+ | Initial Term Id | +---------------------------------------------------------------+ | Default Frame Header Length | +---------------------------------------------------------------+ | MTU Length | +---------------------------------------------------------------+ | Term Length | +---------------------------------------------------------------+ | Page Size | +---------------------------------------------------------------+ | Cache Line Padding ... ... | +---------------------------------------------------------------+ | Default Frame Header ... ... | +---------------------------------------------------------------+
public static void checkTermLength(int termLength)
termLength
- to be checked.java.lang.IllegalStateException
- if the length is not as expected.public static void checkPageSize(int pageSize)
pageSize
- to be checked.java.lang.IllegalStateException
- if the size is not as expected.public static int initialTermId(org.agrona.concurrent.UnsafeBuffer metadataBuffer)
metadataBuffer
- containing the meta data.public static void initialTermId(org.agrona.concurrent.UnsafeBuffer metadataBuffer, int initialTermId)
metadataBuffer
- containing the meta data.initialTermId
- value to be set.public static int mtuLength(org.agrona.concurrent.UnsafeBuffer metadataBuffer)
metadataBuffer
- containing the meta data.public static void mtuLength(org.agrona.concurrent.UnsafeBuffer metadataBuffer, int mtuLength)
metadataBuffer
- containing the meta data.mtuLength
- value to be set.public static int termLength(org.agrona.concurrent.UnsafeBuffer metadataBuffer)
metadataBuffer
- containing the meta data.public static void termLength(org.agrona.concurrent.UnsafeBuffer metadataBuffer, int termLength)
metadataBuffer
- containing the meta data.termLength
- value to be set.public static int pageSize(org.agrona.concurrent.UnsafeBuffer metadataBuffer)
metadataBuffer
- containing the meta data.public static void pageSize(org.agrona.concurrent.UnsafeBuffer metadataBuffer, int pageSize)
metadataBuffer
- containing the meta data.pageSize
- value to be set.public static long correlationId(org.agrona.concurrent.UnsafeBuffer metadataBuffer)
metadataBuffer
- containing the meta data.public static void correlationId(org.agrona.concurrent.UnsafeBuffer metadataBuffer, long id)
metadataBuffer
- containing the meta data.id
- value to be set.public static boolean isConnected(org.agrona.concurrent.UnsafeBuffer metadataBuffer)
metadataBuffer
- containing the meta data.public static void isConnected(org.agrona.concurrent.UnsafeBuffer metadataBuffer, boolean isConnected)
metadataBuffer
- containing the meta data.isConnected
- or notpublic static long endOfStreamPosition(org.agrona.concurrent.UnsafeBuffer metadataBuffer)
metadataBuffer
- containing the meta data.public static void endOfStreamPosition(org.agrona.concurrent.UnsafeBuffer metadataBuffer, long position)
metadataBuffer
- containing the meta data.position
- value of the end of stream positionpublic static int activeTermCount(org.agrona.concurrent.UnsafeBuffer metadataBuffer)
metadataBuffer
- containing the meta data.public static void activeTermCountOrdered(org.agrona.concurrent.UnsafeBuffer metadataBuffer, int termCount)
metadataBuffer
- containing the meta data.termCount
- value of the active term count used by the producer of this log.public static boolean casActiveTermCount(org.agrona.concurrent.UnsafeBuffer metadataBuffer, int expectedTermCount, int updateTermCount)
metadataBuffer
- containing the meta data.expectedTermCount
- value of the active term count expected in the logupdateTermCount
- value of the active term count to be updated in the logpublic static void activeTermCount(org.agrona.concurrent.UnsafeBuffer metadataBuffer, int termCount)
metadataBuffer
- containing the meta data.termCount
- value of the active term count used by the producer of this log.public static int nextPartitionIndex(int currentIndex)
currentIndex
- partition indexpublic static int indexByTerm(int initialTermId, int activeTermId)
initialTermId
- at which the log buffer usage beganactiveTermId
- that is in current usagepublic static int indexByTermCount(long termCount)
termCount
- for the number of terms that have passed.public static int indexByPosition(long position, int positionBitsToShift)
position
- in the stream in bytes.positionBitsToShift
- number of times to right shift the position for term countpublic static long computePosition(int activeTermId, int termOffset, int positionBitsToShift, int initialTermId)
activeTermId
- active term id.termOffset
- in the term.positionBitsToShift
- number of times to left shift the term countinitialTermId
- the initial term id that this stream started onpublic static long computeTermBeginPosition(int activeTermId, int positionBitsToShift, int initialTermId)
activeTermId
- active term id.positionBitsToShift
- number of times to left shift the term countinitialTermId
- the initial term id that this stream started onpublic static int computeTermIdFromPosition(long position, int positionBitsToShift, int initialTermId)
position
- to calculate frompositionBitsToShift
- number of times to right shift the positioninitialTermId
- the initial term id that this stream started onpublic static long computeLogLength(int termLength, int filePageSize)
TERM_MAX_LENGTH
is 1GB and that filePageSize is 1GB or less and a power of 2.termLength
- on which to base the calculation.filePageSize
- to use for log.public static void storeDefaultFrameHeader(org.agrona.concurrent.UnsafeBuffer metadataBuffer, org.agrona.DirectBuffer defaultHeader)
metadataBuffer
- into which the default headers should be stored.defaultHeader
- to be stored.java.lang.IllegalArgumentException
- if the defaultHeader larger than LOG_DEFAULT_FRAME_HEADER_MAX_LENGTH
public static org.agrona.concurrent.UnsafeBuffer defaultFrameHeader(org.agrona.concurrent.UnsafeBuffer metadataBuffer)
metadataBuffer
- containing the raw bytes for the default frame header.public static void applyDefaultHeader(org.agrona.concurrent.UnsafeBuffer metadataBuffer, org.agrona.concurrent.UnsafeBuffer termBuffer, int termOffset)
metadataBuffer
- containing the default headers.termBuffer
- to which the default header should be applied.termOffset
- at which the default should be applied.public static boolean rotateLog(org.agrona.concurrent.UnsafeBuffer metadataBuffer, int termCount, int termId)
metadataBuffer
- for the log.termCount
- from which to rotate.termId
- to be used in the default headers.public static void initialiseTailWithTermId(org.agrona.concurrent.UnsafeBuffer metadataBuffer, int partitionIndex, int termId)
metadataBuffer
- contain the tail counter.partitionIndex
- to be initialised.termId
- to be set.public static int termId(long rawTail)
rawTail
- containing the termIdpublic static int termOffset(long rawTail, long termLength)
rawTail
- containing the termOffset.termLength
- that the offset cannot exceed.public static int termOffset(long result)
result
- into which the termOffset value has been packed.public static long packTail(int termId, int termOffset)
termId
- to be packed.termOffset
- to be packed.public static void rawTail(org.agrona.concurrent.UnsafeBuffer metadataBuffer, int partitionIndex, long rawTail)
metadataBuffer
- containing the tail counters.partitionIndex
- for the tail counter.rawTail
- to be storedpublic static long rawTail(org.agrona.concurrent.UnsafeBuffer metadataBuffer, int partitionIndex)
metadataBuffer
- containing the tail counters.partitionIndex
- for the tail counter.public static void rawTailVolatile(org.agrona.concurrent.UnsafeBuffer metadataBuffer, int partitionIndex, long rawTail)
metadataBuffer
- containing the tail counters.partitionIndex
- for the tail counter.rawTail
- to be storedpublic static long rawTailVolatile(org.agrona.concurrent.UnsafeBuffer metadataBuffer, int partitionIndex)
metadataBuffer
- containing the tail counters.partitionIndex
- for the tail counter.public static long rawTailVolatile(org.agrona.concurrent.UnsafeBuffer metadataBuffer)
metadataBuffer
- containing the tail counters.public static boolean casRawTail(org.agrona.concurrent.UnsafeBuffer metadataBuffer, int partitionIndex, long expectedRawTail, long updateRawTail)
metadataBuffer
- containing the tail counters.partitionIndex
- for the tail counter.expectedRawTail
- expected current value.updateRawTail
- to be applied.public static int positionBitsToShift(int termBufferLength)
termBufferLength
- to compute the number of bits to shift for.Copyright © 2014-2018 Real Logic Ltd. All Rights Reserved.