-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Remove type filter from GetMappings API #47364
Conversation
Pinging @elastic/es-search |
@@ -333,7 +333,7 @@ public void testAddIndexClosedBlocksReusesBlocks() { | |||
} | |||
|
|||
public void testValidateShardLimit() { | |||
int nodesInCluster = randomIntBetween(2,100); | |||
int nodesInCluster = randomIntBetween(2,90); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
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 |
@elasticmachine run elasticsearch-ci/2 |
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)); | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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!
@elasticmachine update branch |
@elasticmachine update branch |
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
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
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