Fix testRestoreLocalHistoryFromTranslog (#52441)

Asserts that no new operations are made into the translog since we re-opened the engine.

Relates #51905
Closes #52410
This commit is contained in:
Nhat Nguyen 2020-02-18 08:50:16 -05:00
parent a92bf5ec61
commit 5aa612c275
1 changed files with 4 additions and 11 deletions

View File

@ -4559,7 +4559,6 @@ public class InternalEngineTests extends EngineTestCase {
final EngineConfig engineConfig; final EngineConfig engineConfig;
final SeqNoStats prevSeqNoStats; final SeqNoStats prevSeqNoStats;
final List<DocIdSeqNoAndSource> prevDocs; final List<DocIdSeqNoAndSource> prevDocs;
final List<Translog.Operation> existingTranslog;
try (InternalEngine engine = createEngine(store, createTempDir(), globalCheckpoint::get)) { try (InternalEngine engine = createEngine(store, createTempDir(), globalCheckpoint::get)) {
engineConfig = engine.config(); engineConfig = engine.config();
for (final long seqNo : seqNos) { for (final long seqNo : seqNos) {
@ -4578,24 +4577,17 @@ public class InternalEngineTests extends EngineTestCase {
engine.syncTranslog(); engine.syncTranslog();
prevSeqNoStats = engine.getSeqNoStats(globalCheckpoint.get()); prevSeqNoStats = engine.getSeqNoStats(globalCheckpoint.get());
prevDocs = getDocIds(engine, true); prevDocs = getDocIds(engine, true);
try (Translog.Snapshot snapshot = engine.getTranslog().newSnapshot()) {
existingTranslog = TestTranslog.drainSnapshot(snapshot, false);
}
} }
try (InternalEngine engine = new InternalEngine(engineConfig)) { try (InternalEngine engine = new InternalEngine(engineConfig)) {
final Translog.TranslogGeneration currrentTranslogGeneration = new Translog.TranslogGeneration( final long currentTranslogGeneration = engine.getTranslog().currentFileGeneration();
engine.getTranslog().getTranslogUUID(), engine.getTranslog().currentFileGeneration());
engine.recoverFromTranslog(translogHandler, globalCheckpoint.get()); engine.recoverFromTranslog(translogHandler, globalCheckpoint.get());
engine.restoreLocalHistoryFromTranslog(translogHandler); engine.restoreLocalHistoryFromTranslog(translogHandler);
assertThat(getDocIds(engine, true), equalTo(prevDocs)); assertThat(getDocIds(engine, true), equalTo(prevDocs));
SeqNoStats seqNoStats = engine.getSeqNoStats(globalCheckpoint.get()); SeqNoStats seqNoStats = engine.getSeqNoStats(globalCheckpoint.get());
assertThat(seqNoStats.getLocalCheckpoint(), equalTo(prevSeqNoStats.getLocalCheckpoint())); assertThat(seqNoStats.getLocalCheckpoint(), equalTo(prevSeqNoStats.getLocalCheckpoint()));
assertThat(seqNoStats.getMaxSeqNo(), equalTo(prevSeqNoStats.getMaxSeqNo())); assertThat(seqNoStats.getMaxSeqNo(), equalTo(prevSeqNoStats.getMaxSeqNo()));
try (Translog.Snapshot snapshot = engine.getTranslog().newSnapshot()) {
assertThat("restore from local translog must not add operations to translog", assertThat("restore from local translog must not add operations to translog",
snapshot.totalOperations(), equalTo(existingTranslog.size())); engine.getTranslog().totalOperationsByMinGen(currentTranslogGeneration), equalTo(0));
assertThat(TestTranslog.drainSnapshot(snapshot, false), equalTo(existingTranslog));
}
} }
assertConsistentHistoryBetweenTranslogAndLuceneIndex(engine, createMapperService("test")); assertConsistentHistoryBetweenTranslogAndLuceneIndex(engine, createMapperService("test"));
} }
@ -6038,6 +6030,7 @@ public class InternalEngineTests extends EngineTestCase {
docs = getDocIds(engine, true); docs = getDocIds(engine, true);
} }
try (InternalEngine engine = new InternalEngine(config)) { try (InternalEngine engine = new InternalEngine(config)) {
engine.onSettingsChanged(TimeValue.MINUS_ONE, ByteSizeValue.ZERO, 0);
engine.recoverFromTranslog(translogHandler, Long.MAX_VALUE); engine.recoverFromTranslog(translogHandler, Long.MAX_VALUE);
assertThat(getDocIds(engine, randomBoolean()), equalTo(docs)); assertThat(getDocIds(engine, randomBoolean()), equalTo(docs));
if (engine.getSeqNoStats(globalCheckpoint.get()).getMaxSeqNo() == globalCheckpoint.get()) { if (engine.getSeqNoStats(globalCheckpoint.get()).getMaxSeqNo() == globalCheckpoint.get()) {