From 56a662ed288a34626852508dd23d95c266f247de Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Sun, 2 Jun 2019 18:05:14 +0200 Subject: [PATCH] Remove Support for VERSION_CHECKPOINTS Translogs (#42782) * Closes #42699 --- .../index/translog/TranslogHeader.java | 18 +++----- .../index/translog/TranslogHeaderTests.java | 41 +----------------- .../index/translog/translog-v2.binary | Bin 0 -> 43 bytes 3 files changed, 8 insertions(+), 51 deletions(-) create mode 100644 server/src/test/resources/org/elasticsearch/index/translog/translog-v2.binary diff --git a/server/src/main/java/org/elasticsearch/index/translog/TranslogHeader.java b/server/src/main/java/org/elasticsearch/index/translog/TranslogHeader.java index d47f0d9d7fdfd..332c049e13337 100644 --- a/server/src/main/java/org/elasticsearch/index/translog/TranslogHeader.java +++ b/server/src/main/java/org/elasticsearch/index/translog/TranslogHeader.java @@ -34,8 +34,6 @@ import java.nio.channels.FileChannel; import java.nio.file.Path; -import static org.elasticsearch.index.seqno.SequenceNumbers.UNASSIGNED_PRIMARY_TERM; - /** * Each translog file is started with a translog header then followed by translog operations. */ @@ -123,6 +121,9 @@ static TranslogHeader read(final String translogUUID, final Path path, final Fil if (version == VERSION_CHECKSUMS) { throw new IllegalStateException("pre-2.0 translog found [" + path + "]"); } + if (version == VERSION_CHECKPOINTS) { + throw new IllegalStateException("pre-6.3 translog found [" + path + "]"); + } // Read the translogUUID final int uuidLen = in.readInt(); if (uuidLen > channel.size()) { @@ -141,17 +142,10 @@ static TranslogHeader read(final String translogUUID, final Path path, final Fil " this translog file belongs to a different translog"); } // Read the primary term - final long primaryTerm; - if (version == VERSION_PRIMARY_TERM) { - primaryTerm = in.readLong(); - } else { - assert version == VERSION_CHECKPOINTS : "Unknown header version [" + version + "]"; - primaryTerm = UNASSIGNED_PRIMARY_TERM; - } + assert version == VERSION_PRIMARY_TERM; + final long primaryTerm = in.readLong(); // Verify the checksum - if (version >= VERSION_PRIMARY_TERM) { - Translog.verifyChecksum(in); - } + Translog.verifyChecksum(in); assert primaryTerm >= 0 : "Primary term must be non-negative [" + primaryTerm + "]; translog path [" + path + "]"; final int headerSizeInBytes = headerSizeInBytes(version, uuid.length); diff --git a/server/src/test/java/org/elasticsearch/index/translog/TranslogHeaderTests.java b/server/src/test/java/org/elasticsearch/index/translog/TranslogHeaderTests.java index 7d06e25519ac9..c3ad511783b39 100644 --- a/server/src/test/java/org/elasticsearch/index/translog/TranslogHeaderTests.java +++ b/server/src/test/java/org/elasticsearch/index/translog/TranslogHeaderTests.java @@ -19,16 +19,10 @@ package org.elasticsearch.index.translog; -import org.apache.lucene.codecs.CodecUtil; -import org.apache.lucene.store.OutputStreamDataOutput; -import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.UUIDs; -import org.elasticsearch.common.io.stream.OutputStreamStreamOutput; import org.elasticsearch.index.seqno.SequenceNumbers; import org.elasticsearch.test.ESTestCase; -import java.io.IOException; -import java.nio.channels.Channels; import java.nio.channels.FileChannel; import java.nio.file.Files; import java.nio.file.Path; @@ -36,7 +30,6 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.lessThan; public class TranslogHeaderTests extends ESTestCase { @@ -72,40 +65,10 @@ public void testCurrentHeaderVersion() throws Exception { }); } - public void testHeaderWithoutPrimaryTerm() throws Exception { - final String translogUUID = UUIDs.randomBase64UUID(); - final long generation = randomNonNegativeLong(); - final Path translogFile = createTempDir().resolve(Translog.getFilename(generation)); - try (FileChannel channel = FileChannel.open(translogFile, StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE)) { - writeHeaderWithoutTerm(channel, translogUUID); - assertThat((int)channel.position(), lessThan(TranslogHeader.headerSizeInBytes(translogUUID))); - } - try (FileChannel channel = FileChannel.open(translogFile, StandardOpenOption.READ)) { - final TranslogHeader inHeader = TranslogHeader.read(translogUUID, translogFile, channel); - assertThat(inHeader.getTranslogUUID(), equalTo(translogUUID)); - assertThat(inHeader.getPrimaryTerm(), equalTo(SequenceNumbers.UNASSIGNED_PRIMARY_TERM)); - assertThat(inHeader.sizeInBytes(), equalTo((int)channel.position())); - } - expectThrows(TranslogCorruptedException.class, () -> { - try (FileChannel channel = FileChannel.open(translogFile, StandardOpenOption.READ)) { - TranslogHeader.read(UUIDs.randomBase64UUID(), translogFile, channel); - } - }); - } - - static void writeHeaderWithoutTerm(FileChannel channel, String translogUUID) throws IOException { - final OutputStreamStreamOutput out = new OutputStreamStreamOutput(Channels.newOutputStream(channel)); - CodecUtil.writeHeader(new OutputStreamDataOutput(out), TranslogHeader.TRANSLOG_CODEC, TranslogHeader.VERSION_CHECKPOINTS); - final BytesRef uuid = new BytesRef(translogUUID); - out.writeInt(uuid.length); - out.writeBytes(uuid.bytes, uuid.offset, uuid.length); - channel.force(true); - assertThat(channel.position(), equalTo(43L)); - } - - public void testLegacyTranslogVersions() throws Exception { + public void testLegacyTranslogVersions() { checkFailsToOpen("/org/elasticsearch/index/translog/translog-v0.binary", IllegalStateException.class, "pre-1.4 translog"); checkFailsToOpen("/org/elasticsearch/index/translog/translog-v1.binary", IllegalStateException.class, "pre-2.0 translog"); + checkFailsToOpen("/org/elasticsearch/index/translog/translog-v2.binary", IllegalStateException.class, "pre-6.3 translog"); checkFailsToOpen("/org/elasticsearch/index/translog/translog-v1-truncated.binary", IllegalStateException.class, "pre-2.0 translog"); checkFailsToOpen("/org/elasticsearch/index/translog/translog-v1-corrupted-magic.binary", TranslogCorruptedException.class, "translog looks like version 1 or later, but has corrupted header"); diff --git a/server/src/test/resources/org/elasticsearch/index/translog/translog-v2.binary b/server/src/test/resources/org/elasticsearch/index/translog/translog-v2.binary new file mode 100644 index 0000000000000000000000000000000000000000..a61a02adee385e39fdc7954cd4cc4c557c8fa19f GIT binary patch literal 43 wcmcD&o+HjtQk0lioRgoBme*a literal 0 HcmV?d00001