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

REST high-level client: add support for split and shrink index API #28425

Merged
merged 6 commits into from
Feb 1, 2018

Conversation

javanna
Copy link
Member

@javanna javanna commented Jan 29, 2018

Relates to #27205

@javanna
Copy link
Member Author

javanna commented Jan 29, 2018

@olcbean maybe you want to have a look too ;)

Copy link
Contributor

@olcbean olcbean left a comment

Choose a reason for hiding this comment

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

LGMT! I left few comments : mostly nits.

@@ -69,7 +67,7 @@ public void testCreateIndex() throws IOException {
CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);

CreateIndexResponse createIndexResponse =
execute(createIndexRequest, highLevelClient().indices()::create, highLevelClient().indices()::createAsync);
execute(createIndexRequest, highLevelClient().indices()::create, highLevelClient().indices()::createAsync);
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for reformatting ;)

createIndex(name, settings, "");
}

protected void createIndex(String name, Settings settings, String mapping) throws IOException {
protected static void createIndex(String name, Settings settings, String mapping) throws IOException {
assertOK(client().performRequest("PUT", name, Collections.emptyMap(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe HttpPut.METHOD_NAME instead?


private static void resizeTest(ResizeType resizeType, CheckedFunction<ResizeRequest, Request, IOException> function)
throws IOException {
ResizeRequest resizeRequest = new ResizeRequest(randomAlphaOfLengthBetween(3, 10), randomAlphaOfLengthBetween(3, 10));
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 would be better to call toLowerCase as the index should be lowercase ( or generate randomIndicesNames )

* Returns a random {@link CreateIndexRequest}.
*/
public static CreateIndexRequest randomCreateIndexRequest() throws IOException {
String index = randomAlphaOfLength(5);
Copy link
Contributor

Choose a reason for hiding this comment

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

toLowerCase ?

if (randomBoolean()) {
randomAliases(createIndexRequest);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be replaced by randomCreateIndexRequest()? Or maybe removed ?

Copy link
Member Author

Choose a reason for hiding this comment

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

no, resize supports only a couple of sections compared to create index (aliases and settings only). I think it is better to set only those specifically.

Copy link
Contributor

Choose a reason for hiding this comment

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

My bad !
But I do not see it being used here. Did you mean to set it as target?

Copy link
Member Author

Choose a reason for hiding this comment

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

it should be set within the method, that is why we pass in the request, otherwise we'd have to return a List<Alias> and set them one by one as the request doesn't accept a list of alias directly.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am afraid I am missing something ...
I am not sure why createIndexRequest in initialized but not used in the resizeRequest : I would have expected to see something like :
resizeRequest.setTargetIndex(createIndexRequest) ?
Currently it seems that the targetIndexRequest is always null regardless of the randomization

Copy link
Member Author

Choose a reason for hiding this comment

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

ops. thanks for being persistent on this :)

}
});
// end::shrink-index-execute-async
}
Copy link
Contributor

Choose a reason for hiding this comment

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

@tlrx should we add assertBusy here ( the same as for create and delete ) ? Or here it is not needed ?

Copy link
Member

Choose a reason for hiding this comment

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

I think that this is OK here because the test framework will wait for pending cluster state updates to be processed before executing the next test and resize action is based on cluster state updates.

targetIndexRequest.settings().toXContent(builder, params);
builder.endObject();
builder.startObject(CreateIndexRequest.ALIASES.getPreferredName());
for (Alias alias :targetIndexRequest.aliases()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit : missing whitespace

private static ResizeResponse createTestItem() {
boolean acknowledged = randomBoolean();
boolean shardsAcknowledged = acknowledged && randomBoolean();
String index = randomAlphaOfLength(5);
Copy link
Contributor

Choose a reason for hiding this comment

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

toLowerCase ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ignore!

}

private static ResizeRequest createTestItem() {
ResizeRequest resizeRequest = new ResizeRequest(randomAlphaOfLengthBetween(3, 10), randomAlphaOfLengthBetween(3, 10));
Copy link
Contributor

Choose a reason for hiding this comment

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

toLowerCase ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know about this, we don't do it in other tests, not sure that we need it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ops : there is not validation of the index names here

// <2>
}
});
// end::split-index-execute-async
Copy link
Contributor

Choose a reason for hiding this comment

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

assertBusy : same as above ?

Copy link
Member

Choose a reason for hiding this comment

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

Same answer :)

Copy link
Member

@tlrx tlrx 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 great! I left many comments but most of them are really minor.

@@ -484,6 +486,31 @@ static Request existsAlias(GetAliasesRequest getAliasesRequest) {
return new Request(HttpHead.METHOD_NAME, endpoint, params.getParams(), null);
}

static Request split(ResizeRequest resizeRequest) throws IOException {
if (resizeRequest.getResizeType() != ResizeType.SPLIT) {
throw new IllegalArgumentException("Wrong resize type for indices.split request: " + resizeRequest.getResizeType());
Copy link
Member

Choose a reason for hiding this comment

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

Nit: can we change the message to something like "Wrong resize type [..] for indices split request"?

Params params = Params.builder();
params.withTimeout(resizeRequest.timeout());
params.withMasterTimeout(resizeRequest.masterNodeTimeout());
params.withWaitForActiveShards(resizeRequest.getTargetIndexRequest().waitForActiveShards());
Copy link
Member

Choose a reason for hiding this comment

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

Should we check that the target index is not null at this stage?

Copy link
Member Author

Choose a reason for hiding this comment

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

we already check this in the validate method, which the high level client calls internally.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I know but I was thinking we could be more defensive. On the other side there's no reason this method would be reused somewhere else so let's keep it like this.

Map<String, Object> nodes = getAsMap("_nodes");
String firstNode = ((Map<String, Object>) nodes.get("nodes")).keySet().iterator().next();
createIndex("source", Settings.builder().put("index.number_of_shards", 4).put("index.number_of_replicas", 0).build());
updateIndexSettings("source", Settings.builder().put("index.routing.allocation.require._name", firstNode)
Copy link
Member

Choose a reason for hiding this comment

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

Do we expect this test to be executed against something else than a single node cluster?

Copy link
Member Author

Choose a reason for hiding this comment

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

I am not too sure about this. I was under the impression that it could be either 1 or 2, but not too sure.

Copy link
Member

Choose a reason for hiding this comment

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

I think it's always a single node cluster, but I'm good to keep it like this.

ResizeResponse resizeResponse = highLevelClient().indices().shrink(resizeRequest);
assertTrue(resizeResponse.isAcknowledged());
assertTrue(resizeResponse.isShardsAcknowledged());
Map<String, Object> indexMetadata = getIndexMetadata("target");
Copy link
Member

Choose a reason for hiding this comment

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

Do you have an objection in using XContentMapValues.extractValue() ?

@@ -101,6 +104,9 @@
import static java.util.Collections.singletonMap;
import static org.elasticsearch.client.Request.REQUEST_BODY_CONTENT_TYPE;
import static org.elasticsearch.client.Request.enforceSameContentType;
import static org.elasticsearch.index.RandomCreateIndexGenerator.randomAliases;
Copy link
Member

Choose a reason for hiding this comment

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

I feel a bit bad about adding another random stuff generator class in the test framework :(

Copy link
Member Author

@javanna javanna Feb 1, 2018

Choose a reason for hiding this comment

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

why? we need it in both the client tests and core tests after all. Maybe you have a better name in mind perhaps?

include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[shrink-index-request-waitForActiveShards]
--------------------------------------------------
<1> The number of active shard copies to wait for before the shrink index API
returns a response, as an `int`.
Copy link
Member

Choose a reason for hiding this comment

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

Nit: sometimes there's a point at the end of the line, sometimes not

--------------------------------------------------
<1> The number of active shard copies to wait for before the split index API
returns a response, as an `int`.
<2> The number of active shard copies to wait for before the split index API
Copy link
Member

Choose a reason for hiding this comment

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

Nit: extra space too

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.startObject(CreateIndexRequest.SETTINGS.getPreferredName());
Copy link
Member

Choose a reason for hiding this comment

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

Nit: could we add some empty lines or anonymous blocks around start/end object to make the object creation easier to read?

assertEquals(resizeResponse.isShardsAcknowledged(), parsedResizeResponse.isShardsAcknowledged());
assertEquals(resizeResponse.isAcknowledged(), parsedResizeResponse.isAcknowledged());
}

Copy link
Member

Choose a reason for hiding this comment

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

nit: extra line

private RandomCreateIndexGenerator() {}

/**
* Returns a random {@link CreateIndexRequest}.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add more doc about the randomized parts( aliases, settings, mappings only)?

@javanna javanna force-pushed the enhancement/hl_client_resize branch from 7fbe26a to de78192 Compare February 1, 2018 10:15
@javanna
Copy link
Member Author

javanna commented Feb 1, 2018

thanks @tlrx I have addressed your comments

* Shrink Index API on elastic.co</a>
*/
public ResizeResponse shrink(ResizeRequest resizeRequest, Header... headers) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(resizeRequest, Request::shrink, ResizeResponse::fromXContent,
Copy link
Member

Choose a reason for hiding this comment

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

Not for this PR but we might want to rename restHighLevelClient to client here

Copy link
Member

@tlrx tlrx left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the changes

@javanna javanna force-pushed the enhancement/hl_client_resize branch from 1f91579 to 0a1fb6c Compare February 1, 2018 15:35
@javanna javanna merged commit d860971 into elastic:master Feb 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants