+ @Override
+ public void reset(final long index) {
+ final long commitIndex = journal.getCommitIndex();
+ if (index <= commitIndex) {
+ // also catches index == 0, which is not a valid next index
+ throw new IndexOutOfBoundsException("Cannot reset to: " + index + ", committed index: " + commitIndex);
+ }
+
+ if (index > currentSegment.firstIndex()) {
+ currentSegment.releaseWriter();
+ currentSegment = journal.resetSegments(index);
+ currentWriter = currentSegment.acquireWriter();
+ } else {
+ checkedTruncate(index - 1);
+ }
+ journal.resetHead(index);
+ }
+