-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Make _doc work as an alias of the actual type of an index.
#39505
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
Conversation
This is similar to the work that has been done on 7.x to make typeless API calls work on indices that have types, except that this commit doesn't introduce typeless calls, eg. the REST API spec or REST handlers haven't been updated. It only affects the get, index, update, delete and bulk APIs. Other APIs that require types such as explain or termvectors are left unchanged. This is necesarry to allow for rolling upgrades from 6.7 to 7.x while internal indices might remain queried during upgrade by nodes that are on either version. Closes elastic#39469
|
Pinging @elastic/es-distributed |
jtibshirani
left a comment
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.
Thanks @jpountz, I left some comments but it looks very close to me. Except for the point around 'routing' below, all changes we tracked in #37450 seem to be reflected here.
I had two additional questions:
- Would it be worth adding light tests that use
_docwith the transport client? That is the functionality we're actually adding here (and that ML + others will be depending on), so it might be nice to have dedicated tests. - It could be worth catching up with someone from the distributed team to see if any issues stand out to them, or they expect any differences between 6.7 and 7.0. It's very much up to you, I'm just suggesting this as we don't have as much time to let this 'bake' in CI for 6.7 in order to catch tricky issues.
| * being used in the mappings. This allows typeless APIs such as 'index' or 'put mappings' | ||
| * to work against indices with a custom type name. | ||
| */ | ||
| public String resolveDocumentType(String type) { |
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, but would it make sense to always call this as part of the IndexMetaData#mappingOrDefault method, instead of doing mappingOrDefault(indexMetaData.resolveDocumentType...) at each call site? That matches what happens on 7.x slightly more closely, and this could become package-private for testing.
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.
7.x is a bit simpler since this method no longer takes a type parameter. I considered having it as part of mappingOrDefault but then it felt wrong to not have this logic in mapping as well, while the automatic replacement does not always make sense for call sites of the mapping method such as MapperService#assertMappingVersion.
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.
👍
| assertEquals("the number of source shards [2] must be a factor of [3]", iae.getMessage()); | ||
| } | ||
|
|
||
| public void testResolveDocumentType() throws IOException { |
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.
Thanks for these great unit tests!
| assert versionType.validateVersionForWrites(version); | ||
|
|
||
| String resolvedType = mapperService.resolveDocumentType(sourceToParse.type()); | ||
| if (resolvedType != sourceToParse.type()) { |
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.
Since this is a string comparison, it would be good to switch to resolvedType.equals(sourceToParse.type()) == false.
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.
OK I'l do that.
| : "op term [ " + opPrimaryTerm + " ] > shard term [" + getOperationPrimaryTerm() + "]"; | ||
| assert versionType.validateVersionForWrites(version); | ||
|
|
||
| String resolvedType = mapperService.resolveDocumentType(sourceToParse.type()); |
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, but I am wondering why this change is structured slightly differently than it is on master -- it just looks like a refactor to me, and that nothing has changed in terms of functionality. If that's true, then maybe it's worth keeping it in the same structure so the code lines up better between versions (even if it's a bit less elegant)?
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.
👍
| : "op term [ " + opPrimaryTerm + " ] > shard term [" + getOperationPrimaryTerm() + "]"; | ||
| assert versionType.validateVersionForWrites(version); | ||
|
|
||
| type = mapperService.resolveDocumentType(type); |
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 this type resolution here (which doesn't appear on master either)? To me it looks like resolution is already handled in the individual calls to docMapper and prepareDelete.
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.
Thanks for catching this, it was probably only useful in an earlier version of the change.
| .put("index.number_of_replicas", 0).build(); | ||
| createIndex("index", settings, "some_type", "_routing", "required=true"); | ||
|
|
||
| expectThrows(RoutingMissingException.class, |
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 didn't see any changes to 'required routing' for delete, update, or get -- I think we might need to resolve the type in some additional places.
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.
Good catch.
|
@dnhatn I added you as a reviewer since you dug the bug about duplicate translog entries. If you could take a look - even after merge in case Julie approves changes before you have a chance to review - this would be great. |
jtibshirani
left a comment
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 with the latest changes. I'm also happy if you want to merge now, and have @dnhatn review post-merge.
|
Thanks @jtibshirani. @dnhatn I'll merge this now, but I'm still interested in your opinion when you have a chance to look. |
dnhatn
left a comment
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.
LGTM.
|
Thank you @dnhatn ! |
This is similar to the work that has been done on 7.x to make typeless API calls
work on indices that have types, except that this commit doesn't introduce
typeless calls, eg. the REST API spec or REST handlers haven't been updated.
It only affects the get, index, update, delete and bulk APIs. Other APIs that
require types such as explain or termvectors are left unchanged.
This is necesarry to allow for rolling upgrades from 6.7 to 7.x while internal
indices might remain queried during upgrade by nodes that are on either version.
Closes #39469