Unify JournalSegmentWriter.truncate()
[controller.git] / atomix-storage / src / main / java / io / atomix / storage / journal / DiskJournalSegmentWriter.java
index 7120158839145e9c3f88307fb1eb31238907a809..d3aa3332c7a56eddd71c4f36193398e386d78323 100644 (file)
@@ -134,29 +134,9 @@ final class DiskJournalSegmentWriter<E> extends JournalSegmentWriter<E> {
   }
 
   @Override
-  void truncate(final long index) {
-    // If the index is greater than or equal to the last index, skip the truncate.
-    if (index >= getLastIndex()) {
-      return;
-    }
-
-    // Reset the last entry.
-    lastEntry = null;
-
-    // Truncate the index.
-    this.index.truncate(index);
-
+  void writeEmptyHeader(final int position) {
     try {
-      if (index < firstIndex) {
-        // Reset the writer to the first entry.
-        currentPosition = JournalSegmentDescriptor.BYTES;
-      } else {
-        // Reset the writer to the given index.
-        reset(index);
-      }
-
-      // Zero the entry header at current channel position.
-      channel.write(ZERO_ENTRY_HEADER.asReadOnlyBuffer(), currentPosition);
+      channel.write(ZERO_ENTRY_HEADER.asReadOnlyBuffer(), position);
     } catch (IOException e) {
       throw new StorageException(e);
     }