From 91bf2f5b4f1e0880ffa133b3d2a920063392811c Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 8 May 2024 15:08:44 +0200 Subject: [PATCH] Remove JournalWriter.truncate() The truncate(N) operation is completely equivalent to reset(N + 1). Remove this duplicity, preventing potential confusion. JIRA: CONTROLLER-2100 Change-Id: If62e55edfd610c87174a6b83a15c0a1a0ab7836c Signed-off-by: Robert Varga --- .../java/io/atomix/storage/journal/ByteBufWriter.java | 10 ---------- .../java/io/atomix/storage/journal/JournalWriter.java | 10 ---------- .../atomix/storage/journal/SegmentedByteBufWriter.java | 8 -------- .../atomix/storage/journal/SegmentedJournalWriter.java | 5 ----- .../io/atomix/storage/journal/AbstractJournalTest.java | 8 ++++---- 5 files changed, 4 insertions(+), 37 deletions(-) diff --git a/atomix-storage/src/main/java/io/atomix/storage/journal/ByteBufWriter.java b/atomix-storage/src/main/java/io/atomix/storage/journal/ByteBufWriter.java index 58f9d35291..910759cd17 100644 --- a/atomix-storage/src/main/java/io/atomix/storage/journal/ByteBufWriter.java +++ b/atomix-storage/src/main/java/io/atomix/storage/journal/ByteBufWriter.java @@ -55,16 +55,6 @@ public interface ByteBufWriter { // FIXME: throws IOException void reset(long index); - /** - * Truncates the log to the given index. - * - * @param index The index to which to truncate the log. - * @throws IndexOutOfBoundsException if the journal cannot be reset to specified index - */ - // FIXME: reconcile with reset() - // FIXME: throws IOException - void truncate(long index); - /** * Flushes written entries to disk. */ diff --git a/atomix-storage/src/main/java/io/atomix/storage/journal/JournalWriter.java b/atomix-storage/src/main/java/io/atomix/storage/journal/JournalWriter.java index 0561c99fe0..649e43e4ef 100644 --- a/atomix-storage/src/main/java/io/atomix/storage/journal/JournalWriter.java +++ b/atomix-storage/src/main/java/io/atomix/storage/journal/JournalWriter.java @@ -51,18 +51,8 @@ public interface JournalWriter { * @param index the next index to write * @throws IndexOutOfBoundsException if the journal cannot be reset to specified index */ - // FIXME: reconcile with reader's reset and truncate() void reset(long index); - /** - * Truncates the log to the given index. - * - * @param index The index to which to truncate the log. - * @throws IndexOutOfBoundsException if the journal cannot be reset to specified index - */ - // FIXME: reconcile with reset() - void truncate(long index); - /** * Flushes written entries to disk. */ diff --git a/atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedByteBufWriter.java b/atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedByteBufWriter.java index 6d50ef642f..5ef55393fe 100644 --- a/atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedByteBufWriter.java +++ b/atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedByteBufWriter.java @@ -87,14 +87,6 @@ final class SegmentedByteBufWriter implements ByteBufWriter { } } - @Override - public void truncate(final long index) { - if (index < journal.getCommitIndex()) { - throw new IndexOutOfBoundsException("Cannot truncate committed index: " + index); - } - checkedTruncate(index); - } - private void checkedTruncate(final long index) { // Delete all segments with first indexes greater than the given index. while (index < currentSegment.firstIndex() && currentSegment != journal.firstSegment()) { 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 11aa6c2431..a5e0737940 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 @@ -51,11 +51,6 @@ final class SegmentedJournalWriter implements JournalWriter { writer.reset(index); } - @Override - public void truncate(final long index) { - writer.truncate(index); - } - @Override public void flush() { writer.flush(); diff --git a/atomix-storage/src/test/java/io/atomix/storage/journal/AbstractJournalTest.java b/atomix-storage/src/test/java/io/atomix/storage/journal/AbstractJournalTest.java index 8abc2b2779..6118f600cd 100644 --- a/atomix-storage/src/test/java/io/atomix/storage/journal/AbstractJournalTest.java +++ b/atomix-storage/src/test/java/io/atomix/storage/journal/AbstractJournalTest.java @@ -153,7 +153,7 @@ public abstract class AbstractJournalTest { assertNoNext(reader); // Truncate the journal and write a different entry. - writer.truncate(1); + writer.reset(2); assertEquals(2, writer.getNextIndex()); writer.append(ENTRY); reader.reset(2); @@ -204,7 +204,7 @@ public abstract class AbstractJournalTest { indexed = assertNext(reader); assertEquals(1, indexed.index()); - writer.truncate(0); + writer.reset(1); assertEquals(0, journal.lastIndex()); assertEquals(1, writer.getNextIndex()); indexed = writer.append(ENTRY); @@ -232,7 +232,7 @@ public abstract class AbstractJournalTest { assertEquals(j, assertNext(reader).index()); } - writer.truncate(i - 2); + writer.reset(i - 1); assertNoNext(reader); assertEquals(i - 1, writer.append(new TestEntry(32)).index()); @@ -269,7 +269,7 @@ public abstract class AbstractJournalTest { reader.reset(i + 1); } - writer.truncate(i - 1); + writer.reset(i); writer.append(ENTRY); assertNext(reader); -- 2.36.6