[Remove] Old Translog Checkpoint Format (#1884)

This commit removes support for old translog checkpoint formats prior to 7.0.0.

Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
This commit is contained in:
Nick Knize 2022-01-11 12:58:35 -06:00 committed by GitHub
parent c457272e6b
commit 0887ac6d92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 51 deletions

View File

@ -64,13 +64,10 @@ final class Checkpoint {
final long minTranslogGeneration; final long minTranslogGeneration;
final long trimmedAboveSeqNo; final long trimmedAboveSeqNo;
private static final int VERSION_6_0_0 = 2; // introduction of global checkpoints
private static final int CURRENT_VERSION = 3; // introduction of trimmed above seq# private static final int CURRENT_VERSION = 3; // introduction of trimmed above seq#
private static final String CHECKPOINT_CODEC = "ckp"; private static final String CHECKPOINT_CODEC = "ckp";
// size of 6.4.0 checkpoint
static final int V3_FILE_SIZE = CodecUtil.headerLength(CHECKPOINT_CODEC) + Integer.BYTES // ops static final int V3_FILE_SIZE = CodecUtil.headerLength(CHECKPOINT_CODEC) + Integer.BYTES // ops
+ Long.BYTES // offset + Long.BYTES // offset
+ Long.BYTES // generation + Long.BYTES // generation
@ -78,17 +75,7 @@ final class Checkpoint {
+ Long.BYTES // maximum sequence number + Long.BYTES // maximum sequence number
+ Long.BYTES // global checkpoint + Long.BYTES // global checkpoint
+ Long.BYTES // minimum translog generation in the translog + Long.BYTES // minimum translog generation in the translog
+ Long.BYTES // maximum reachable (trimmed) sequence number, introduced in 6.4.0 + Long.BYTES // maximum reachable (trimmed) sequence number
+ CodecUtil.footerLength();
// size of 6.0.0 checkpoint
static final int V2_FILE_SIZE = CodecUtil.headerLength(CHECKPOINT_CODEC) + Integer.BYTES // ops
+ Long.BYTES // offset
+ Long.BYTES // generation
+ Long.BYTES // minimum sequence number
+ Long.BYTES // maximum sequence number
+ Long.BYTES // global checkpoint
+ Long.BYTES // minimum translog generation in the translog
+ CodecUtil.footerLength(); + CodecUtil.footerLength();
/** /**
@ -177,18 +164,6 @@ final class Checkpoint {
return new Checkpoint(offset, numOps, generation, minSeqNo, maxSeqNo, globalCheckpoint, minTranslogGeneration, trimmedAboveSeqNo); return new Checkpoint(offset, numOps, generation, minSeqNo, maxSeqNo, globalCheckpoint, minTranslogGeneration, trimmedAboveSeqNo);
} }
static Checkpoint readCheckpointV2(final DataInput in) throws IOException {
final long offset = in.readLong();
final int numOps = in.readInt();
final long generation = in.readLong();
final long minSeqNo = in.readLong();
final long maxSeqNo = in.readLong();
final long globalCheckpoint = in.readLong();
final long minTranslogGeneration = in.readLong();
final long trimmedAboveSeqNo = SequenceNumbers.UNASSIGNED_SEQ_NO;
return new Checkpoint(offset, numOps, generation, minSeqNo, maxSeqNo, globalCheckpoint, minTranslogGeneration, trimmedAboveSeqNo);
}
@Override @Override
public String toString() { public String toString() {
return "Checkpoint{" return "Checkpoint{"
@ -216,15 +191,10 @@ final class Checkpoint {
try (IndexInput indexInput = dir.openInput(path.getFileName().toString(), IOContext.DEFAULT)) { try (IndexInput indexInput = dir.openInput(path.getFileName().toString(), IOContext.DEFAULT)) {
// We checksum the entire file before we even go and parse it. If it's corrupted we barf right here. // We checksum the entire file before we even go and parse it. If it's corrupted we barf right here.
CodecUtil.checksumEntireFile(indexInput); CodecUtil.checksumEntireFile(indexInput);
final int fileVersion = CodecUtil.checkHeader(indexInput, CHECKPOINT_CODEC, VERSION_6_0_0, CURRENT_VERSION); final int fileVersion = CodecUtil.checkHeader(indexInput, CHECKPOINT_CODEC, CURRENT_VERSION, CURRENT_VERSION);
if (fileVersion == VERSION_6_0_0) { assert fileVersion == CURRENT_VERSION : fileVersion;
assert indexInput.length() == V2_FILE_SIZE : indexInput.length(); assert indexInput.length() == V3_FILE_SIZE : indexInput.length();
return Checkpoint.readCheckpointV2(indexInput); return Checkpoint.readCheckpointV3(indexInput);
} else {
assert fileVersion == CURRENT_VERSION : fileVersion;
assert indexInput.length() == V3_FILE_SIZE : indexInput.length();
return Checkpoint.readCheckpointV3(indexInput);
}
} catch (CorruptIndexException | NoSuchFileException | IndexFormatTooOldException | IndexFormatTooNewException e) { } catch (CorruptIndexException | NoSuchFileException | IndexFormatTooOldException | IndexFormatTooNewException e) {
throw new TranslogCorruptedException(path.toString(), e); throw new TranslogCorruptedException(path.toString(), e);
} }

View File

@ -3461,22 +3461,7 @@ public class TranslogTests extends OpenSearchTestCase {
expectThrows( expectThrows(
TranslogCorruptedException.class, TranslogCorruptedException.class,
IndexFormatTooOldException.class, IndexFormatTooOldException.class,
() -> Checkpoint.read(getDataPath("/org/opensearch/index/checkpoint/v1.ckp.binary")) () -> Checkpoint.read(getDataPath("/org/opensearch/index/checkpoint/v2.ckp.binary"))
);
assertThat(
Checkpoint.read(getDataPath("/org/opensearch/index/checkpoint/v2.ckp.binary")),
equalTo(
new Checkpoint(
-1312746831014894010L,
44230819,
4168771208509507653L,
6217263213205155568L,
8590850694628654668L,
3768575734506660560L,
1476009383806516272L,
SequenceNumbers.UNASSIGNED_SEQ_NO
)
)
); );
} }