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

Types removal - deprecate types in _bulk apis #36549

Merged
merged 1 commit into from
Jan 10, 2019

Conversation

markharwood
Copy link
Contributor

  • Deprecate transport client APIs with document types.
  • Deprecate REST endpoints that have types in URLs or bodies.

Some remaining work (e.g. CRUDDocumentationIT.testBulk code examples) depends on @mayya-sharipova 's changes to IndexRequest for the singular index apis.

@markharwood markharwood added WIP :Search Foundations/Mapping Index mappings, including merging and defining field types v7.0.0 >refactoring labels Dec 12, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search

@markharwood
Copy link
Contributor Author

run gradle build tests

1 similar comment
@markharwood
Copy link
Contributor Author

run gradle build tests

@markharwood markharwood force-pushed the fix/35190bulk branch 6 times, most recently from f578b66 to c0e198f Compare December 20, 2018 14:23
@markharwood
Copy link
Contributor Author

run gradle build tests

1 similar comment
@markharwood
Copy link
Contributor Author

run gradle build tests

@markharwood markharwood force-pushed the fix/35190bulk branch 3 times, most recently from c36372f to c0b5dea Compare December 24, 2018 10:42
@markharwood markharwood force-pushed the fix/35190bulk branch 3 times, most recently from 46ceae8 to e3233f3 Compare January 2, 2019 17:06
@markharwood markharwood force-pushed the fix/35190bulk branch 2 times, most recently from d69dec4 to 49b3568 Compare January 3, 2019 10:28
@markharwood
Copy link
Contributor Author

The last remaining test failure is a rolling upgrade test (IndexingIT) which looks to be failing when a 6.x node is given a types removal warning by a 7.x node.
I've opened #37105 in the 6.x branch to address this which when comitted should hopefully give us a green build here.

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.

What a huge effort!! I left a few preliminary comments as I got up to speed with the approach.

}
}
{
//Check that untyped document additions and untyped global inherit the established custom type
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you be able to explain a bit what 'inherit the custom type' means here? I'm a little unclear on why the custom type would be relevant, since we're setting both the global and local types to 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.

It means the custom document type introduced to the mapping by the earlier code in this test. I'll add a comment.

@@ -55,7 +55,7 @@ public void testReindex() throws IOException {
RestStatus.OK,
highLevelClient().bulk(
bulkRequest,
RequestOptions.DEFAULT
expectWarnings(BulkRequest.TYPES_DEPRECATION_MESSAGE)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that since the reindex PR (#36823) was merged, this is no longer necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, in fact this false expectation causes an error. Will fix

@@ -686,7 +686,7 @@ public void testBulk() throws Exception {
.source(XContentType.JSON,"field", "baz"));
// end::bulk-request
// tag::bulk-execute
BulkResponse bulkResponse = client.bulk(request, RequestOptions.DEFAULT);
BulkResponse bulkResponse = client.bulk(request, RequestOptions.DEFAULT);
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 -- some trailing whitespace here.

@@ -103,7 +103,7 @@ public void setUpDocs() throws IOException {
.endObject());
bulkRequest.add(indexRequest);
}
BulkResponse bulkResponse = highLevelClient().bulk(bulkRequest, RequestOptions.DEFAULT);
BulkResponse bulkResponse = highLevelClient().bulk(bulkRequest, expectWarnings(BulkRequest.TYPES_DEPRECATION_MESSAGE));
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to modify the bulk call instead of expecting a warning here?

@@ -495,6 +496,9 @@ public void testRollover() throws IOException {
Request bulkRequest = new Request("POST", "/" + index + "_write/doc/_bulk");
bulkRequest.setJsonEntity(bulk.toString());
bulkRequest.addParameter("refresh", "");
bulkRequest.setOptions(expectVersionSpecificWarnings((v)->{
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this can just be expectWarnings (same as the call below).

@@ -76,6 +80,8 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
String defaultType = request.param("type");
if (defaultType == null) {
defaultType = MapperService.SINGLE_MAPPING_NAME;
} else {
deprecationLogger.deprecatedAndMaybeLog("bulk_with_types", BulkRequest.TYPES_DEPRECATION_MESSAGE);
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: would it make sense to move the deprecation message to this action class, for consistency with the other APIs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If that's the convention, sure, I can make that change

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@markharwood
Copy link
Contributor Author

run gradle build tests

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 is looking good to me! I will wait on the build results before hitting 'approve', in case another issue comes up or you'd like another pair of eyes on it (some of the changes around defaults in IndexRequest are a bit subtle).


private BulkResponse bulkWithTypes(BulkRequest request) throws IOException {
BulkResponse bulkResponse = execute(request, highLevelClient()::bulk, highLevelClient()::bulkAsync,
expectVersionSpecificWarnings((v)->{v.current(BulkRequest.TYPES_DEPRECATION_MESSAGE);}));
Copy link
Contributor

Choose a reason for hiding this comment

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

One more instance of expectVersionSpecificWarnings that can be updated to expectWarnings.

@@ -1070,6 +1072,9 @@ private void checkSnapshot(String snapshotName, int count, Version tookOnVersion
Request writeToRestoredRequest = new Request("POST", "/restored_" + index + "/doc/_bulk");
writeToRestoredRequest.addParameter("refresh", "true");
writeToRestoredRequest.setJsonEntity(bulk.toString());
writeToRestoredRequest.setOptions(expectVersionSpecificWarnings((v)->{
Copy link
Contributor

Choose a reason for hiding this comment

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

Same thought here.

@@ -82,7 +83,7 @@
*/
static final int MAX_SOURCE_LENGTH_IN_TOSTRING = 2048;

private String type = MapperService.SINGLE_MAPPING_NAME;
private String type;
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be useful to add a comment to these files IndexRequest, UpdateRequest, and DeleteRequest) explaining the different states of the type parameter, as it is not very obvious to a newcomer. I really should've done this in my initial PRs that began to modify these files, apologies for punting on that.

@jtibshirani
Copy link
Contributor

@elasticmachine run gradle build tests 1

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.

Thanks @markharwood, this looks good to me. My only other thought is that it'd be good to update the PR description with an explanation of how bulk, index, update, and delete requests have changed (perhaps mentioning defaultTypeIfNull).

@@ -51,7 +51,7 @@ public void testBulkPipelineUpsert() throws Exception {
new RestBulkAction(settings(Version.CURRENT).build(), mock(RestController.class))
Copy link
Contributor

Choose a reason for hiding this comment

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

In other PRs we have added a dedicated test here to ensure we're emitting deprecation warnings. However, there are several integration tests in this PR that maked typed calls and check for deprecation warnings, so I don't think it's strictly necessary.

@markharwood markharwood force-pushed the fix/35190bulk branch 3 times, most recently from 2955a7f to 4bea050 Compare January 8, 2019 15:59
@markharwood
Copy link
Contributor Author

run gradle build tests

@markharwood markharwood force-pushed the fix/35190bulk branch 2 times, most recently from f0d8a00 to c2a16b7 Compare January 9, 2019 11:14
Copy link
Member

@cbuescher cbuescher left a comment

Choose a reason for hiding this comment

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

@markharwood I did a first quick pass ignoring the changes in test classes, will take a look at those also if needed

/**
* @deprecated Types are in the process of being removed. Use {@link #BulkRequest(String)} instead
*/
@Deprecated
public BulkRequest(@Nullable String globalIndex, @Nullable String globalType) {
Copy link
Member

Choose a reason for hiding this comment

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

It looks like CRUDDocumentationIT is using this deprecatd ctor still (amongst other). Since its code that is contained in the docs, should we move that to using the typeless constructor?

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'm not sure - it's documentation showing how index and type can be associated with the BulkRequest and "inherited" by an IndexRequest objects that are missing these values.

I suppose it's a general point if we want documentation to include supported-yet-deprecated features? I can pull the docs/code if we think that's the right thing. Thoughts? cc @jtibshirani

Copy link
Contributor

Choose a reason for hiding this comment

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

We've been removing documentation for deprecated features, with the understanding that users can refer to the previous version's documentation (where the feature is not deprecated).

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the clarification, I think you are refering to https://www.elastic.co/guide/en/elasticsearch/client/java-rest/master/java-rest-high-document-bulk.html#CO102-1. I would be in favour of removing the mentioning of the type there as well and changing to the other ctor then.

* or empty
* @return the Request
*/
T defaultTypeIfNull(String defaultType);
Copy link
Member

Choose a reason for hiding this comment

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

Can you briefly explain why this is added? Only to improve my understanding of the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bulk requests can specify a default index and type which is automatically filled-in on any contained Index/Update/DeleteRequests that are missing these properties. A form of inheritance.

This is the method where any blank choice of type is overridden with the BulkRequest's choice of type. This code became necessary after a different PR switched the Index/Update/DeleteRequests to default to _doc instead of null - all the bulk type inheritance tests failed because we couldn't differentiate between objects where the user had explicitly defined a choice of _doc and those where the user had not made an explicit choice. Here we have to revert back to holding a null for this setting by default.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the explanation, think I got it.

@@ -152,9 +154,6 @@ public IndexRequest(String index, String type, String id) {
@Override
public ActionRequestValidationException validate() {
ActionRequestValidationException validationException = super.validate();
if (type == null) {
validationException = addValidationError("type is missing", validationException);
}
Copy link
Member

Choose a reason for hiding this comment

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

Any reason this is removed here but still validated in DeleteRequest?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I can't think why they should differ

@cbuescher
Copy link
Member

@markharwood rest of the PR (test changes) look good to me btw.

@markharwood markharwood force-pushed the fix/35190bulk branch 2 times, most recently from facae87 to 89aa779 Compare January 10, 2019 10:44
Copy link
Member

@cbuescher cbuescher left a comment

Choose a reason for hiding this comment

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

@markharwood thanks for the update, LGTM.

Added warnings checks to existing tests
Added “defaultTypeIfNull” to DocWriteRequest interface so that Bulk requests can override a null choice of document type with any global custom choice.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>refactoring :Search Foundations/Mapping Index mappings, including merging and defining field types v7.0.0-beta1 WIP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants