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 type filter from GetMappings API #47364

Merged
merged 26 commits into from
Oct 21, 2019

Conversation

romseygeek
Copy link
Contributor

This commit removes the types filter from the GetMappings API, which is no longer
useful seeing as we can only have a single mapping type per index. It also changes
the structure of GetMappingsResponse and GetIndexResponse to remove the extra
nesting of mappings below the no-longer-relevant type name, and removes the types
methods from the equivalent request classes.

Relates to #41059

@romseygeek romseygeek added :Search Foundations/Mapping Index mappings, including merging and defining field types >breaking-java v8.0.0 labels Oct 1, 2019
@romseygeek romseygeek self-assigned this Oct 1, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search

@@ -333,7 +333,7 @@ public void testAddIndexClosedBlocksReusesBlocks() {
}

public void testValidateShardLimit() {
int nodesInCluster = randomIntBetween(2,100);
int nodesInCluster = randomIntBetween(2,90);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems unrelated to types removal?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by a separate merge in from master

@romseygeek romseygeek requested a review from colings86 October 14, 2019 08:03
Copy link
Contributor

@jtibshirani jtibshirani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me overall, I left a few minor comments.

I was a bit confused at first about what this PR did -- we're removing deprecated HLRC methods and also refactoring transport client classes at the same time. For future APIs perhaps we could split these into two separate tasks, or just clarify in the PR description? It could also be helpful to mention 'transport API' in the PR title, otherwise it's easy to assume it refers to the REST API.

assert MapperService.SINGLE_MAPPING_NAME.equals(type) : "Expected type [_doc] but got " + type;
mappingsMapBuilder.put(key, new MappingMetaData(in));
}
else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small comment, I think we always put else on the same line as the previous closing brace: } else {. This applies to a few places in the PR.

@@ -42,15 +42,19 @@ public ClusterInfoRequest() {
public ClusterInfoRequest(StreamInput in) throws IOException {
super(in);
indices = in.readStringArray();
types = in.readStringArray();
if (in.getVersion().before(Version.V_8_0_0)) {
in.readStringArray();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small comment, we could assert the types are empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these can still be non-empty in a mixed cluster with a user-request containing types routed through a 7x node

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we support the case where a user is making typed requests in a mixed 7.x and 8.x cluster?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but then I think we need to throw an exception rather than assert? Or is the idea that assertions are only there in our test infrastructure, and in production it would be ignored. In which case maybe we should throw an exception here rather than use an assertion?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, it seems like we should be throwing exceptions here (and in other requests) instead of asserts. This would allow us to 'fail fast' when a user starts a rolling upgrade to 8.x but hasn't fully switched to typeless calls.

I think we use asserts in other requests like GraphExploreRequest (I missed that in previous reviews!), perhaps we could update to using exceptions everywhere in a future PR?

indexMapBuilder.put(index, new MappingMetaData(in));
}
else {
indexMapBuilder.put(index, null);
Copy link
Contributor

@jtibshirani jtibshirani Oct 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems best to avoid having null values in maps. It makes the result of Map#get less clear --null result could indicate that the key isn't present, or it could be present but have a null value. Also, many map construction methods (like Map.of) will reject null values. Perhaps we could use Optional here, or introduce a notion of empty MappingMetaData?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, null is nasty here. I've pushed a change to create a new empty mappings placeholder.

}

private Predicate<String> randomFieldsExcludeFilter() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could make sense to keep this as a precaution, to ensure the mappings are always well-formed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HLRC's AbstractResponseTestCase doesn't seem to support this, unfortunately

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@romseygeek
Copy link
Contributor Author

I was a bit confused at first about what this PR did -- we're removing deprecated HLRC methods and also refactoring transport client classes at the same time. For future APIs perhaps we could split these into two separate tasks, or just clarify in the PR description? It could also be helpful to mention 'transport API' in the PR title, otherwise it's easy to assume it refers to the REST API.

Yes, sorry about that. I think I'll open a separate PR to just remove all the type-referring deprecated methods in HLRC to prevent confusion in the future

@romseygeek
Copy link
Contributor Author

@elasticmachine run elasticsearch-ci/2
@elasticmachine run elasticsearch-ci/packaging-sample-matrix

Copy link
Contributor

@jtibshirani jtibshirani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'll open a separate PR to just remove all the type-referring deprecated methods in HLRC to prevent confusion in the future

Seems like a nice idea!

if (indexMapping.keys().size() == 0) {
ImmutableOpenMap<String, MappingMetaData> mappings = getIndexResponse.mappings();
MappingMetaData indexMapping = mappings.get(sourceIndexName);
if (indexMapping == null || indexMapping == MappingMetaData.EMPTY_MAPPINGS) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering why we need to check for null here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the index itself might not exist for some reason, in which case Map.get(key) will return null

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although looking more closely, the GetIndexRequest used above here will error out if the index doesn't exist, so we can remove the null check. Good catch!

String type = in.readString();
assert MapperService.SINGLE_MAPPING_NAME.equals(type) : "Expected [_doc] but got [" + type + "]";
mappingsMapBuilder.put(index, new MappingMetaData(in));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If numMappings == 0, I think we would want to put (index, MappingMetaData.EMPTY_MAPPINGS). That way we maintain the invariant that the map contains a key for every requested index.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

mappingEntry.value.writeTo(out);
if (out.getVersion().before(Version.V_8_0_0)) {
out.writeVInt(indexEntry.value == MappingMetaData.EMPTY_MAPPINGS ? 0 : 1);
if (indexEntry.value != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be indexEntry.value != MappingMetaData.EMPTY_MAPPINGS?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed this one... will fix, thanks!

@romseygeek
Copy link
Contributor Author

@elasticmachine update branch

@romseygeek
Copy link
Contributor Author

@elasticmachine update branch

@romseygeek romseygeek merged commit afeee4b into elastic:master Oct 21, 2019
@romseygeek romseygeek deleted the types-removal/getmappings branch October 21, 2019 09:10
pgomulka added a commit that referenced this pull request Jul 14, 2020
based on pgomulka:compat/delete_update #58246

CompatRestIT. test {yaml=indices.get_field_mapping/30_missing_type/Raise 404 when type doesn't exist}
because of that change (custom type to _doc) a test that was expecting 404 for a type that did not exist, passes now as the logic is trying to fetch for _doc (any type that exist on that index will be good).

CompatRestIT. test {yaml=indices.get_mapping/11_basic_with_types/Get /{index}/_mapping with empty mappings}
this is because I can't tell if the mapping contained a type or not when fetching a mapping.

CompatRestIT. test {yaml=indices.get_mapping/20_missing_type/Existent and non-existent type returns 404 and the existing type}
CompatRestIT. test {yaml=indices.get_mapping/20_missing_type/Existent and non-existent types returns 404 and the existing type}
CompatRestIT. test {yaml=indices.get_mapping/20_missing_type/No type matching pattern returns 404}
CompatRestIT. test {yaml=indices.get_mapping/20_missing_type/Non-existent type returns 404}
failing - (not returning 404) - because type is always found (defaulted to _doc)

CompatRestIT. test {yaml=indices.get_mapping/20_missing_type/Type missing when no types exist}
CompatRestIT. test {yaml=indices.get_mapping/61_empty_with_types/Check empty mapping when getting all mappings via /_mapping}
CompatRestIT. test {yaml=indices.get_template/11_basic_with_types/Get template with no mappings}
CompatRestIT. test {yaml=indices.get_template/11_basic_with_types/Get template}
CompatRestIT. test {yaml=indices.put_mapping/20_mix_typeless_typeful/PUT mapping with _doc on an index that has types}
CompatRestIT. test {yaml=indices.put_mapping/20_mix_typeless_typeful/PUT mapping with typeless API on an index that has types}
#47364
#41676
martijnvg added a commit to martijnvg/elasticsearch that referenced this pull request Jan 4, 2021
This was done in master via elastic#47364, but that change was never backported to 7.x.
This change only includes the changes to GetIndexResponseTests from that pr.

This should also fix the failure in elastic#66653,
since no fields are shuffled in the server side response.

Closes elastic#66653
martijnvg added a commit that referenced this pull request Jan 5, 2021
This was done in master via #47364, but that change was never backported to 7.x.
This change only includes the changes to GetIndexResponseTests from that pr.

This should also fix the failure in #66653,
since no fields are shuffled in the server side response.

Closes #66653
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>breaking-java :Search Foundations/Mapping Index mappings, including merging and defining field types v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants