Skip to content

Commit

Permalink
Use type explicitly
Browse files Browse the repository at this point in the history
We have a single type in 7.0
  • Loading branch information
dnhatn committed Apr 30, 2018
1 parent 7bfd4d1 commit 11c2d53
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3048,7 +3048,7 @@ public void testDoubleDeliveryReplica() throws IOException {
TopDocs topDocs = searcher.searcher().search(new MatchAllDocsQuery(), 10);
assertEquals(1, topDocs.totalHits);
}
List<Translog.Operation> ops = readAllOperationsInLucene(engine, createMapperService("test"));
List<Translog.Operation> ops = readAllOperationsInLucene(engine, "test");
assertThat(ops.stream().map(o -> o.seqNo()).collect(Collectors.toList()), hasItem(20L));
}

Expand Down Expand Up @@ -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<Translog.Operation> operationsFromLucene = readAllOperationsInLucene(noOpEngine, mapperService);
List<Translog.Operation> 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);
}
Expand Down Expand Up @@ -4615,10 +4614,9 @@ private void assertOperationHistoryInLucene(List<Engine.Operation> operations) t
engine.forceMerge(true);
}
}
MapperService mapperService = createMapperService("test");
List<Translog.Operation> actualOps = readAllOperationsInLucene(engine, mapperService);
List<Translog.Operation> actualOps = readAllOperationsInLucene(engine, "test");
assertThat(actualOps.stream().map(o -> o.seqNo()).collect(Collectors.toList()), containsInAnyOrder(expectedSeqNos.toArray()));
assertConsistentHistoryBetweenTranslogAndLuceneIndex(engine, mapperService);
assertConsistentHistoryBetweenTranslogAndLuceneIndex(engine, createMapperService("test"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Translog.Operation> readAllOperationsInLucene(Engine engine, MapperService mapper) throws IOException {
public static List<Translog.Operation> readAllOperationsInLucene(Engine engine, String docType) throws IOException {
engine.refresh("test");
final List<Translog.Operation> operations = new ArrayList<>();
try (Engine.Searcher searcher = engine.acquireSearcher("test", Engine.SearcherScope.INTERNAL)) {
Expand All @@ -725,7 +725,7 @@ public static List<Translog.Operation> 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();
Expand All @@ -735,15 +735,14 @@ public static List<Translog.Operation> 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<LeafReaderContext> leaves = searcher.getIndexReader().leaves();
final int leafIndex = ReaderUtil.subIndex(docID, leaves);
final int segmentDocID = docID - leaves.get(leafIndex).docBase;
final long seqNo = readNumericDV(leaves.get(leafIndex), SeqNoFieldMapper.NAME, segmentDocID);
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) {
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -798,7 +796,7 @@ public static void assertConsistentHistoryBetweenTranslogAndLuceneIndex(Engine e
translogOps.put(op.seqNo(), op);
}
}
final List<Translog.Operation> luceneOps = readAllOperationsInLucene(engine, mapper);
final List<Translog.Operation> luceneOps = readAllOperationsInLucene(engine, mapper.documentMapper().type());
for (Translog.Operation luceneOp : luceneOps) {
Translog.Operation translogOp = translogOps.get(luceneOp.seqNo());
if (translogOp == null) {
Expand Down

0 comments on commit 11c2d53

Please sign in to comment.