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

Deprecate types in rollover index API #38039

Merged

Conversation

mayya-sharipova
Copy link
Contributor

Relates to #35190

@mayya-sharipova mayya-sharipova added the :Search Foundations/Mapping Index mappings, including merging and defining field types label Jan 30, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search

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 so much @mayya-sharipova for tackling this API that we missed originally.

Because we missed it in the original PR to add include_type_name to the relevant REST APIs, in this PR I think we also need to update RestRolloverIndexAction to accept a include_type_name parameter, and emit a deprecation warning if it's set. The logic will probably end up looking similar to that in RestCreateIndexAction. I'm guessing the tests are all passing because IndicesClientIT#testRollover happens to never specify mappings, so we don't hit the case where RestRolloverIndexAction has to parse a typeless mapping definition..

I'll also add @hub-cap as a reviewer so that he can take a look at the Java HLRC changes.

@@ -54,9 +54,9 @@ include-tagged::{doc-tests-file}[{api}-request-masterTimeout]
include-tagged::{doc-tests-file}[{api}-request-waitForActiveShards]
--------------------------------------------------
<1> The number of active shard copies to wait for before the rollover index API
returns a response, as an `int`
returns a response
<2> The number of active shard copies to wait for before the rollover index API
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: instead of having the exact same text for both callouts, maybe we could change the second to say "Resets the number of active shard copies to wait for to the default value"?

}

private static void toXContent(RolloverResponse response, XContentBuilder builder) throws IOException {
builder.startObject();
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of duplicating toXContent logic, in recent PRs we have been converting the client-side response to a server response, and then calling toXContent on the server response. Here's an example: https://github.com/elastic/elasticsearch/blob/master/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetMappingsResponseTests.java#L102

This is something we only agreed on recently, I didn't catch it on our earlier PRs (like for get field mappings).

Copy link
Contributor

Choose a reason for hiding this comment

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

yay constant change!!!! :P

@@ -76,6 +74,8 @@
import org.elasticsearch.client.indices.PutIndexTemplateRequest;
import org.elasticsearch.client.indices.PutMappingRequest;
import org.elasticsearch.client.indices.UnfreezeIndexRequest;
import org.elasticsearch.client.indices.rollover.RolloverRequest;
Copy link
Contributor

@jtibshirani jtibshirani Jan 30, 2019

Choose a reason for hiding this comment

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

It would be good to update testRollover to also specify mappings, so we can test our changes related to types.

@@ -58,7 +59,7 @@ protected RolloverResponse createTestInstance() {
private static final List<Supplier<Condition<?>>> conditionSuppliers = new ArrayList<>();
static {
conditionSuppliers.add(() -> new MaxAgeCondition(new TimeValue(randomNonNegativeLong())));
conditionSuppliers.add(() -> new MaxDocsCondition(randomNonNegativeLong()));
conditionSuppliers.add(() -> new MaxSizeCondition(new ByteSizeValue(randomNonNegativeLong())));
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

*/
public class RolloverRequest extends TimedRequest implements Validatable, ToXContentObject {

static final String AGE_CONDITION = "max_age";
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 it might be cleaner if we continued to use the Condition class, as we do in the server-side request class. This would also make the toXContent method more robust/ type safe.

We decided earlier that although we would like to duplicate the request + response classes into client-side versions, we were okay if these classes referenced server objects internally. So we could just use the server-side Condition class here, and not worry about duplicating it as well.

* Sets the timeout to wait for the all the nodes to acknowledge
* @param timeout timeout as a string (e.g. 1s)
*/
public void setTimeout(String timeout) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I touched a few requests that also extended TimedRequest, and opted to just omit these methods (and update the HLRC documentation to remove calls to them). We have been trying to keep these new client-side classes as small as possible, as it is easier to add methods after getting user feedback than to remove them.

/**
* Request class to swap index under an alias upon satisfying conditions
*/
public class RolloverRequest extends TimedRequest implements Validatable, ToXContentObject {
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be great to have a test RolloverRequestTests for this new client class. Maybe since the toXContent method is fairly simple, we could just write a few manual tests for serialization, instead of trying to use an xContentTester?

private CreateIndexRequest createIndexRequest = new CreateIndexRequest("_na_");

public RolloverRequest(String alias, String newIndexName) {
this.alias = alias;
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can validate that alias is not null here, as we do in the server-side RolloverRequest.

Copy link
Contributor

Choose a reason for hiding this comment

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

++ to validating all things in a constructor, and making them final as well.

public static void randomAliases(CreateIndexRequest request) {
int aliasesNo = randomIntBetween(0, 2);
for (int i = 0; i < aliasesNo; i++) {
request.alias(randomAlias());
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of copying over the logic for randomAlias, could we make org.elasticsearch.index.RandomCreateIndexGenerator.randomAlias public and use it?

Copy link
Contributor

@hub-cap hub-cap left a comment

Choose a reason for hiding this comment

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

all minor nits, this is pretty much lgtm for me, but ill let @jtibshirani be the final review.

private CreateIndexRequest createIndexRequest = new CreateIndexRequest("_na_");

public RolloverRequest(String alias, String newIndexName) {
this.alias = alias;
Copy link
Contributor

Choose a reason for hiding this comment

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

++ to validating all things in a constructor, and making them final as well.

(Boolean)args[3], (Boolean)args[4], (Boolean) args[5], (Boolean) args[6]));

static {
PARSER.declareField(constructorArg(), (parser, context) -> parser.text(), OLD_INDEX, ObjectParser.ValueType.STRING);
Copy link
Contributor

Choose a reason for hiding this comment

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

these can probably be .declareString(constructorArg(), OLD_INDEX), same with the declareBoolean as well.

public RolloverResponse(String oldIndex, String newIndex, Map<String, Boolean> conditionResults,
boolean dryRun, boolean rolledOver, boolean acknowledged, boolean shardsAcknowledged) {
super(acknowledged, shardsAcknowledged);
this.oldIndex = oldIndex;
Copy link
Contributor

Choose a reason for hiding this comment

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

can you make the fields in the RolloverResponse final pls

/**
* Response object for {@link RolloverRequest} API
*/
public final class RolloverResponse extends ShardsAcknowledgedResponse {
Copy link
Contributor

Choose a reason for hiding this comment

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

does this need to be a ShardsAcknowledgedResponse?

Copy link
Contributor

Choose a reason for hiding this comment

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

WRT declareAcknowledgedAndShardsAcknowledgedFields, i think we can do something client side thats small and similar? Do we have (m)any classes in o.e.client.indicies using it? Maybe we can put a parent class in o.e.client.indicies that is similar in how it functions.

}

private static void toXContent(RolloverResponse response, XContentBuilder builder) throws IOException {
builder.startObject();
Copy link
Contributor

Choose a reason for hiding this comment

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

yay constant change!!!! :P

}

@Override
protected void addCustomFields(XContentBuilder builder, Params params) throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

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

is this needed?

/**
* Response object for {@link RolloverRequest} API
*
* Note: there is a new class with the same name for the Java HLRC that uses a typeless format.
Copy link
Contributor

Choose a reason for hiding this comment

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

<3

/**
* Request class to swap index under an alias upon satisfying conditions
*/
public class RolloverRequest extends TimedRequest implements Validatable, ToXContentObject {
Copy link
Contributor

Choose a reason for hiding this comment

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

is there nothing to Validate? its fine, just making sure.

@mayya-sharipova
Copy link
Contributor Author

@jtibshirani Julie, thanks a lot for such a comprehensive feedback. I have tried to address all your comments except not copying over the logic for randomAlias from org.elasticsearch.index.RandomCreateIndexGenerator.randomAlias. It was not possible as the server's randomAlias expects the server's CreateIndexRequest, that is why we need a copy of that in the client that expects the client's CreateIndexRequest.

@jtibshirani Julie, I particularly wanted to ask your feedback on the way I implemented mapping parsing in the server's RolloverRequest: https://github.com/elastic/elasticsearch/pull/38039/files#diff-2902594b9bc003bcb80ffcb6db13d7a7R74. and in RestRolloverIndexAction https://github.com/elastic/elasticsearch/pull/38039/files#diff-2902594b9bc003bcb80ffcb6db13d7a7R74? Are we happy with this approach? Or would you suggest something else?

@hub-cap Thanks a lot for the review. I will address your feedback in the next commit. I wanted to ask you, why are making the client HLRC Request/Response classes to be again dependent on the server's ones? I remember that before we have made a decision to separate the client HLRC classes from the server code as much as possible, as we reverting this decision now?

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 have tried to address all your comments except not copying over the logic for randomAlias from org.elasticsearch.index.RandomCreateIndexGenerator.randomAlias.

I was just referring to the method randomAlias, which creates an Alias (it doesn't mention CreateIndexRequest at all). It's currently private, but we could make it a public method and call it instead of duplicating that randomization logic.

I particularly wanted to ask your feedback on the way I implemented mapping parsing in the server's RolloverRequest.

It looks good to me overall, I added a suggestion in the code.

I wanted to ask you, why are making the client HLRC Request/Response classes to be again dependent on the server's ones?

I filled @mayya-sharipova in offline about our conversation. I think the short answer is that while the long-term goal is still to cut the server dependency completely, we decided on a compromise for this time-sensitive work where we would create new client requests + responses, but still use some server objects internally.

One other thought I forgot to mention in my first review -- it would be great to add one yml test case, as none of the existing ones for rollover involve mappings.


@Override
public Optional<ValidationException> validate() {
if (alias == null) {
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 for the new HLRC classes, we've been trying to just validate in the constructor, as opposed to using this special validate method.

Copy link
Contributor

Choose a reason for hiding this comment

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

you can use Objects.requireNotNull() here.

RolloverRequest rolloverIndexRequest = new RolloverRequest(request.param("index"), request.param("new_index"));
if (includeTypeName == false) {
rolloverIndexRequest.setNoTypeNameForMappingParsing();
Copy link
Contributor

Choose a reason for hiding this comment

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

This overall approach looks good to me, but I wonder if instead of setting a special flag on the request here, we can just pass a boolean includeTypeName to the fromXContent method? In particular, parse methods take an arbitary Context parameter that I think you could use to pass in the boolean. Here is an example from FieldCapabilities where we are passing in a String name to the ObjectParser: https://github.com/elastic/elasticsearch/blob/master/server/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilities.java#L136-L138

@mayya-sharipova
Copy link
Contributor Author

mayya-sharipova commented Feb 4, 2019

@hub-cap Thanks for the review. The PR is ready for another round of review. I have address all your comments, except that if RolloverResponse class needs to extend ShardsAcknowledgedResponse. It doesn't need, and indeed we can create a client side class that is smaller. But because of the time constraints for the feature freeze, would be ok to leave this work for later?

@jtibshirani Thanks for another round of review, I have tried to address your comments in the last commit. Can you please review again

Copy link
Contributor

@hub-cap hub-cap left a comment

Choose a reason for hiding this comment

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

LGTM, i didnt see an answer on the class extending ShardsAcknowledgedResponse but i dont think thats a deal breaker. one other nit inline


@Override
public Optional<ValidationException> validate() {
if (alias == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

you can use Objects.requireNotNull() 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.

This looks good to me! I'll also take a look at the question around ShardsAcknowledgedResponse (for a future PR), as I ended up using it for CreateIndexResponse as well.

- do:
index:
index: logs-1
type: test
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 not sure it's worth another update + build, but a note that we've been trying to avoid typed index calls (unless we're explicitly testing typed behavior as in 41_mapping_with_types).

@mayya-sharipova
Copy link
Contributor Author

@jtibshirani Thanks Julie for the review.,
I have decided to trigger another update+ build to address your comment for the types in yml tests.

About ShardsAcknowledgedResponse, and I talked offline with @hub-cap, and we have decided it would be ok to address this in a separate PR. I have filed an issue for this

@mayya-sharipova mayya-sharipova merged commit 6417044 into elastic:master Feb 4, 2019
@mayya-sharipova mayya-sharipova deleted the deprecate-types-rollover branch February 4, 2019 21:07
mayya-sharipova added a commit to mayya-sharipova/elasticsearch that referenced this pull request Feb 5, 2019
jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request Feb 5, 2019
…-lease-expiration

* elastic/master: (24 commits)
  Add support for API keys to access Elasticsearch (elastic#38291)
  Add typless client side GetIndexRequest calls and response class (elastic#37778)
  Limit token expiry to 1 hour maximum (elastic#38244)
  add docs saying mixed-cluster ILM is not supported (elastic#37954)
  Skip unsupported languages for tests (elastic#38328)
  Deprecate `_type` in simulate pipeline requests (elastic#37949)
  Mute testCannotShrinkLeaderIndex (elastic#38374)
  Tighten mapping syncing in ccr remote restore (elastic#38071)
  Add test for `PutFollowAction` on a closed index (elastic#38236)
  Fix SSLContext pinning to TLSV1.2 in reload tests (elastic#38341)
  Mute RareClusterStateIT.testDelayedMappingPropagationOnReplica (elastic#38357)
  Deprecate types in rollover index API (elastic#38039)
  Types removal - fix FullClusterRestartIT warning expectations (elastic#38310)
  Fix ILM explain response to allow unknown fields (elastic#38054)
  Mute testFollowIndexAndCloseNode (elastic#38360)
  Docs: Drop inline callout from scroll example (elastic#38340)
  Deprecate HLRC security methods (elastic#37883)
  Remove types from Monitoring plugin "backend" code (elastic#37745)
  Add Composite to AggregationBuilders (elastic#38207)
  Clarify slow cluster-state log messages (elastic#38302)
  ...
mayya-sharipova added a commit that referenced this pull request Feb 5, 2019
mayya-sharipova added a commit to mayya-sharipova/elasticsearch that referenced this pull request Feb 5, 2019
mayya-sharipova added a commit that referenced this pull request Feb 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>deprecation :Search Foundations/Mapping Index mappings, including merging and defining field types v7.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants