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; } }
protected AllocatedBuffer initAllocatedBuffer(final int partitionSize) { final int requiredCapacity = requiredCapacity(partitionSize); AllocatedBuffer allocatedBuffer = null; if (allocateInMemory) { allocatedBuffer = BufferAllocators.allocateDirect(requiredCapacity); } else { if (rawBuffer != null) { if (rawBuffer.remaining() < requiredCapacity) { throw new RuntimeException("Buffer size below required capacity of " + requiredCapacity); } allocatedBuffer = new ExternallyAllocatedBuffer(rawBuffer); } else { final File bufferFile = new File(bufferFileName); if (!bufferFile.exists()) { throw new RuntimeException("File " + bufferFileName + " does not exist"); } allocatedBuffer = BufferAllocators.allocateMappedFile(requiredCapacity, bufferFile); } } return allocatedBuffer; } }
public LogBuffer(AllocatedBuffer allocatedBuffer, int partitionSize, int initialPartitionId) { this.partitionSize = partitionSize; rawBuffer = allocatedBuffer; partitions = new PartitionBuilder().slicePartitions(partitionSize, rawBuffer); metadataBuffer = new UnsafeBuffer( rawBuffer.getRawBuffer(), logMetadataOffset(partitionSize), LOG_META_DATA_LENGTH); metadataBuffer.putInt(LOG_INITIAL_PARTITION_ID_OFFSET, initialPartitionId); metadataBuffer.putIntVolatile(LOG_ACTIVE_PARTITION_ID_OFFSET, initialPartitionId); }
public LogBuffer(AllocatedBuffer allocatedBuffer, int partitionSize, int initialPartitionId) { this.partitionSize = partitionSize; rawBuffer = allocatedBuffer; partitions = new PartitionBuilder().slicePartitions(partitionSize, rawBuffer); metadataBuffer = new UnsafeBuffer( rawBuffer.getRawBuffer(), logMetadataOffset(partitionSize), LOG_META_DATA_LENGTH); metadataBuffer.putInt(LOG_INITIAL_PARTITION_ID_OFFSET, initialPartitionId); metadataBuffer.putIntVolatile(LOG_ACTIVE_PARTITION_ID_OFFSET, initialPartitionId); }
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; } }
protected AllocatedBuffer initAllocatedBuffer(final int partitionSize) { final int requiredCapacity = requiredCapacity(partitionSize); AllocatedBuffer allocatedBuffer = null; if (allocateInMemory) { allocatedBuffer = BufferAllocators.allocateDirect(requiredCapacity); } else { if (rawBuffer != null) { if (rawBuffer.remaining() < requiredCapacity) { throw new RuntimeException("Buffer size below required capacity of " + requiredCapacity); } allocatedBuffer = new ExternallyAllocatedBuffer(rawBuffer); } else { final File bufferFile = new File(bufferFileName); if (!bufferFile.exists()) { throw new RuntimeException("File " + bufferFileName + " does not exist"); } allocatedBuffer = BufferAllocators.allocateMappedFile(requiredCapacity, bufferFile); } } return allocatedBuffer; } }