-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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
Chunked encoding for CCR APIs #92526
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,11 +7,15 @@ | |
|
||
package org.elasticsearch.xpack.ccr.rest; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.elasticsearch.action.support.ThreadedActionListener; | ||
import org.elasticsearch.client.internal.node.NodeClient; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.rest.BaseRestHandler; | ||
import org.elasticsearch.rest.RestRequest; | ||
import org.elasticsearch.rest.action.RestToXContentListener; | ||
import org.elasticsearch.rest.action.RestChunkedToXContentListener; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.xpack.core.ccr.action.FollowStatsAction; | ||
|
||
import java.util.List; | ||
|
@@ -20,6 +24,8 @@ | |
|
||
public class RestFollowStatsAction extends BaseRestHandler { | ||
|
||
private static final Logger logger = LogManager.getLogger(RestFollowStatsAction.class); | ||
|
||
@Override | ||
public List<Route> routes() { | ||
return List.of(new Route(GET, "/{index}/_ccr/stats")); | ||
|
@@ -34,7 +40,17 @@ public String getName() { | |
protected RestChannelConsumer prepareRequest(final RestRequest restRequest, final NodeClient client) { | ||
final FollowStatsAction.StatsRequest request = new FollowStatsAction.StatsRequest(); | ||
request.setIndices(Strings.splitStringByCommaToArray(restRequest.param("index"))); | ||
return channel -> client.execute(FollowStatsAction.INSTANCE, request, new RestToXContentListener<>(channel)); | ||
return channel -> client.execute( | ||
FollowStatsAction.INSTANCE, | ||
request, | ||
new ThreadedActionListener<>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here why does this need threading if it's chunked encoding? |
||
logger, | ||
client.threadPool(), | ||
ThreadPool.Names.MANAGEMENT, | ||
new RestChunkedToXContentListener<>(channel), | ||
false | ||
) | ||
); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,13 +11,15 @@ | |
import org.elasticsearch.action.ActionResponse; | ||
import org.elasticsearch.action.ActionType; | ||
import org.elasticsearch.action.support.master.MasterNodeRequest; | ||
import org.elasticsearch.common.collect.Iterators; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.xcontent.ToXContentObject; | ||
import org.elasticsearch.xcontent.XContentBuilder; | ||
import org.elasticsearch.common.xcontent.ChunkedToXContent; | ||
import org.elasticsearch.xcontent.ToXContent; | ||
import org.elasticsearch.xpack.core.ccr.AutoFollowStats; | ||
|
||
import java.io.IOException; | ||
import java.util.Iterator; | ||
import java.util.Objects; | ||
|
||
public class CcrStatsAction extends ActionType<CcrStatsAction.Response> { | ||
|
@@ -48,7 +50,7 @@ public void writeTo(StreamOutput out) throws IOException { | |
} | ||
} | ||
|
||
public static class Response extends ActionResponse implements ToXContentObject { | ||
public static class Response extends ActionResponse implements ChunkedToXContent { | ||
|
||
private final AutoFollowStats autoFollowStats; | ||
private final FollowStatsAction.StatsResponses followStats; | ||
|
@@ -79,14 +81,14 @@ public void writeTo(StreamOutput out) throws IOException { | |
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
{ | ||
builder.field("auto_follow_stats", autoFollowStats, params); | ||
builder.field("follow_stats", followStats, params); | ||
} | ||
builder.endObject(); | ||
return builder; | ||
public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params outerParams) { | ||
return Iterators.concat( | ||
Iterators.single( | ||
(builder, params) -> builder.startObject().field("auto_follow_stats", autoFollowStats, params).field("follow_stats") | ||
), | ||
followStats.toXContentChunked(outerParams), | ||
Iterators.single((builder, params) -> builder.endObject()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: I added |
||
); | ||
} | ||
|
||
@Override | ||
|
@@ -101,6 +103,7 @@ public boolean equals(Object o) { | |
public int hashCode() { | ||
return Objects.hash(autoFollowStats, followStats); | ||
} | ||
|
||
} | ||
|
||
} |
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 do I still need a threaded listener with chunked encoding?
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.
The
toXContent
implementation collects all the shard responses into a map keyed by index up-front - I think that should be done elsewhere.elasticsearch/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/FollowStatsAction.java
Lines 73 to 78 in c1efe47
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.
On reflection this could reasonably be using the CCR pool, adjusted in a194c11.