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 09d8d5f76116a..b622b252f319b 100644 --- a/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java +++ b/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java @@ -3048,7 +3048,7 @@ public void testDoubleDeliveryReplica() throws IOException { TopDocs topDocs = searcher.searcher().search(new MatchAllDocsQuery(), 10); assertEquals(1, topDocs.totalHits); } - List ops = readAllOperationsInLucene(engine, createMapperService("test")); + List ops = readAllOperationsInLucene(engine, "test"); assertThat(ops.stream().map(o -> o.seqNo()).collect(Collectors.toList()), hasItem(20L)); } @@ -3641,13 +3641,12 @@ protected long doGenerateSeqNoForOperation(Operation operation) { assertThat(noOp.seqNo(), equalTo((long) (maxSeqNo + 2))); assertThat(noOp.primaryTerm(), equalTo(primaryTerm.get())); assertThat(noOp.reason(), equalTo(reason)); - MapperService mapperService = createMapperService("test"); - List operationsFromLucene = readAllOperationsInLucene(noOpEngine, mapperService); + List operationsFromLucene = readAllOperationsInLucene(noOpEngine, "test"); assertThat(operationsFromLucene, hasSize(maxSeqNo + 2 - localCheckpoint)); // fills n gap and 2 manual noop. for (int i = 0; i < operationsFromLucene.size(); i++) { assertThat(operationsFromLucene.get(i), equalTo(new Translog.NoOp(localCheckpoint + 1 + i, primaryTerm.get(), ""))); } - assertConsistentHistoryBetweenTranslogAndLuceneIndex(noOpEngine, mapperService); + assertConsistentHistoryBetweenTranslogAndLuceneIndex(noOpEngine, createMapperService("test")); } finally { IOUtils.close(noOpEngine); } @@ -4615,10 +4614,9 @@ private void assertOperationHistoryInLucene(List operations) t engine.forceMerge(true); } } - MapperService mapperService = createMapperService("test"); - List actualOps = readAllOperationsInLucene(engine, mapperService); + List actualOps = readAllOperationsInLucene(engine, "test"); assertThat(actualOps.stream().map(o -> o.seqNo()).collect(Collectors.toList()), containsInAnyOrder(expectedSeqNos.toArray())); - assertConsistentHistoryBetweenTranslogAndLuceneIndex(engine, mapperService); + assertConsistentHistoryBetweenTranslogAndLuceneIndex(engine, createMapperService("test")); } } diff --git a/test/framework/src/main/java/org/elasticsearch/index/engine/EngineTestCase.java b/test/framework/src/main/java/org/elasticsearch/index/engine/EngineTestCase.java index 38f518afa898e..a9d44e8a83018 100644 --- a/test/framework/src/main/java/org/elasticsearch/index/engine/EngineTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/index/engine/EngineTestCase.java @@ -713,7 +713,7 @@ public static void assertOpsOnReplica( * Reads all engine operations that have been processed by the engine from Lucene index. * The returned operations are sorted and de-duplicated, thus each sequence number will be have at most one operation. */ - public static List readAllOperationsInLucene(Engine engine, MapperService mapper) throws IOException { + public static List readAllOperationsInLucene(Engine engine, String docType) throws IOException { engine.refresh("test"); final List operations = new ArrayList<>(); try (Engine.Searcher searcher = engine.acquireSearcher("test", Engine.SearcherScope.INTERNAL)) { @@ -725,7 +725,7 @@ public static List readAllOperationsInLucene(Engine engine, final TopDocs allDocs = indexSearcher.search(new MatchAllDocsQuery(), Integer.MAX_VALUE, sortedBySeqNoThenByTerm); long lastSeenSeqNo = SequenceNumbers.NO_OPS_PERFORMED; for (ScoreDoc scoreDoc : allDocs.scoreDocs) { - final Translog.Operation op = readOperationInLucene(indexSearcher, mapper, scoreDoc.doc); + final Translog.Operation op = readOperationInLucene(indexSearcher, docType, scoreDoc.doc); if (op.seqNo() != lastSeenSeqNo) { operations.add(op); lastSeenSeqNo = op.seqNo(); @@ -735,7 +735,7 @@ public static List readAllOperationsInLucene(Engine engine, return operations; } - private static Translog.Operation readOperationInLucene(IndexSearcher searcher, MapperService mapper, int docID) throws IOException { + private static Translog.Operation readOperationInLucene(IndexSearcher searcher, String docType, int docID) throws IOException { final List leaves = searcher.getIndexReader().leaves(); final int leafIndex = ReaderUtil.subIndex(docID, leaves); final int segmentDocID = docID - leaves.get(leafIndex).docBase; @@ -743,7 +743,6 @@ private static Translog.Operation readOperationInLucene(IndexSearcher searcher, final long primaryTerm = readNumericDV(leaves.get(leafIndex), SeqNoFieldMapper.PRIMARY_TERM_NAME, segmentDocID); final FieldsVisitor fields = new FieldsVisitor(true); searcher.doc(docID, fields); - fields.postProcess(mapper); final Translog.Operation op; final boolean isTombstone = isTombstoneOperation(leaves.get(leafIndex), segmentDocID); if (isTombstone && fields.uid() == null) { @@ -752,16 +751,15 @@ assert readNumericDV(leaves.get(leafIndex), Lucene.SOFT_DELETE_FIELD, segmentDoc : "Noop operation but soft_deletes field is not set"; } else { final String id = fields.uid().id(); - final String type = fields.uid().type(); final Term uid = new Term(IdFieldMapper.NAME, Uid.encodeId(id)); final long version = readNumericDV(leaves.get(leafIndex), VersionFieldMapper.NAME, segmentDocID); if (isTombstone) { - op = new Translog.Delete(type, id, uid, seqNo, primaryTerm, version, VersionType.INTERNAL); + op = new Translog.Delete(docType, id, uid, seqNo, primaryTerm, version, VersionType.INTERNAL); assert readNumericDV(leaves.get(leafIndex), Lucene.SOFT_DELETE_FIELD, segmentDocID) == 1 : "Delete operation but soft_deletes field is not set"; } else { final BytesReference source = fields.source(); - op = new Translog.Index(type, id, seqNo, primaryTerm, version, VersionType.INTERNAL, source.toBytesRef().bytes, + op = new Translog.Index(docType, id, seqNo, primaryTerm, version, VersionType.INTERNAL, source.toBytesRef().bytes, fields.routing(), -1); } } @@ -798,7 +796,7 @@ public static void assertConsistentHistoryBetweenTranslogAndLuceneIndex(Engine e translogOps.put(op.seqNo(), op); } } - final List luceneOps = readAllOperationsInLucene(engine, mapper); + final List luceneOps = readAllOperationsInLucene(engine, mapper.documentMapper().type()); for (Translog.Operation luceneOp : luceneOps) { Translog.Operation translogOp = translogOps.get(luceneOp.seqNo()); if (translogOp == null) {