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 <robert.varga@pantheon.tech>
// 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.
*/
* @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.
*/
}
}
- @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()) {
writer.reset(index);
}
- @Override
- public void truncate(final long index) {
- writer.truncate(index);
- }
-
@Override
public void flush() {
writer.flush();
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);
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);
assertEquals(j, assertNext(reader).index());
}
- writer.truncate(i - 2);
+ writer.reset(i - 1);
assertNoNext(reader);
assertEquals(i - 1, writer.append(new TestEntry(32)).index());
reader.reset(i + 1);
}
- writer.truncate(i - 1);
+ writer.reset(i);
writer.append(ENTRY);
assertNext(reader);