Skip to content

Commit

Permalink
Fix hard-deletes engine simulation (#50517)
Browse files Browse the repository at this point in the history
The test "testRecoverFromHardDeletesIndex" failed because the 
"min_retained_seqno" commit tag exists after we index using a
hard-deletes engine. A hard-deletes engine must not create this 
commit tag; hence we need to remove it in the test.

Relates #50415
  • Loading branch information
dnhatn authored Dec 29, 2019
1 parent 858892f commit 5e9b629
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5464,7 +5464,22 @@ public long softUpdateDocuments(Term term, Iterable<? extends Iterable<? extends
}
docs = getDocIds(hardDeletesEngine, true);
}
// We need to remove min_retained_seq_no commit tag as the actual hard-deletes engine does not have it.
store.trimUnsafeCommits(translogPath);
Map<String, String> userData = new HashMap<>(store.readLastCommittedSegmentsInfo().userData);
userData.remove(Engine.MIN_RETAINED_SEQNO);
IndexWriterConfig indexWriterConfig = new IndexWriterConfig(null)
.setOpenMode(IndexWriterConfig.OpenMode.APPEND)
.setIndexCreatedVersionMajor(Version.CURRENT.luceneVersion.major)
.setSoftDeletesField(Lucene.SOFT_DELETES_FIELD)
.setCommitOnClose(false)
.setMergePolicy(NoMergePolicy.INSTANCE);
try (IndexWriter writer = new IndexWriter(store.directory(), indexWriterConfig)) {
writer.setLiveCommitData(userData.entrySet());
writer.commit();
}
try (InternalEngine softDeletesEngine = new InternalEngine(config)) { // do not recover from translog
assertThat(softDeletesEngine.getLastCommittedSegmentInfos().userData, equalTo(userData));
assertThat(softDeletesEngine.getVersionMap().keySet(), empty());
softDeletesEngine.recoverFromTranslog(translogHandler, Long.MAX_VALUE);
if (randomBoolean()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1088,15 +1088,16 @@ public static void assertConsistentHistoryBetweenTranslogAndLuceneIndex(Engine e
}
final long globalCheckpoint = EngineTestCase.getTranslog(engine).getLastSyncedGlobalCheckpoint();
final long retainedOps = engine.config().getIndexSettings().getSoftDeleteRetentionOperations();
final long seqNoForRecovery;
final long minSeqNoToRetain;
if (engine.config().getIndexSettings().isSoftDeleteEnabled()) {
try (Engine.IndexCommitRef safeCommit = engine.acquireSafeIndexCommit()) {
seqNoForRecovery = Long.parseLong(safeCommit.getIndexCommit().getUserData().get(SequenceNumbers.LOCAL_CHECKPOINT_KEY)) + 1;
final long seqNoForRecovery = Long.parseLong(
safeCommit.getIndexCommit().getUserData().get(SequenceNumbers.LOCAL_CHECKPOINT_KEY)) + 1;
minSeqNoToRetain = Math.min(seqNoForRecovery, globalCheckpoint + 1 - retainedOps);
}
} else {
seqNoForRecovery = engine.getMinRetainedSeqNo();
minSeqNoToRetain = engine.getMinRetainedSeqNo();
}
final long minSeqNoToRetain = Math.min(seqNoForRecovery, globalCheckpoint + 1 - retainedOps);
for (Translog.Operation translogOp : translogOps) {
final Translog.Operation luceneOp = luceneOps.get(translogOp.seqNo());
if (luceneOp == null) {
Expand Down

0 comments on commit 5e9b629

Please sign in to comment.