-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Conversation
@olcbean maybe you want to have a look too ;) |
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.
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); |
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 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(), |
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.
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)); |
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 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); |
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.
toLowerCase
?
if (randomBoolean()) { | ||
randomAliases(createIndexRequest); | ||
} | ||
} |
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.
Can this be replaced by randomCreateIndexRequest()
? Or maybe removed ?
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.
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.
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.
My bad !
But I do not see it being used here. Did you mean to set it as target?
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 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.
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 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
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.
ops. thanks for being persistent on this :)
} | ||
}); | ||
// end::shrink-index-execute-async | ||
} |
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.
@tlrx should we add assertBusy
here ( the same as for create and delete ) ? Or here it is not needed ?
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 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()) { |
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.
nit : missing whitespace
private static ResizeResponse createTestItem() { | ||
boolean acknowledged = randomBoolean(); | ||
boolean shardsAcknowledged = acknowledged && randomBoolean(); | ||
String index = randomAlphaOfLength(5); |
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.
toLowerCase
?
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.
Ignore!
} | ||
|
||
private static ResizeRequest createTestItem() { | ||
ResizeRequest resizeRequest = new ResizeRequest(randomAlphaOfLengthBetween(3, 10), randomAlphaOfLengthBetween(3, 10)); |
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.
toLowerCase
?
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 know about this, we don't do it in other tests, not sure that we need it?
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.
Ops : there is not validation of the index names here
// <2> | ||
} | ||
}); | ||
// end::split-index-execute-async |
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.
assertBusy
: same as above ?
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.
Same answer :)
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 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()); |
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.
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()); |
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 we check that the target index is not null at this stage?
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.
we already check this in the validate method, which the high level client calls internally.
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, 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) |
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.
Do we expect this test to be executed against something else than a single node 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.
I am not too sure about this. I was under the impression that it could be either 1 or 2, but not too sure.
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 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"); |
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.
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; |
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 feel a bit bad about adding another random stuff generator class in the test framework :(
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.
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`. |
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.
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 |
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.
Nit: extra space too
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
builder.startObject(CreateIndexRequest.SETTINGS.getPreferredName()); |
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.
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()); | ||
} | ||
|
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.
nit: extra line
private RandomCreateIndexGenerator() {} | ||
|
||
/** | ||
* Returns a random {@link CreateIndexRequest}. |
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.
Maybe add more doc about the randomized parts( aliases, settings, mappings only)?
7fbe26a
to
de78192
Compare
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, |
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.
Not for this PR but we might want to rename restHighLevelClient
to client
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.
LGTM, thanks for the changes
1f91579
to
0a1fb6c
Compare
Relates to #27205