|
132 | 132 | import org.elasticsearch.index.translog.TranslogConfig; |
133 | 133 | import org.elasticsearch.indices.breaker.NoneCircuitBreakerService; |
134 | 134 | import org.elasticsearch.test.IndexSettingsModule; |
| 135 | +import org.elasticsearch.test.VersionUtils; |
135 | 136 | import org.hamcrest.MatcherAssert; |
136 | 137 | import org.hamcrest.Matchers; |
137 | 138 |
|
@@ -5632,6 +5633,61 @@ public void testRebuildLocalCheckpointTracker() throws Exception { |
5632 | 5633 | } |
5633 | 5634 | } |
5634 | 5635 |
|
| 5636 | + /** |
| 5637 | + * Simulate a bug in https://github.com/elastic/elasticsearch/pull/38879 where the max_seq_no |
| 5638 | + * of the index commit can be smaller than seq_no of some documents in the commit. |
| 5639 | + */ |
| 5640 | + public void testAlwaysRebuildLocalCheckpointForOldIndex() throws Exception { |
| 5641 | + Settings.Builder settings = Settings.builder() |
| 5642 | + .put(defaultSettings.getSettings()) |
| 5643 | + .put(IndexMetaData.SETTING_VERSION_CREATED, VersionUtils.randomVersionBetween(random(), Version.V_6_5_0, Version.V_6_6_1)) |
| 5644 | + .put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true); |
| 5645 | + final IndexMetaData indexMetaData = IndexMetaData.builder(defaultSettings.getIndexMetaData()).settings(settings).build(); |
| 5646 | + final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(indexMetaData); |
| 5647 | + Path translogPath = createTempDir(); |
| 5648 | + List<Engine.Operation> operations = generateHistoryOnReplica(between(1, 500), randomBoolean(), randomBoolean(), randomBoolean()); |
| 5649 | + final AtomicLong globalCheckpoint = new AtomicLong(SequenceNumbers.NO_OPS_PERFORMED); |
| 5650 | + try (Store store = createStore()) { |
| 5651 | + EngineConfig config = config(indexSettings, store, translogPath, NoMergePolicy.INSTANCE, null, null, globalCheckpoint::get); |
| 5652 | + final List<DocIdSeqNoAndTerm> docs; |
| 5653 | + try (InternalEngine engine = createEngine(config)) { |
| 5654 | + for (Engine.Operation op : operations) { |
| 5655 | + applyOperation(engine, op); |
| 5656 | + if (randomInt(100) < 10) { |
| 5657 | + engine.flush(); |
| 5658 | + globalCheckpoint.set(randomLongBetween(globalCheckpoint.get(), engine.getLocalCheckpoint())); |
| 5659 | + } |
| 5660 | + } |
| 5661 | + globalCheckpoint.set(randomLongBetween(globalCheckpoint.get(), engine.getLocalCheckpoint())); |
| 5662 | + engine.syncTranslog(); |
| 5663 | + docs = getDocIds(engine, true); |
| 5664 | + } |
| 5665 | + trimUnsafeCommits(config); |
| 5666 | + // Simulate a bug in https://github.com/elastic/elasticsearch/pull/38879 where max_seq_no is smaller than seq_no of some docs. |
| 5667 | + if (randomBoolean()) { |
| 5668 | + IndexWriterConfig iwc = new IndexWriterConfig(null) |
| 5669 | + .setSoftDeletesField(Lucene.SOFT_DELETES_FIELD) |
| 5670 | + .setCommitOnClose(false) |
| 5671 | + .setMergePolicy(NoMergePolicy.INSTANCE) |
| 5672 | + .setOpenMode(IndexWriterConfig.OpenMode.APPEND); |
| 5673 | + try (IndexWriter writer = new IndexWriter(config.getStore().directory(), iwc)) { |
| 5674 | + Map<String, String> userData = new HashMap<>(); |
| 5675 | + writer.getLiveCommitData().forEach(e -> userData.put(e.getKey(), e.getValue())); |
| 5676 | + SequenceNumbers.CommitInfo commitInfo = SequenceNumbers.loadSeqNoInfoFromLuceneCommit(userData.entrySet()); |
| 5677 | + long maxSeqNo = randomLongBetween(commitInfo.localCheckpoint, commitInfo.maxSeqNo); |
| 5678 | + userData.put(SequenceNumbers.MAX_SEQ_NO, Long.toString(maxSeqNo)); |
| 5679 | + writer.setLiveCommitData(userData.entrySet()); |
| 5680 | + writer.commit(); |
| 5681 | + } |
| 5682 | + } |
| 5683 | + try (InternalEngine engine = new InternalEngine(config)) { |
| 5684 | + engine.reinitializeMaxSeqNoOfUpdatesOrDeletes(); |
| 5685 | + engine.recoverFromTranslog(translogHandler, Long.MAX_VALUE); |
| 5686 | + assertThat(getDocIds(engine, true), equalTo(docs)); |
| 5687 | + } |
| 5688 | + } |
| 5689 | + } |
| 5690 | + |
5635 | 5691 | public void testOpenSoftDeletesIndexWithSoftDeletesDisabled() throws Exception { |
5636 | 5692 | try (Store store = createStore()) { |
5637 | 5693 | Path translogPath = createTempDir(); |
|
0 commit comments