Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Remove] types from translog #2439

Merged
merged 3 commits into from
Mar 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -593,10 +593,9 @@ private static Response prepareRamIndex(
try (Directory directory = new ByteBuffersDirectory()) {
try (IndexWriter indexWriter = new IndexWriter(directory, new IndexWriterConfig(defaultAnalyzer))) {
String index = indexService.index().getName();
String type = indexService.mapperService().documentMapper().type();
BytesReference document = request.contextSetup.document;
XContentType xContentType = request.contextSetup.xContentType;
SourceToParse sourceToParse = new SourceToParse(index, type, "_id", document, xContentType);
SourceToParse sourceToParse = new SourceToParse(index, "_id", document, xContentType);
ParsedDocument parsedDocument = indexService.mapperService().documentMapper().parse(sourceToParse);
indexWriter.addDocuments(parsedDocument.docs());
try (IndexReader indexReader = DirectoryReader.open(indexWriter)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void testDocumentParsingFailsOnMetaField() throws Exception {
BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field(rfMetaField, 0).endObject());
MapperParsingException e = expectThrows(
MapperParsingException.class,
() -> mapper.parse(new SourceToParse("test", "_doc", "1", bytes, XContentType.JSON))
() -> mapper.parse(new SourceToParse("test", "1", bytes, XContentType.JSON))
);
assertTrue(
e.getCause().getMessage().contains("Field [" + rfMetaField + "] is a metadata field and cannot be added inside a document.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ public void testNotIndexed() throws Exception {
ParsedDocument doc = mapper.parse(
new SourceToParse(
"test",
"_doc",
"1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", 123).endObject()),
XContentType.JSON
Expand All @@ -156,7 +155,6 @@ public void testNoDocValues() throws Exception {
ParsedDocument doc = mapper.parse(
new SourceToParse(
"test",
"_doc",
"1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", 123).endObject()),
XContentType.JSON
Expand All @@ -178,7 +176,6 @@ public void testStore() throws Exception {
ParsedDocument doc = mapper.parse(
new SourceToParse(
"test",
"_doc",
"1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", 123).endObject()),
XContentType.JSON
Expand All @@ -202,7 +199,6 @@ public void testCoerce() throws Exception {
ParsedDocument doc = mapper.parse(
new SourceToParse(
"test",
"_doc",
"1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", "123").endObject()),
XContentType.JSON
Expand All @@ -222,7 +218,6 @@ public void testCoerce() throws Exception {
ThrowingRunnable runnable = () -> mapper2.parse(
new SourceToParse(
"test",
"_doc",
"1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", "123").endObject()),
XContentType.JSON
Expand All @@ -246,7 +241,6 @@ private void doTestIgnoreMalformed(String value, String exceptionMessageContains
ThrowingRunnable runnable = () -> mapper.parse(
new SourceToParse(
"test",
"_doc",
"1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", value).endObject()),
XContentType.JSON
Expand All @@ -261,7 +255,6 @@ private void doTestIgnoreMalformed(String value, String exceptionMessageContains
ParsedDocument doc = mapper2.parse(
new SourceToParse(
"test",
"_doc",
"1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", value).endObject()),
XContentType.JSON
Expand All @@ -277,7 +270,6 @@ public void testNullValue() throws IOException {
ParsedDocument doc = mapper.parse(
new SourceToParse(
"test",
"_doc",
"1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject().nullField("field").endObject()),
XContentType.JSON
Expand All @@ -291,7 +283,6 @@ public void testNullValue() throws IOException {
doc = mapper.parse(
new SourceToParse(
"test",
"_doc",
"1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject().nullField("field").endObject()),
XContentType.JSON
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,14 @@ public void testSingleLevel() throws Exception {

// Doc without join
ParsedDocument doc = docMapper.parse(
new SourceToParse(
"test",
"type",
"0",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject().endObject()),
XContentType.JSON
)
new SourceToParse("test", "0", BytesReference.bytes(XContentFactory.jsonBuilder().startObject().endObject()), XContentType.JSON)
);
assertNull(doc.rootDoc().getBinaryValue("join_field"));

// Doc parent
doc = docMapper.parse(
new SourceToParse(
"test",
"type",
"1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("join_field", "parent").endObject()),
XContentType.JSON
Expand All @@ -107,7 +100,6 @@ public void testSingleLevel() throws Exception {
doc = docMapper.parse(
new SourceToParse(
"test",
"type",
"2",
BytesReference.bytes(
XContentFactory.jsonBuilder()
Expand All @@ -131,7 +123,6 @@ public void testSingleLevel() throws Exception {
() -> docMapper.parse(
new SourceToParse(
"test",
"type",
"1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("join_field", "unknown").endObject()),
XContentType.JSON
Expand Down Expand Up @@ -161,7 +152,6 @@ public void testParentIdSpecifiedAsNumber() throws Exception {
ParsedDocument doc = docMapper.parse(
new SourceToParse(
"test",
"type",
"2",
BytesReference.bytes(
XContentFactory.jsonBuilder()
Expand All @@ -181,7 +171,6 @@ public void testParentIdSpecifiedAsNumber() throws Exception {
doc = docMapper.parse(
new SourceToParse(
"test",
"type",
"2",
BytesReference.bytes(
XContentFactory.jsonBuilder()
Expand Down Expand Up @@ -222,21 +211,14 @@ public void testMultipleLevels() throws Exception {

// Doc without join
ParsedDocument doc = docMapper.parse(
new SourceToParse(
"test",
"type",
"0",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject().endObject()),
XContentType.JSON
)
new SourceToParse("test", "0", BytesReference.bytes(XContentFactory.jsonBuilder().startObject().endObject()), XContentType.JSON)
);
assertNull(doc.rootDoc().getBinaryValue("join_field"));

// Doc parent
doc = docMapper.parse(
new SourceToParse(
"test",
"type",
"1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("join_field", "parent").endObject()),
XContentType.JSON
Expand All @@ -249,7 +231,6 @@ public void testMultipleLevels() throws Exception {
doc = docMapper.parse(
new SourceToParse(
"test",
"type",
"2",
BytesReference.bytes(
XContentFactory.jsonBuilder()
Expand All @@ -274,7 +255,6 @@ public void testMultipleLevels() throws Exception {
() -> docMapper.parse(
new SourceToParse(
"test",
"type",
"2",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("join_field", "child").endObject()),
XContentType.JSON,
Expand All @@ -290,7 +270,6 @@ public void testMultipleLevels() throws Exception {
() -> docMapper.parse(
new SourceToParse(
"test",
"type",
"2",
BytesReference.bytes(
XContentFactory.jsonBuilder()
Expand All @@ -311,7 +290,6 @@ public void testMultipleLevels() throws Exception {
doc = docMapper.parse(
new SourceToParse(
"test",
"type",
"3",
BytesReference.bytes(
XContentFactory.jsonBuilder()
Expand All @@ -335,7 +313,6 @@ public void testMultipleLevels() throws Exception {
() -> docMapper.parse(
new SourceToParse(
"test",
"type",
"1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("join_field", "unknown").endObject()),
XContentType.JSON
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ protected Query doToQuery(QueryShardContext context) throws IOException {
}
docMapper = mapperService.documentMapper();
for (BytesReference document : documents) {
docs.add(docMapper.parse(new SourceToParse(context.index().getName(), type, "_temp_id", document, documentXContentType)));
docs.add(docMapper.parse(new SourceToParse(context.index().getName(), "_temp_id", document, documentXContentType)));
}

FieldNameAnalyzer fieldNameAnalyzer = (FieldNameAnalyzer) docMapper.mappers().indexAnalyzer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,6 @@ public void testPercolatorFieldMapper() throws Exception {
.parse(
new SourceToParse(
"test",
MapperService.SINGLE_MAPPING_NAME,
"1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, queryBuilder).endObject()),
XContentType.JSON
Expand All @@ -574,7 +573,6 @@ public void testPercolatorFieldMapper() throws Exception {
.parse(
new SourceToParse(
"test",
MapperService.SINGLE_MAPPING_NAME,
"1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, queryBuilder).endObject()),
XContentType.JSON
Expand All @@ -592,7 +590,6 @@ public void testPercolatorFieldMapper() throws Exception {
.parse(
new SourceToParse(
"test",
MapperService.SINGLE_MAPPING_NAME,
"1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, queryBuilder).endObject()),
XContentType.JSON
Expand Down Expand Up @@ -621,7 +618,6 @@ public void testStoringQueries() throws Exception {
.parse(
new SourceToParse(
"test",
MapperService.SINGLE_MAPPING_NAME,
"1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, query).endObject()),
XContentType.JSON
Expand All @@ -640,7 +636,6 @@ public void testQueryWithRewrite() throws Exception {
.parse(
new SourceToParse(
"test",
MapperService.SINGLE_MAPPING_NAME,
"1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, queryBuilder).endObject()),
XContentType.JSON
Expand All @@ -665,7 +660,6 @@ public void testPercolatorFieldMapperUnMappedField() throws Exception {
.parse(
new SourceToParse(
"test",
MapperService.SINGLE_MAPPING_NAME,
"1",
BytesReference.bytes(
XContentFactory.jsonBuilder().startObject().field(fieldName, termQuery("unmapped_field", "value")).endObject()
Expand All @@ -684,7 +678,6 @@ public void testPercolatorFieldMapper_noQuery() throws Exception {
.parse(
new SourceToParse(
"test",
MapperService.SINGLE_MAPPING_NAME,
"1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject().endObject()),
XContentType.JSON
Expand All @@ -697,7 +690,6 @@ public void testPercolatorFieldMapper_noQuery() throws Exception {
.parse(
new SourceToParse(
"test",
MapperService.SINGLE_MAPPING_NAME,
"1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject().nullField(fieldName).endObject()),
XContentType.JSON
Expand Down Expand Up @@ -760,7 +752,6 @@ public void testMultiplePercolatorFields() throws Exception {
.parse(
new SourceToParse(
"test",
typeName,
"1",
BytesReference.bytes(
jsonBuilder().startObject().field("query_field1", queryBuilder).field("query_field2", queryBuilder).endObject()
Expand Down Expand Up @@ -803,7 +794,6 @@ public void testNestedPercolatorField() throws Exception {
.parse(
new SourceToParse(
"test",
typeName,
"1",
BytesReference.bytes(
jsonBuilder().startObject().startObject("object_field").field("query_field", queryBuilder).endObject().endObject()
Expand All @@ -823,7 +813,6 @@ public void testNestedPercolatorField() throws Exception {
.parse(
new SourceToParse(
"test",
typeName,
"1",
BytesReference.bytes(
jsonBuilder().startObject()
Expand All @@ -846,7 +835,6 @@ public void testNestedPercolatorField() throws Exception {
.parse(
new SourceToParse(
"test",
typeName,
"1",
BytesReference.bytes(
jsonBuilder().startObject()
Expand Down Expand Up @@ -954,7 +942,6 @@ public void testImplicitlySetDefaultScriptLang() throws Exception {
.parse(
new SourceToParse(
"test",
MapperService.SINGLE_MAPPING_NAME,
"1",
BytesReference.bytes(
XContentFactory.jsonBuilder()
Expand Down Expand Up @@ -1002,7 +989,6 @@ public void testImplicitlySetDefaultScriptLang() throws Exception {
.parse(
new SourceToParse(
"test",
MapperService.SINGLE_MAPPING_NAME,
"1",
BytesReference.bytes(
XContentFactory.jsonBuilder()
Expand Down Expand Up @@ -1097,7 +1083,6 @@ public void testDuplicatedClauses() throws Exception {
.parse(
new SourceToParse(
"test",
MapperService.SINGLE_MAPPING_NAME,
"1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, qb).endObject()),
XContentType.JSON
Expand All @@ -1123,7 +1108,6 @@ public void testDuplicatedClauses() throws Exception {
.parse(
new SourceToParse(
"test",
MapperService.SINGLE_MAPPING_NAME,
"1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, qb).endObject()),
XContentType.JSON
Expand Down Expand Up @@ -1152,7 +1136,6 @@ public void testDuplicatedClauses() throws Exception {
.parse(
new SourceToParse(
"test",
MapperService.SINGLE_MAPPING_NAME,
"1",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field(fieldName, qb).endObject()),
XContentType.JSON
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,16 +342,16 @@ public static class BlockingOperationListener implements IndexingOperationListen

@Override
public Engine.Index preIndex(ShardId shardId, Engine.Index index) {
return preCheck(index, index.type());
return preCheck(index);
}

@Override
public Engine.Delete preDelete(ShardId shardId, Engine.Delete delete) {
return preCheck(delete, delete.type());
return preCheck(delete);
}

private <T extends Engine.Operation> T preCheck(T operation, String type) {
if (("_doc".equals(type) == false) || (operation.origin() != Engine.Operation.Origin.PRIMARY)) {
private <T extends Engine.Operation> T preCheck(T operation) {
if ((operation.origin() != Engine.Operation.Origin.PRIMARY)) {
return operation;
}

Expand Down
Loading