TEST: trim unsafe commits before opening engine

Since #29260, unsafe commits must be trimmed before opening an engine.
This makes the engine constructor follow Lucene standard semantics and
use the last commit. However, we haven't fully applied this change in some
tests.

Relates #29260
This commit is contained in:
Nhat Nguyen 2018-03-29 14:16:18 -04:00
parent eb8b31746a
commit 04dd738782
1 changed files with 17 additions and 11 deletions

View File

@ -644,6 +644,7 @@ public class InternalEngineTests extends EngineTestCase {
InternalEngine engine = createEngine(store, translog); InternalEngine engine = createEngine(store, translog);
engine.close(); engine.close();
trimUnsafeCommits(engine.config());
engine = new InternalEngine(engine.config()); engine = new InternalEngine(engine.config());
assertTrue(engine.isRecovering()); assertTrue(engine.isRecovering());
engine.recoverFromTranslog(); engine.recoverFromTranslog();
@ -659,6 +660,7 @@ public class InternalEngineTests extends EngineTestCase {
engine.index(indexForDoc(doc)); engine.index(indexForDoc(doc));
engine.close(); engine.close();
trimUnsafeCommits(engine.config());
engine = new InternalEngine(engine.config()); engine = new InternalEngine(engine.config());
expectThrows(IllegalStateException.class, () -> engine.flush(true, true)); expectThrows(IllegalStateException.class, () -> engine.flush(true, true));
assertTrue(engine.isRecovering()); assertTrue(engine.isRecovering());
@ -690,18 +692,14 @@ public class InternalEngineTests extends EngineTestCase {
} finally { } finally {
IOUtils.close(engine); IOUtils.close(engine);
} }
trimUnsafeCommits(engine.config());
Engine recoveringEngine = null; try (Engine recoveringEngine = new InternalEngine(engine.config())){
try {
recoveringEngine = new InternalEngine(engine.config());
recoveringEngine.recoverFromTranslog(); recoveringEngine.recoverFromTranslog();
try (Engine.Searcher searcher = recoveringEngine.acquireSearcher("test")) { try (Engine.Searcher searcher = recoveringEngine.acquireSearcher("test")) {
final TotalHitCountCollector collector = new TotalHitCountCollector(); final TotalHitCountCollector collector = new TotalHitCountCollector();
searcher.searcher().search(new MatchAllDocsQuery(), collector); searcher.searcher().search(new MatchAllDocsQuery(), collector);
assertThat(collector.getTotalHits(), equalTo(operations.get(operations.size() - 1) instanceof Engine.Delete ? 0 : 1)); assertThat(collector.getTotalHits(), equalTo(operations.get(operations.size() - 1) instanceof Engine.Delete ? 0 : 1));
} }
} finally {
IOUtils.close(recoveringEngine);
} }
} }
@ -722,6 +720,7 @@ public class InternalEngineTests extends EngineTestCase {
Engine recoveringEngine = null; Engine recoveringEngine = null;
try { try {
final AtomicBoolean committed = new AtomicBoolean(); final AtomicBoolean committed = new AtomicBoolean();
trimUnsafeCommits(initialEngine.config());
recoveringEngine = new InternalEngine(initialEngine.config()) { recoveringEngine = new InternalEngine(initialEngine.config()) {
@Override @Override
@ -1151,6 +1150,7 @@ public class InternalEngineTests extends EngineTestCase {
SequenceNumbers.UNASSIGNED_SEQ_NO, shardId); SequenceNumbers.UNASSIGNED_SEQ_NO, shardId);
store.associateIndexWithNewTranslog(translogUUID); store.associateIndexWithNewTranslog(translogUUID);
} }
trimUnsafeCommits(config);
engine = new InternalEngine(config); engine = new InternalEngine(config);
engine.recoverFromTranslog(); engine.recoverFromTranslog();
assertEquals(engine.getLastCommittedSegmentInfos().getUserData().get(Engine.SYNC_COMMIT_ID), syncId); assertEquals(engine.getLastCommittedSegmentInfos().getUserData().get(Engine.SYNC_COMMIT_ID), syncId);
@ -2054,9 +2054,8 @@ public class InternalEngineTests extends EngineTestCase {
IOUtils.close(initialEngine); IOUtils.close(initialEngine);
} }
InternalEngine recoveringEngine = null; trimUnsafeCommits(initialEngine.engineConfig);
try { try (InternalEngine recoveringEngine = new InternalEngine(initialEngine.config())){
recoveringEngine = new InternalEngine(initialEngine.config());
recoveringEngine.recoverFromTranslog(); recoveringEngine.recoverFromTranslog();
assertEquals(primarySeqNo, recoveringEngine.getLocalCheckpointTracker().getMaxSeqNo()); assertEquals(primarySeqNo, recoveringEngine.getLocalCheckpointTracker().getMaxSeqNo());
@ -2075,8 +2074,6 @@ public class InternalEngineTests extends EngineTestCase {
assertThat(recoveringEngine.getLocalCheckpointTracker().getCheckpoint(), equalTo(primarySeqNo)); assertThat(recoveringEngine.getLocalCheckpointTracker().getCheckpoint(), equalTo(primarySeqNo));
assertThat(recoveringEngine.getLocalCheckpointTracker().getMaxSeqNo(), equalTo(primarySeqNo)); assertThat(recoveringEngine.getLocalCheckpointTracker().getMaxSeqNo(), equalTo(primarySeqNo));
assertThat(recoveringEngine.getLocalCheckpointTracker().generateSeqNo(), equalTo(primarySeqNo + 1)); assertThat(recoveringEngine.getLocalCheckpointTracker().generateSeqNo(), equalTo(primarySeqNo + 1));
} finally {
IOUtils.close(recoveringEngine);
} }
} }
@ -2389,6 +2386,7 @@ public class InternalEngineTests extends EngineTestCase {
// open and recover tlog // open and recover tlog
{ {
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
trimUnsafeCommits(config);
try (InternalEngine engine = new InternalEngine(config)) { try (InternalEngine engine = new InternalEngine(config)) {
assertTrue(engine.isRecovering()); assertTrue(engine.isRecovering());
Map<String, String> userData = engine.getLastCommittedSegmentInfos().getUserData(); Map<String, String> userData = engine.getLastCommittedSegmentInfos().getUserData();
@ -2413,6 +2411,7 @@ public class InternalEngineTests extends EngineTestCase {
final String translogUUID = final String translogUUID =
Translog.createEmptyTranslog(config.getTranslogConfig().getTranslogPath(), SequenceNumbers.NO_OPS_PERFORMED, shardId); Translog.createEmptyTranslog(config.getTranslogConfig().getTranslogPath(), SequenceNumbers.NO_OPS_PERFORMED, shardId);
store.associateIndexWithNewTranslog(translogUUID); store.associateIndexWithNewTranslog(translogUUID);
trimUnsafeCommits(config);
try (InternalEngine engine = new InternalEngine(config)) { try (InternalEngine engine = new InternalEngine(config)) {
Map<String, String> userData = engine.getLastCommittedSegmentInfos().getUserData(); Map<String, String> userData = engine.getLastCommittedSegmentInfos().getUserData();
assertEquals("1", userData.get(Translog.TRANSLOG_GENERATION_KEY)); assertEquals("1", userData.get(Translog.TRANSLOG_GENERATION_KEY));
@ -2426,6 +2425,7 @@ public class InternalEngineTests extends EngineTestCase {
// open and recover tlog with empty tlog // open and recover tlog with empty tlog
{ {
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
trimUnsafeCommits(config);
try (InternalEngine engine = new InternalEngine(config)) { try (InternalEngine engine = new InternalEngine(config)) {
Map<String, String> userData = engine.getLastCommittedSegmentInfos().getUserData(); Map<String, String> userData = engine.getLastCommittedSegmentInfos().getUserData();
assertEquals("1", userData.get(Translog.TRANSLOG_GENERATION_KEY)); assertEquals("1", userData.get(Translog.TRANSLOG_GENERATION_KEY));
@ -2487,6 +2487,7 @@ public class InternalEngineTests extends EngineTestCase {
boolean started = false; boolean started = false;
InternalEngine engine = null; InternalEngine engine = null;
try { try {
trimUnsafeCommits(config(defaultSettings, store, translogPath, NoMergePolicy.INSTANCE, null));
engine = createEngine(store, translogPath); engine = createEngine(store, translogPath);
started = true; started = true;
} catch (EngineException | IOException e) { } catch (EngineException | IOException e) {
@ -2567,6 +2568,7 @@ public class InternalEngineTests extends EngineTestCase {
} }
assertVisibleCount(engine, numDocs); assertVisibleCount(engine, numDocs);
engine.close(); engine.close();
trimUnsafeCommits(engine.config());
engine = new InternalEngine(engine.config()); engine = new InternalEngine(engine.config());
engine.skipTranslogRecovery(); engine.skipTranslogRecovery();
try (Engine.Searcher searcher = engine.acquireSearcher("test")) { try (Engine.Searcher searcher = engine.acquireSearcher("test")) {
@ -2608,6 +2610,7 @@ public class InternalEngineTests extends EngineTestCase {
parser.mappingUpdate = dynamicUpdate(); parser.mappingUpdate = dynamicUpdate();
engine.close(); engine.close();
trimUnsafeCommits(copy(engine.config(), inSyncGlobalCheckpointSupplier));
engine = new InternalEngine(copy(engine.config(), inSyncGlobalCheckpointSupplier)); // we need to reuse the engine config unless the parser.mappingModified won't work engine = new InternalEngine(copy(engine.config(), inSyncGlobalCheckpointSupplier)); // we need to reuse the engine config unless the parser.mappingModified won't work
engine.recoverFromTranslog(); engine.recoverFromTranslog();
@ -3685,6 +3688,7 @@ public class InternalEngineTests extends EngineTestCase {
final BiFunction<Long, Long, LocalCheckpointTracker> supplier = (ms, lcp) -> new LocalCheckpointTracker( final BiFunction<Long, Long, LocalCheckpointTracker> supplier = (ms, lcp) -> new LocalCheckpointTracker(
maxSeqNo, maxSeqNo,
localCheckpoint); localCheckpoint);
trimUnsafeCommits(engine.config());
noOpEngine = new InternalEngine(engine.config(), supplier) { noOpEngine = new InternalEngine(engine.config(), supplier) {
@Override @Override
protected long doGenerateSeqNoForOperation(Operation operation) { protected long doGenerateSeqNoForOperation(Operation operation) {
@ -3832,6 +3836,7 @@ public class InternalEngineTests extends EngineTestCase {
completedSeqNos.add(seqNo); completedSeqNos.add(seqNo);
} }
}; };
trimUnsafeCommits(engine.config());
actualEngine = new InternalEngine(engine.config(), supplier); actualEngine = new InternalEngine(engine.config(), supplier);
final int operations = randomIntBetween(0, 1024); final int operations = randomIntBetween(0, 1024);
final Set<Long> expectedCompletedSeqNos = new HashSet<>(); final Set<Long> expectedCompletedSeqNos = new HashSet<>();
@ -3902,6 +3907,7 @@ public class InternalEngineTests extends EngineTestCase {
assertEquals(docs - 1, engine.getLocalCheckpointTracker().getCheckpoint()); assertEquals(docs - 1, engine.getLocalCheckpointTracker().getCheckpoint());
assertEquals(maxSeqIDOnReplica, replicaEngine.getLocalCheckpointTracker().getMaxSeqNo()); assertEquals(maxSeqIDOnReplica, replicaEngine.getLocalCheckpointTracker().getMaxSeqNo());
assertEquals(checkpointOnReplica, replicaEngine.getLocalCheckpointTracker().getCheckpoint()); assertEquals(checkpointOnReplica, replicaEngine.getLocalCheckpointTracker().getCheckpoint());
trimUnsafeCommits(copy(replicaEngine.config(), globalCheckpoint::get));
recoveringEngine = new InternalEngine(copy(replicaEngine.config(), globalCheckpoint::get)); recoveringEngine = new InternalEngine(copy(replicaEngine.config(), globalCheckpoint::get));
assertEquals(numDocsOnReplica, recoveringEngine.getTranslog().stats().getUncommittedOperations()); assertEquals(numDocsOnReplica, recoveringEngine.getTranslog().stats().getUncommittedOperations());
recoveringEngine.recoverFromTranslog(); recoveringEngine.recoverFromTranslog();