X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=atomix-storage%2Fsrc%2Fmain%2Fjava%2Fio%2Fatomix%2Fstorage%2Fjournal%2FMappedJournalSegmentWriter.java;h=99180c5840321165696796a45234f5dcfcbb237e;hb=479ecb0109aaa1c8682dd083600b777cbd68dc07;hp=d30440e6d66e9314a2c01c2dc03382fa53d9495d;hpb=3924193f0176e3f114a2dc82e45a49a684fe2375;p=controller.git diff --git a/atomix-storage/src/main/java/io/atomix/storage/journal/MappedJournalSegmentWriter.java b/atomix-storage/src/main/java/io/atomix/storage/journal/MappedJournalSegmentWriter.java index d30440e6d6..99180c5840 100644 --- a/atomix-storage/src/main/java/io/atomix/storage/journal/MappedJournalSegmentWriter.java +++ b/atomix-storage/src/main/java/io/atomix/storage/journal/MappedJournalSegmentWriter.java @@ -16,9 +16,10 @@ */ package io.atomix.storage.journal; +import static io.atomix.storage.journal.SegmentEntry.HEADER_BYTES; + import com.esotericsoftware.kryo.KryoException; import io.atomix.storage.journal.index.JournalIndex; - import java.io.IOException; import java.nio.BufferOverflowException; import java.nio.BufferUnderflowException; @@ -87,10 +88,10 @@ final class MappedJournalSegmentWriter extends JournalSegmentWriter { } @Override - FileChannelJournalSegmentWriter toFileChannel() { + DiskJournalSegmentWriter toFileChannel() { final int position = buffer.position(); close(); - return new FileChannelJournalSegmentWriter<>(this, position); + return new DiskJournalSegmentWriter<>(this, position); } @Override @@ -161,11 +162,11 @@ final class MappedJournalSegmentWriter extends JournalSegmentWriter { // Serialize the entry. int position = buffer.position(); - if (position + ENTRY_HEADER_BYTES > buffer.limit()) { + if (position + HEADER_BYTES > buffer.limit()) { throw new BufferOverflowException(); } - buffer.position(position + ENTRY_HEADER_BYTES); + buffer.position(position + HEADER_BYTES); try { namespace.serialize(entry, buffer); @@ -173,7 +174,7 @@ final class MappedJournalSegmentWriter extends JournalSegmentWriter { throw new BufferOverflowException(); } - final int length = buffer.position() - (position + ENTRY_HEADER_BYTES); + final int length = buffer.position() - (position + HEADER_BYTES); // If the entry length exceeds the maximum entry size then throw an exception. if (length > maxEntrySize) { @@ -184,14 +185,14 @@ final class MappedJournalSegmentWriter extends JournalSegmentWriter { // Compute the checksum for the entry. final CRC32 crc32 = new CRC32(); - buffer.position(position + ENTRY_HEADER_BYTES); + buffer.position(position + HEADER_BYTES); ByteBuffer slice = buffer.slice(); slice.limit(length); crc32.update(slice); final long checksum = crc32.getValue(); // Create a single byte[] in memory for the entire entry and write it as a batch to the underlying buffer. - buffer.position(position).putInt(length).putInt((int) checksum).position(position + ENTRY_HEADER_BYTES + length); + buffer.position(position).putInt(length).putInt((int) checksum).position(position + HEADER_BYTES + length); // Update the last entry with the correct index/term/length. Indexed indexedEntry = new Indexed<>(index, entry, length);