Search in sources :

Example 6 with Buffer

use of io.atomix.storage.buffer.Buffer in project atomix by atomix.

the class JournalSegmentDescriptorTest method testDescriptorPersist.

/**
 * Tests persisting the segment descriptor.
 */
@Test
public void testDescriptorPersist() {
    Buffer buffer = FileBuffer.allocate(file, JournalSegmentDescriptor.BYTES);
    JournalSegmentDescriptor descriptor = JournalSegmentDescriptor.builder(buffer).withId(2).withIndex(1025).withMaxSegmentSize(1024 * 1024).withMaxEntries(2048).build();
    assertEquals(descriptor.id(), 2);
    assertEquals(descriptor.version(), JournalSegmentDescriptor.VERSION);
    assertEquals(descriptor.index(), 1025);
    assertEquals(descriptor.maxSegmentSize(), 1024 * 1024);
    assertEquals(descriptor.maxEntries(), 2048);
    buffer.close();
    descriptor = new JournalSegmentDescriptor(FileBuffer.allocate(file, JournalSegmentDescriptor.BYTES));
    assertEquals(descriptor.id(), 2);
    assertEquals(descriptor.version(), JournalSegmentDescriptor.VERSION);
    assertEquals(descriptor.index(), 1025);
    assertEquals(descriptor.maxSegmentSize(), 1024 * 1024);
    descriptor.close();
    descriptor = new JournalSegmentDescriptor(FileBuffer.allocate(file, JournalSegmentDescriptor.BYTES));
    assertEquals(descriptor.id(), 2);
    assertEquals(descriptor.version(), JournalSegmentDescriptor.VERSION);
    assertEquals(descriptor.index(), 1025);
    assertEquals(descriptor.maxSegmentSize(), 1024 * 1024);
}
Also used : Buffer(io.atomix.storage.buffer.Buffer) FileBuffer(io.atomix.storage.buffer.FileBuffer) Test(org.junit.Test)

Example 7 with Buffer

use of io.atomix.storage.buffer.Buffer in project atomix by atomix.

the class SnapshotDescriptorTest method testCopySnapshotDescriptor.

@Test
public void testCopySnapshotDescriptor() throws Exception {
    SnapshotDescriptor descriptor = SnapshotDescriptor.builder().withIndex(2).withTimestamp(3).build();
    Buffer buffer = HeapBuffer.allocate(SnapshotDescriptor.BYTES);
    descriptor.copyTo(buffer);
    buffer.flip();
    descriptor = new SnapshotDescriptor(buffer);
    assertEquals(2, descriptor.index());
    assertEquals(3, descriptor.timestamp());
}
Also used : Buffer(io.atomix.storage.buffer.Buffer) HeapBuffer(io.atomix.storage.buffer.HeapBuffer) Test(org.junit.Test)

Example 8 with Buffer

use of io.atomix.storage.buffer.Buffer in project atomix by atomix.

the class SegmentedJournal method createMemorySegment.

/**
 * Creates a new segment.
 */
private JournalSegment<E> createMemorySegment(JournalSegmentDescriptor descriptor) {
    File segmentFile = JournalSegmentFile.createSegmentFile(name, directory, descriptor.id());
    Buffer buffer = HeapBuffer.allocate(Math.min(DEFAULT_BUFFER_SIZE, descriptor.maxSegmentSize()), Integer.MAX_VALUE);
    descriptor.copyTo(buffer);
    JournalSegment<E> segment = newSegment(new JournalSegmentFile(segmentFile), descriptor);
    log.debug("Created memory segment: {}", segment);
    return segment;
}
Also used : Buffer(io.atomix.storage.buffer.Buffer) MappedBuffer(io.atomix.storage.buffer.MappedBuffer) FileBuffer(io.atomix.storage.buffer.FileBuffer) HeapBuffer(io.atomix.storage.buffer.HeapBuffer) File(java.io.File)

Example 9 with Buffer

use of io.atomix.storage.buffer.Buffer in project atomix by atomix.

the class SegmentedJournal method loadMemorySegment.

/**
 * Loads a segment.
 */
private JournalSegment<E> loadMemorySegment(long segmentId) {
    File file = JournalSegmentFile.createSegmentFile(name, directory, segmentId);
    Buffer buffer = HeapBuffer.allocate(Math.min(DEFAULT_BUFFER_SIZE, maxSegmentSize), Integer.MAX_VALUE);
    JournalSegmentDescriptor descriptor = new JournalSegmentDescriptor(buffer);
    JournalSegment<E> segment = newSegment(new JournalSegmentFile(file), descriptor);
    log.debug("Loaded memory segment: {}", descriptor.id());
    return segment;
}
Also used : Buffer(io.atomix.storage.buffer.Buffer) MappedBuffer(io.atomix.storage.buffer.MappedBuffer) FileBuffer(io.atomix.storage.buffer.FileBuffer) HeapBuffer(io.atomix.storage.buffer.HeapBuffer) File(java.io.File)

Example 10 with Buffer

use of io.atomix.storage.buffer.Buffer in project atomix by atomix.

the class SegmentedJournal method createMappedSegment.

/**
 * Creates a new segment.
 */
private JournalSegment<E> createMappedSegment(JournalSegmentDescriptor descriptor) {
    File segmentFile = JournalSegmentFile.createSegmentFile(name, directory, descriptor.id());
    Buffer buffer = MappedBuffer.allocate(segmentFile, Math.min(DEFAULT_BUFFER_SIZE, descriptor.maxSegmentSize()), Integer.MAX_VALUE);
    descriptor.copyTo(buffer);
    JournalSegment<E> segment = newSegment(new JournalSegmentFile(segmentFile), descriptor);
    log.debug("Created memory mapped segment: {}", segment);
    return segment;
}
Also used : Buffer(io.atomix.storage.buffer.Buffer) MappedBuffer(io.atomix.storage.buffer.MappedBuffer) FileBuffer(io.atomix.storage.buffer.FileBuffer) HeapBuffer(io.atomix.storage.buffer.HeapBuffer) File(java.io.File)

Aggregations

Buffer (io.atomix.storage.buffer.Buffer)17 HeapBuffer (io.atomix.storage.buffer.HeapBuffer)14 FileBuffer (io.atomix.storage.buffer.FileBuffer)9 Test (org.junit.Test)8 MappedBuffer (io.atomix.storage.buffer.MappedBuffer)6 File (java.io.File)6 ServiceContext (io.atomix.primitive.service.ServiceContext)2 Session (io.atomix.primitive.session.Session)2 Set (io.atomix.core.counter.impl.AtomicCounterOperations.Set)1 AtomicCounterService (io.atomix.core.counter.impl.AtomicCounterService)1 Run (io.atomix.core.election.impl.LeaderElectionOperations.Run)1 LeaderElectionService (io.atomix.core.election.impl.LeaderElectionService)1 Get (io.atomix.core.map.impl.AtomicCounterMapOperations.Get)1 Put (io.atomix.core.map.impl.AtomicCounterMapOperations.Put)1 AtomicCounterMapService (io.atomix.core.map.impl.AtomicCounterMapService)1 Get (io.atomix.core.map.impl.ConsistentMapOperations.Get)1 Put (io.atomix.core.map.impl.ConsistentMapOperations.Put)1 Get (io.atomix.core.multimap.impl.ConsistentSetMultimapOperations.Get)1 Put (io.atomix.core.multimap.impl.ConsistentSetMultimapOperations.Put)1 ConsistentSetMultimapService (io.atomix.core.multimap.impl.ConsistentSetMultimapService)1