Skip to content

Commit 804476c

Browse files
HoholDaveCTurner
authored andcommitted
Remove support for old translog checkpoint formats (#44280)
This commit removes support for the translog checkpoint format from versions before 6.0.0 since 7.x versions are incompatible with indices from these versions. Relates #44720 Fixes #44210
1 parent 51aefbd commit 804476c

4 files changed

Lines changed: 27 additions & 38 deletions

File tree

server/src/main/java/org/elasticsearch/index/translog/Checkpoint.java

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ final class Checkpoint {
5151
final long minTranslogGeneration;
5252
final long trimmedAboveSeqNo;
5353

54-
private static final int INITIAL_VERSION = 1; // start with 1, just to recognize there was some magic serialization logic before
5554
private static final int VERSION_6_0_0 = 2; // introduction of global checkpoints
5655
private static final int CURRENT_VERSION = 3; // introduction of trimmed above seq#
5756

@@ -63,10 +62,10 @@ final class Checkpoint {
6362
+ Integer.BYTES // ops
6463
+ Long.BYTES // offset
6564
+ Long.BYTES // generation
66-
+ Long.BYTES // minimum sequence number, introduced in 6.0.0
67-
+ Long.BYTES // maximum sequence number, introduced in 6.0.0
68-
+ Long.BYTES // global checkpoint, introduced in 6.0.0
69-
+ Long.BYTES // minimum translog generation in the translog - introduced in 6.0.0
65+
+ Long.BYTES // minimum sequence number
66+
+ Long.BYTES // maximum sequence number
67+
+ Long.BYTES // global checkpoint
68+
+ Long.BYTES // minimum translog generation in the translog
7069
+ Long.BYTES // maximum reachable (trimmed) sequence number, introduced in 6.4.0
7170
+ CodecUtil.footerLength();
7271

@@ -75,17 +74,10 @@ final class Checkpoint {
7574
+ Integer.BYTES // ops
7675
+ Long.BYTES // offset
7776
+ Long.BYTES // generation
78-
+ Long.BYTES // minimum sequence number, introduced in 6.0.0
79-
+ Long.BYTES // maximum sequence number, introduced in 6.0.0
80-
+ Long.BYTES // global checkpoint, introduced in 6.0.0
81-
+ Long.BYTES // minimum translog generation in the translog - introduced in 6.0.0
82-
+ CodecUtil.footerLength();
83-
84-
// size of 5.0.0 checkpoint
85-
static final int V1_FILE_SIZE = CodecUtil.headerLength(CHECKPOINT_CODEC)
86-
+ Integer.BYTES // ops
87-
+ Long.BYTES // offset
88-
+ Long.BYTES // generation
77+
+ Long.BYTES // minimum sequence number
78+
+ Long.BYTES // maximum sequence number
79+
+ Long.BYTES // global checkpoint
80+
+ Long.BYTES // minimum translog generation in the translog
8981
+ CodecUtil.footerLength();
9082

9183
/**
@@ -136,7 +128,7 @@ static Checkpoint emptyTranslogCheckpoint(final long offset, final long generati
136128
return new Checkpoint(offset, 0, generation, minSeqNo, maxSeqNo, globalCheckpoint, minTranslogGeneration, trimmedAboveSeqNo);
137129
}
138130

139-
static Checkpoint readCheckpointV6_4_0(final DataInput in) throws IOException {
131+
static Checkpoint readCheckpointV3(final DataInput in) throws IOException {
140132
final long offset = in.readLong();
141133
final int numOps = in.readInt();
142134
final long generation = in.readLong();
@@ -148,7 +140,7 @@ static Checkpoint readCheckpointV6_4_0(final DataInput in) throws IOException {
148140
return new Checkpoint(offset, numOps, generation, minSeqNo, maxSeqNo, globalCheckpoint, minTranslogGeneration, trimmedAboveSeqNo);
149141
}
150142

151-
static Checkpoint readCheckpointV6_0_0(final DataInput in) throws IOException {
143+
static Checkpoint readCheckpointV2(final DataInput in) throws IOException {
152144
final long offset = in.readLong();
153145
final int numOps = in.readInt();
154146
final long generation = in.readLong();
@@ -160,19 +152,6 @@ static Checkpoint readCheckpointV6_0_0(final DataInput in) throws IOException {
160152
return new Checkpoint(offset, numOps, generation, minSeqNo, maxSeqNo, globalCheckpoint, minTranslogGeneration, trimmedAboveSeqNo);
161153
}
162154

163-
// reads a checksummed checkpoint introduced in ES 5.0.0
164-
static Checkpoint readCheckpointV5_0_0(final DataInput in) throws IOException {
165-
final long offset = in.readLong();
166-
final int numOps = in.readInt();
167-
final long generation = in.readLong();
168-
final long minSeqNo = SequenceNumbers.NO_OPS_PERFORMED;
169-
final long maxSeqNo = SequenceNumbers.NO_OPS_PERFORMED;
170-
final long globalCheckpoint = SequenceNumbers.UNASSIGNED_SEQ_NO;
171-
final long minTranslogGeneration = -1;
172-
final long trimmedAboveSeqNo = SequenceNumbers.UNASSIGNED_SEQ_NO;
173-
return new Checkpoint(offset, numOps, generation, minSeqNo, maxSeqNo, globalCheckpoint, minTranslogGeneration, trimmedAboveSeqNo);
174-
}
175-
176155
@Override
177156
public String toString() {
178157
return "Checkpoint{" +
@@ -192,17 +171,14 @@ public static Checkpoint read(Path path) throws IOException {
192171
try (IndexInput indexInput = dir.openInput(path.getFileName().toString(), IOContext.DEFAULT)) {
193172
// We checksum the entire file before we even go and parse it. If it's corrupted we barf right here.
194173
CodecUtil.checksumEntireFile(indexInput);
195-
final int fileVersion = CodecUtil.checkHeader(indexInput, CHECKPOINT_CODEC, INITIAL_VERSION, CURRENT_VERSION);
196-
if (fileVersion == INITIAL_VERSION) {
197-
assert indexInput.length() == V1_FILE_SIZE : indexInput.length();
198-
return Checkpoint.readCheckpointV5_0_0(indexInput);
199-
} else if (fileVersion == VERSION_6_0_0) {
174+
final int fileVersion = CodecUtil.checkHeader(indexInput, CHECKPOINT_CODEC, VERSION_6_0_0, CURRENT_VERSION);
175+
if (fileVersion == VERSION_6_0_0) {
200176
assert indexInput.length() == V2_FILE_SIZE : indexInput.length();
201-
return Checkpoint.readCheckpointV6_0_0(indexInput);
177+
return Checkpoint.readCheckpointV2(indexInput);
202178
} else {
203179
assert fileVersion == CURRENT_VERSION : fileVersion;
204180
assert indexInput.length() == V3_FILE_SIZE : indexInput.length();
205-
return Checkpoint.readCheckpointV6_4_0(indexInput);
181+
return Checkpoint.readCheckpointV3(indexInput);
206182
}
207183
} catch (CorruptIndexException | NoSuchFileException | IndexFormatTooOldException | IndexFormatTooNewException e) {
208184
throw new TranslogCorruptedException(path.toString(), e);

server/src/test/java/org/elasticsearch/index/translog/TranslogTests.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.apache.lucene.document.Field;
2626
import org.apache.lucene.document.NumericDocValuesField;
2727
import org.apache.lucene.document.TextField;
28+
import org.apache.lucene.index.IndexFormatTooOldException;
2829
import org.apache.lucene.index.Term;
2930
import org.apache.lucene.mockfile.FilterFileChannel;
3031
import org.apache.lucene.mockfile.FilterFileSystemProvider;
@@ -2791,6 +2792,18 @@ public void testCheckpointOnDiskFull() throws IOException {
27912792
assertEquals(read, checkpoint);
27922793
}
27932794

2795+
public void testLegacyCheckpointVersion() throws IOException {
2796+
expectThrows(
2797+
TranslogCorruptedException.class,
2798+
IndexFormatTooOldException.class,
2799+
() -> Checkpoint.read(getDataPath("/org/elasticsearch/index/checkpoint/v1.ckp.binary"))
2800+
);
2801+
assertThat(Checkpoint.read(getDataPath("/org/elasticsearch/index/checkpoint/v2.ckp.binary")),
2802+
equalTo(new Checkpoint(-1312746831014894010L, 44230819, 4168771208509507653L, 6217263213205155568L,
2803+
8590850694628654668L, 3768575734506660560L, 1476009383806516272L,
2804+
SequenceNumbers.UNASSIGNED_SEQ_NO)));
2805+
}
2806+
27942807
/**
27952808
* Tests that closing views after the translog is fine and we can reopen the translog
27962809
*/
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)