From 5aa612c2759b9f025e429a0075161c4271c054a8 Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Tue, 18 Feb 2020 08:50:16 -0500 Subject: [PATCH] Fix testRestoreLocalHistoryFromTranslog (#52441) Asserts that no new operations are made into the translog since we re-opened the engine. Relates #51905 Closes #52410 --- .../index/engine/InternalEngineTests.java | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java b/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java index 5e21db432ce..db831aa5479 100644 --- a/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java +++ b/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java @@ -4559,7 +4559,6 @@ public class InternalEngineTests extends EngineTestCase { final EngineConfig engineConfig; final SeqNoStats prevSeqNoStats; final List prevDocs; - final List existingTranslog; try (InternalEngine engine = createEngine(store, createTempDir(), globalCheckpoint::get)) { engineConfig = engine.config(); for (final long seqNo : seqNos) { @@ -4578,24 +4577,17 @@ public class InternalEngineTests extends EngineTestCase { engine.syncTranslog(); prevSeqNoStats = engine.getSeqNoStats(globalCheckpoint.get()); prevDocs = getDocIds(engine, true); - try (Translog.Snapshot snapshot = engine.getTranslog().newSnapshot()) { - existingTranslog = TestTranslog.drainSnapshot(snapshot, false); - } } try (InternalEngine engine = new InternalEngine(engineConfig)) { - final Translog.TranslogGeneration currrentTranslogGeneration = new Translog.TranslogGeneration( - engine.getTranslog().getTranslogUUID(), engine.getTranslog().currentFileGeneration()); + final long currentTranslogGeneration = engine.getTranslog().currentFileGeneration(); engine.recoverFromTranslog(translogHandler, globalCheckpoint.get()); engine.restoreLocalHistoryFromTranslog(translogHandler); assertThat(getDocIds(engine, true), equalTo(prevDocs)); SeqNoStats seqNoStats = engine.getSeqNoStats(globalCheckpoint.get()); assertThat(seqNoStats.getLocalCheckpoint(), equalTo(prevSeqNoStats.getLocalCheckpoint())); assertThat(seqNoStats.getMaxSeqNo(), equalTo(prevSeqNoStats.getMaxSeqNo())); - try (Translog.Snapshot snapshot = engine.getTranslog().newSnapshot()) { - assertThat("restore from local translog must not add operations to translog", - snapshot.totalOperations(), equalTo(existingTranslog.size())); - assertThat(TestTranslog.drainSnapshot(snapshot, false), equalTo(existingTranslog)); - } + assertThat("restore from local translog must not add operations to translog", + engine.getTranslog().totalOperationsByMinGen(currentTranslogGeneration), equalTo(0)); } assertConsistentHistoryBetweenTranslogAndLuceneIndex(engine, createMapperService("test")); } @@ -6038,6 +6030,7 @@ public class InternalEngineTests extends EngineTestCase { docs = getDocIds(engine, true); } try (InternalEngine engine = new InternalEngine(config)) { + engine.onSettingsChanged(TimeValue.MINUS_ONE, ByteSizeValue.ZERO, 0); engine.recoverFromTranslog(translogHandler, Long.MAX_VALUE); assertThat(getDocIds(engine, randomBoolean()), equalTo(docs)); if (engine.getSeqNoStats(globalCheckpoint.get()).getMaxSeqNo() == globalCheckpoint.get()) {