public int cleanPartitions() { int workCount = 0; for (int i = 0; i < LogBufferDescriptor.PARTITION_COUNT; i++) { final LogBufferPartition partition = partitions[i]; if (partition.getStatusVolatile() == PARTITION_NEEDS_CLEANING) { partition.clean(); ++workCount; } } return workCount; }
public int claim( final LogBufferPartition partition, final int activePartitionId, final ClaimedFragmentBatch batch, final int fragmentCount, final int batchLength, final Runnable onComplete) { final int partitionSize = partition.getPartitionSize(); // reserve enough space for frame alignment because each batch fragment must start on an aligned // position final int framedMessageLength = batchLength + fragmentCount * (HEADER_LENGTH + FRAME_ALIGNMENT) + FRAME_ALIGNMENT; final int alignedFrameLength = align(framedMessageLength, FRAME_ALIGNMENT); // move the tail of the partition final int frameOffset = partition.getAndAddTail(alignedFrameLength); int newTail = frameOffset + alignedFrameLength; if (newTail <= (partitionSize - HEADER_LENGTH)) { final UnsafeBuffer buffer = partition.getDataBuffer(); // all fragment data are written using the claimed batch batch.wrap(buffer, activePartitionId, frameOffset, alignedFrameLength, onComplete); } else { newTail = onEndOfPartition(partition, frameOffset); } return newTail; }
public void onActiveParitionFilled(int activePartitionId) { final int nextPartitionId = 1 + activePartitionId; final int nextNextPartitionId = 1 + nextPartitionId; final LogBufferPartition nextNextPartition = partitions[(nextNextPartitionId) % getPartitionCount()]; nextNextPartition.setStatusOrdered(PARTITION_NEEDS_CLEANING); metadataBuffer.putIntOrdered(LOG_ACTIVE_PARTITION_ID_OFFSET, nextPartitionId); }
long limit, final boolean isStreamAware) { final UnsafeBuffer buffer = partition.getDataBuffer(); final int bufferOffset = partition.getUnderlyingBufferOffset(); final int firstFragmentOffset = partitionOffset; offsetLimit = partition.getPartitionSize(); partitionOffset += alignedLength(framedLength); if (partitionOffset >= partition.getPartitionSize()) { partitionId += 1; partitionOffset = 0;
@SuppressWarnings("restriction") protected int onEndOfPartition(final LogBufferPartition partition, final int partitionOffset) { int newTail = RESULT_END_OF_PARTITION; final int padLength = partition.getPartitionSize() - partitionOffset; if (padLength >= HEADER_LENGTH) { // this message tripped the end of the partition, fill buffer with padding final UnsafeBuffer buffer = partition.getDataBuffer(); buffer.putIntOrdered(lengthOffset(partitionOffset), -padLength); UNSAFE.storeFence(); buffer.putShort(typeOffset(partitionOffset), TYPE_PADDING); buffer.putIntOrdered(lengthOffset(partitionOffset), padLength); newTail = RESULT_PADDING_AT_END_OF_PARTITION; } return newTail; } }
final LogBufferPartition partition = logBuffer.getPartition(activePartitionId); final int partitionOffset = partition.getTailCounterVolatile(); final long position = position(activePartitionId, partitionOffset);
public LogBufferPartition[] slicePartitions(int partitionSize, AllocatedBuffer allocatedBuffer) { final ByteBuffer buffer = allocatedBuffer.getRawBuffer(); final LogBufferPartition[] partitions = new LogBufferPartition[PARTITION_COUNT]; for (int i = 0; i < PARTITION_COUNT; i++) { final int dataSectionOffset = partitionDataSectionOffset(partitionSize, i); final int metaDataSectionOffset = partitionMetadataSectionOffset(partitionSize, i); final UnsafeBuffer dataSection = new UnsafeBuffer(buffer, dataSectionOffset, partitionSize); final UnsafeBuffer metadataSection = new UnsafeBuffer(buffer, metaDataSectionOffset, PARTITION_META_DATA_LENGTH); partitions[i] = new LogBufferPartition(dataSection, metadataSection, dataSectionOffset); } return partitions; } }
public boolean needsCleaning() { return getStatusVolatile() == PARTITION_NEEDS_CLEANING; }
long limit, final boolean isStreamAware) { final UnsafeBuffer buffer = partition.getDataBuffer(); final int bufferOffset = partition.getUnderlyingBufferOffset(); final int firstFragmentOffset = partitionOffset; offsetLimit = partition.getPartitionSize(); partitionOffset += alignedLength(framedLength); if (partitionOffset >= partition.getPartitionSize()) { partitionId += 1; partitionOffset = 0;
@SuppressWarnings("restriction") protected int onEndOfPartition(final LogBufferPartition partition, final int partitionOffset) { int newTail = RESULT_END_OF_PARTITION; final int padLength = partition.getPartitionSize() - partitionOffset; if (padLength >= HEADER_LENGTH) { // this message tripped the end of the partition, fill buffer with padding final UnsafeBuffer buffer = partition.getDataBuffer(); buffer.putIntOrdered(lengthOffset(partitionOffset), -padLength); UNSAFE.storeFence(); buffer.putShort(typeOffset(partitionOffset), TYPE_PADDING); buffer.putIntOrdered(lengthOffset(partitionOffset), padLength); newTail = RESULT_PADDING_AT_END_OF_PARTITION; } return newTail; } }
final LogBufferPartition partition = logBuffer.getPartition(activePartitionId); final int partitionOffset = partition.getTailCounterVolatile(); final long position = position(activePartitionId, partitionOffset);
public LogBufferPartition[] slicePartitions(int partitionSize, AllocatedBuffer allocatedBuffer) { final ByteBuffer buffer = allocatedBuffer.getRawBuffer(); final LogBufferPartition[] partitions = new LogBufferPartition[PARTITION_COUNT]; for (int i = 0; i < PARTITION_COUNT; i++) { final int dataSectionOffset = partitionDataSectionOffset(partitionSize, i); final int metaDataSectionOffset = partitionMetadataSectionOffset(partitionSize, i); final UnsafeBuffer dataSection = new UnsafeBuffer(buffer, dataSectionOffset, partitionSize); final UnsafeBuffer metadataSection = new UnsafeBuffer(buffer, metaDataSectionOffset, PARTITION_META_DATA_LENGTH); partitions[i] = new LogBufferPartition(dataSection, metadataSection, dataSectionOffset); } return partitions; } }
public boolean needsCleaning() { return getStatusVolatile() == PARTITION_NEEDS_CLEANING; }
public int claim( final LogBufferPartition partition, final int activePartitionId, final ClaimedFragmentBatch batch, final int fragmentCount, final int batchLength, final Runnable onComplete) { final int partitionSize = partition.getPartitionSize(); // reserve enough space for frame alignment because each batch fragment must start on an aligned // position final int framedMessageLength = batchLength + fragmentCount * (HEADER_LENGTH + FRAME_ALIGNMENT) + FRAME_ALIGNMENT; final int alignedFrameLength = align(framedMessageLength, FRAME_ALIGNMENT); // move the tail of the partition final int frameOffset = partition.getAndAddTail(alignedFrameLength); int newTail = frameOffset + alignedFrameLength; if (newTail <= (partitionSize - HEADER_LENGTH)) { final UnsafeBuffer buffer = partition.getDataBuffer(); // all fragment data are written using the claimed batch batch.wrap(buffer, activePartitionId, frameOffset, alignedFrameLength, onComplete); } else { newTail = onEndOfPartition(partition, frameOffset); } return newTail; }
final long limit, boolean handlerControlled) { final UnsafeBuffer buffer = partition.getDataBuffer(); fragmentOffset += alignedLength(framedLength); if (fragmentOffset >= partition.getPartitionSize()) { ++partitionId; fragmentOffset = 0;
public int cleanPartitions() { int workCount = 0; for (int i = 0; i < LogBufferDescriptor.PARTITION_COUNT; i++) { final LogBufferPartition partition = partitions[i]; if (partition.getStatusVolatile() == PARTITION_NEEDS_CLEANING) { partition.clean(); ++workCount; } } return workCount; }
final LogBufferPartition partition = logBuffer.getPartition(activePartitionId); final int partitionOffset = partition.getTailCounterVolatile(); final long position = position(activePartitionId, partitionOffset);
public void clean() { dataBuffer.setMemory(0, partitionSize, (byte) 0); metadataBuffer.putInt(PARTITION_TAIL_COUNTER_OFFSET, 0); setStatusOrdered(PARTITION_CLEAN); }
@SuppressWarnings("restriction") public int claim( final LogBufferPartition partition, final int activePartitionId, final ClaimedFragment claim, final int length, final int streamId, Runnable onComplete) { final int partitionSize = partition.getPartitionSize(); final int framedMessageLength = framedLength(length); final int alignedFrameLength = alignedLength(framedMessageLength); // move the tail of the partition final int frameOffset = partition.getAndAddTail(alignedFrameLength); int newTail = frameOffset + alignedFrameLength; if (newTail <= (partitionSize - HEADER_LENGTH)) { final UnsafeBuffer buffer = partition.getDataBuffer(); // write negative length field buffer.putIntOrdered(lengthOffset(frameOffset), -framedMessageLength); UNSAFE.storeFence(); buffer.putShort(typeOffset(frameOffset), TYPE_MESSAGE); buffer.putInt(streamIdOffset(frameOffset), streamId); claim.wrap(buffer, frameOffset, framedMessageLength, onComplete); // Do not commit the message } else { newTail = onEndOfPartition(partition, frameOffset); } return newTail; }
final long limit, boolean handlerControlled) { final UnsafeBuffer buffer = partition.getDataBuffer(); fragmentOffset += alignedLength(framedLength); if (fragmentOffset >= partition.getPartitionSize()) { ++partitionId; fragmentOffset = 0;