From: Robert Varga Date: Mon, 11 Mar 2024 10:56:22 +0000 (+0100) Subject: Remove MappableJournalSegmentWriter X-Git-Tag: v8.0.5~27 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=c87be6fb22c45480e0670c60f00226597a9d975f;p=controller.git Remove MappableJournalSegmentWriter MappableJournalSegmentWriter is now just mediating implementation access -- which is always is now guarded by a reference. This means we can ditch this indirection and give out SegmentedJournalWriter directly. JIRA: CONTROLLER-2098 Change-Id: If15bdb10f9a317960aaf41aa80c57e929923ed21 Signed-off-by: Robert Varga (cherry picked from commit cca2548d39eb1c398d98aeb0280c2e47b78852ce) --- diff --git a/atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegment.java b/atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegment.java index 992c56ddfc..3c27109a22 100644 --- a/atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegment.java +++ b/atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegment.java @@ -40,10 +40,11 @@ final class JournalSegment implements AutoCloseable { private final int maxEntrySize; private final JournalIndex index; private final JournalSerdes namespace; - private final MappableJournalSegmentWriter writer; private final Set> readers = ConcurrentHashMap.newKeySet(); private final AtomicInteger references = new AtomicInteger(); private final FileChannel channel; + + private JournalSegmentWriter writer; private boolean open = true; JournalSegment( @@ -65,7 +66,7 @@ final class JournalSegment implements AutoCloseable { } catch (IOException e) { throw new StorageException(e); } - writer = new MappableJournalSegmentWriter<>(channel, this, maxEntrySize, index, namespace); + writer = new FileChannelJournalSegmentWriter<>(channel, this, maxEntrySize, index, namespace); } /** @@ -158,7 +159,7 @@ final class JournalSegment implements AutoCloseable { */ private void acquire() { if (references.getAndIncrement() == 0 && storageLevel == StorageLevel.MAPPED) { - writer.map(); + writer = writer.toMapped(); } } @@ -168,7 +169,7 @@ final class JournalSegment implements AutoCloseable { private void release() { if (references.decrementAndGet() == 0) { if (storageLevel == StorageLevel.MAPPED) { - writer.unmap(); + writer = writer.toFileChannel(); } if (!open) { finishClose(); @@ -181,7 +182,7 @@ final class JournalSegment implements AutoCloseable { * * @return The segment writer. */ - MappableJournalSegmentWriter acquireWriter() { + JournalSegmentWriter acquireWriter() { checkOpen(); acquire(); diff --git a/atomix-storage/src/main/java/io/atomix/storage/journal/MappableJournalSegmentWriter.java b/atomix-storage/src/main/java/io/atomix/storage/journal/MappableJournalSegmentWriter.java deleted file mode 100644 index 71f0589927..0000000000 --- a/atomix-storage/src/main/java/io/atomix/storage/journal/MappableJournalSegmentWriter.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2018-present Open Networking Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.atomix.storage.journal; - -import io.atomix.storage.journal.index.JournalIndex; -import java.nio.MappedByteBuffer; -import java.nio.channels.FileChannel; - -/** - * Mappable log segment writer. - */ -final class MappableJournalSegmentWriter implements JournalWriter { - private JournalSegmentWriter writer; - - MappableJournalSegmentWriter( - FileChannel channel, - JournalSegment segment, - int maxEntrySize, - JournalIndex index, - JournalSerdes namespace) { - this.writer = new FileChannelJournalSegmentWriter<>(channel, segment, maxEntrySize, index, namespace); - } - - /** - * Maps the segment writer into memory, returning the mapped buffer. - * - * @return the buffer that was mapped into memory - */ - MappedByteBuffer map() { - final var mapped = writer.toMapped(); - writer = mapped; - return mapped.buffer(); - } - - /** - * Unmaps the mapped buffer. - */ - void unmap() { - writer = writer.toFileChannel(); - } - - MappedByteBuffer buffer() { - return writer.buffer(); - } - - @Override - public long getLastIndex() { - return writer.getLastIndex(); - } - - @Override - public Indexed getLastEntry() { - return writer.getLastEntry(); - } - - @Override - public long getNextIndex() { - return writer.getNextIndex(); - } - - @Override - public Indexed append(T entry) { - return writer.append(entry); - } - - @Override - public void append(Indexed entry) { - writer.append(entry); - } - - @Override - public void commit(long index) { - writer.commit(index); - } - - @Override - public void reset(long index) { - writer.reset(index); - } - - @Override - public void truncate(long index) { - writer.truncate(index); - } - - @Override - public void flush() { - writer.flush(); - } - - @Override - public void close() { - writer.close(); - } -} diff --git a/atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedJournalWriter.java b/atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedJournalWriter.java index 4d13b2e5cc..35f7540b9e 100644 --- a/atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedJournalWriter.java +++ b/atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedJournalWriter.java @@ -23,7 +23,7 @@ import java.nio.BufferOverflowException; public final class SegmentedJournalWriter implements JournalWriter { private final SegmentedJournal journal; private JournalSegment currentSegment; - private MappableJournalSegmentWriter currentWriter; + private JournalSegmentWriter currentWriter; SegmentedJournalWriter(SegmentedJournal journal) { this.journal = journal;