Skip to content

Commit a23bb30

Browse files
committed
[HLRC] Added support for CCR Resume Follow API (#35638)
This change also adds documentation for the Resume Follow API Relates to #33824
1 parent 2fff5a3 commit a23bb30

File tree

10 files changed

+579
-164
lines changed

10 files changed

+579
-164
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/CcrClient.java

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.elasticsearch.client.ccr.PauseFollowRequest;
2424
import org.elasticsearch.client.ccr.PutFollowRequest;
2525
import org.elasticsearch.client.ccr.PutFollowResponse;
26+
import org.elasticsearch.client.ccr.ResumeFollowRequest;
2627
import org.elasticsearch.client.ccr.UnfollowRequest;
2728
import org.elasticsearch.client.core.AcknowledgedResponse;
2829

@@ -90,7 +91,7 @@ public void putFollowAsync(PutFollowRequest request,
9091
}
9192

9293
/**
93-
* Instructs a follower index the pause the following of a leader index.
94+
* Instructs a follower index to pause the following of a leader index.
9495
*
9596
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-pause-follow.html">
9697
* the docs</a> for more.
@@ -111,7 +112,7 @@ public AcknowledgedResponse pauseFollow(PauseFollowRequest request, RequestOptio
111112
}
112113

113114
/**
114-
* Asynchronously instruct a follower index the pause the following of a leader index.
115+
* Asynchronously instruct a follower index to pause the following of a leader index.
115116
*
116117
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-pause-follow.html">
117118
* the docs</a> for more.
@@ -131,6 +132,48 @@ public void pauseFollowAsync(PauseFollowRequest request,
131132
Collections.emptySet());
132133
}
133134

135+
/**
136+
* Instructs a follower index to resume the following of a leader index.
137+
*
138+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-resume-follow.html">
139+
* the docs</a> for more.
140+
*
141+
* @param request the request
142+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
143+
* @return the response
144+
* @throws IOException in case there is a problem sending the request or parsing back the response
145+
*/
146+
public AcknowledgedResponse resumeFollow(ResumeFollowRequest request, RequestOptions options) throws IOException {
147+
return restHighLevelClient.performRequestAndParseEntity(
148+
request,
149+
CcrRequestConverters::resumeFollow,
150+
options,
151+
AcknowledgedResponse::fromXContent,
152+
Collections.emptySet()
153+
);
154+
}
155+
156+
/**
157+
* Asynchronously instruct a follower index to resume the following of a leader index.
158+
*
159+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-resume-follow.html">
160+
* the docs</a> for more.
161+
*
162+
* @param request the request
163+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
164+
*/
165+
public void resumeFollowAsync(ResumeFollowRequest request,
166+
RequestOptions options,
167+
ActionListener<AcknowledgedResponse> listener) {
168+
restHighLevelClient.performRequestAsyncAndParseEntity(
169+
request,
170+
CcrRequestConverters::resumeFollow,
171+
options,
172+
AcknowledgedResponse::fromXContent,
173+
listener,
174+
Collections.emptySet());
175+
}
176+
134177
/**
135178
* Instructs a follower index to unfollow and become a regular index.
136179
* Note that index following needs to be paused and the follower index needs to be closed.

client/rest-high-level/src/main/java/org/elasticsearch/client/CcrRequestConverters.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.http.client.methods.HttpPut;
2424
import org.elasticsearch.client.ccr.PauseFollowRequest;
2525
import org.elasticsearch.client.ccr.PutFollowRequest;
26+
import org.elasticsearch.client.ccr.ResumeFollowRequest;
2627
import org.elasticsearch.client.ccr.UnfollowRequest;
2728

2829
import java.io.IOException;
@@ -50,6 +51,16 @@ static Request pauseFollow(PauseFollowRequest pauseFollowRequest) {
5051
return new Request(HttpPost.METHOD_NAME, endpoint);
5152
}
5253

54+
static Request resumeFollow(ResumeFollowRequest resumeFollowRequest) throws IOException {
55+
String endpoint = new RequestConverters.EndpointBuilder()
56+
.addPathPart(resumeFollowRequest.getFollowerIndex())
57+
.addPathPartAsIs("_ccr", "resume_follow")
58+
.build();
59+
Request request = new Request(HttpPost.METHOD_NAME, endpoint);
60+
request.setEntity(createEntity(resumeFollowRequest, REQUEST_BODY_CONTENT_TYPE));
61+
return request;
62+
}
63+
5364
static Request unfollow(UnfollowRequest unfollowRequest) {
5465
String endpoint = new RequestConverters.EndpointBuilder()
5566
.addPathPart(unfollowRequest.getFollowerIndex())
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.client.ccr;
21+
22+
import org.elasticsearch.common.ParseField;
23+
import org.elasticsearch.common.unit.ByteSizeValue;
24+
import org.elasticsearch.common.unit.TimeValue;
25+
import org.elasticsearch.common.xcontent.ToXContent;
26+
import org.elasticsearch.common.xcontent.XContentBuilder;
27+
28+
import java.io.IOException;
29+
import java.util.Objects;
30+
31+
public class FollowConfig {
32+
33+
static final ParseField MAX_READ_REQUEST_OPERATION_COUNT = new ParseField("max_read_request_operation_count");
34+
static final ParseField MAX_READ_REQUEST_SIZE = new ParseField("max_read_request_size");
35+
static final ParseField MAX_OUTSTANDING_READ_REQUESTS = new ParseField("max_outstanding_read_requests");
36+
static final ParseField MAX_WRITE_REQUEST_OPERATION_COUNT = new ParseField("max_write_request_operation_count");
37+
static final ParseField MAX_WRITE_REQUEST_SIZE = new ParseField("max_write_request_size");
38+
static final ParseField MAX_OUTSTANDING_WRITE_REQUESTS = new ParseField("max_outstanding_write_requests");
39+
static final ParseField MAX_WRITE_BUFFER_COUNT = new ParseField("max_write_buffer_count");
40+
static final ParseField MAX_WRITE_BUFFER_SIZE = new ParseField("max_write_buffer_size");
41+
static final ParseField MAX_RETRY_DELAY_FIELD = new ParseField("max_retry_delay");
42+
static final ParseField READ_POLL_TIMEOUT = new ParseField("read_poll_timeout");
43+
44+
private Integer maxReadRequestOperationCount;
45+
private Integer maxOutstandingReadRequests;
46+
private ByteSizeValue maxReadRequestSize;
47+
private Integer maxWriteRequestOperationCount;
48+
private ByteSizeValue maxWriteRequestSize;
49+
private Integer maxOutstandingWriteRequests;
50+
private Integer maxWriteBufferCount;
51+
private ByteSizeValue maxWriteBufferSize;
52+
private TimeValue maxRetryDelay;
53+
private TimeValue readPollTimeout;
54+
55+
FollowConfig() {
56+
}
57+
58+
public Integer getMaxReadRequestOperationCount() {
59+
return maxReadRequestOperationCount;
60+
}
61+
62+
public void setMaxReadRequestOperationCount(Integer maxReadRequestOperationCount) {
63+
this.maxReadRequestOperationCount = maxReadRequestOperationCount;
64+
}
65+
66+
public Integer getMaxOutstandingReadRequests() {
67+
return maxOutstandingReadRequests;
68+
}
69+
70+
public void setMaxOutstandingReadRequests(Integer maxOutstandingReadRequests) {
71+
this.maxOutstandingReadRequests = maxOutstandingReadRequests;
72+
}
73+
74+
public ByteSizeValue getMaxReadRequestSize() {
75+
return maxReadRequestSize;
76+
}
77+
78+
public void setMaxReadRequestSize(ByteSizeValue maxReadRequestSize) {
79+
this.maxReadRequestSize = maxReadRequestSize;
80+
}
81+
82+
public Integer getMaxWriteRequestOperationCount() {
83+
return maxWriteRequestOperationCount;
84+
}
85+
86+
public void setMaxWriteRequestOperationCount(Integer maxWriteRequestOperationCount) {
87+
this.maxWriteRequestOperationCount = maxWriteRequestOperationCount;
88+
}
89+
90+
public ByteSizeValue getMaxWriteRequestSize() {
91+
return maxWriteRequestSize;
92+
}
93+
94+
public void setMaxWriteRequestSize(ByteSizeValue maxWriteRequestSize) {
95+
this.maxWriteRequestSize = maxWriteRequestSize;
96+
}
97+
98+
public Integer getMaxOutstandingWriteRequests() {
99+
return maxOutstandingWriteRequests;
100+
}
101+
102+
public void setMaxOutstandingWriteRequests(Integer maxOutstandingWriteRequests) {
103+
this.maxOutstandingWriteRequests = maxOutstandingWriteRequests;
104+
}
105+
106+
public Integer getMaxWriteBufferCount() {
107+
return maxWriteBufferCount;
108+
}
109+
110+
public void setMaxWriteBufferCount(Integer maxWriteBufferCount) {
111+
this.maxWriteBufferCount = maxWriteBufferCount;
112+
}
113+
114+
public ByteSizeValue getMaxWriteBufferSize() {
115+
return maxWriteBufferSize;
116+
}
117+
118+
public void setMaxWriteBufferSize(ByteSizeValue maxWriteBufferSize) {
119+
this.maxWriteBufferSize = maxWriteBufferSize;
120+
}
121+
122+
public TimeValue getMaxRetryDelay() {
123+
return maxRetryDelay;
124+
}
125+
126+
public void setMaxRetryDelay(TimeValue maxRetryDelay) {
127+
this.maxRetryDelay = maxRetryDelay;
128+
}
129+
130+
public TimeValue getReadPollTimeout() {
131+
return readPollTimeout;
132+
}
133+
134+
public void setReadPollTimeout(TimeValue readPollTimeout) {
135+
this.readPollTimeout = readPollTimeout;
136+
}
137+
138+
void toXContentFragment(XContentBuilder builder, ToXContent.Params params) throws IOException {
139+
if (maxReadRequestOperationCount != null) {
140+
builder.field(MAX_READ_REQUEST_OPERATION_COUNT.getPreferredName(), maxReadRequestOperationCount);
141+
}
142+
if (maxReadRequestSize != null) {
143+
builder.field(MAX_READ_REQUEST_SIZE.getPreferredName(), maxReadRequestSize.getStringRep());
144+
}
145+
if (maxWriteRequestOperationCount != null) {
146+
builder.field(MAX_WRITE_REQUEST_OPERATION_COUNT.getPreferredName(), maxWriteRequestOperationCount);
147+
}
148+
if (maxWriteRequestSize != null) {
149+
builder.field(MAX_WRITE_REQUEST_SIZE.getPreferredName(), maxWriteRequestSize.getStringRep());
150+
}
151+
if (maxWriteBufferCount != null) {
152+
builder.field(MAX_WRITE_BUFFER_COUNT.getPreferredName(), maxWriteBufferCount);
153+
}
154+
if (maxWriteBufferSize != null) {
155+
builder.field(MAX_WRITE_BUFFER_SIZE.getPreferredName(), maxWriteBufferSize.getStringRep());
156+
}
157+
if (maxOutstandingReadRequests != null) {
158+
builder.field(MAX_OUTSTANDING_READ_REQUESTS.getPreferredName(), maxOutstandingReadRequests);
159+
}
160+
if (maxOutstandingWriteRequests != null) {
161+
builder.field(MAX_OUTSTANDING_WRITE_REQUESTS.getPreferredName(), maxOutstandingWriteRequests);
162+
}
163+
if (maxRetryDelay != null) {
164+
builder.field(MAX_RETRY_DELAY_FIELD.getPreferredName(), maxRetryDelay.getStringRep());
165+
}
166+
if (readPollTimeout != null) {
167+
builder.field(READ_POLL_TIMEOUT.getPreferredName(), readPollTimeout.getStringRep());
168+
}
169+
}
170+
171+
@Override
172+
public boolean equals(Object o) {
173+
if (this == o) return true;
174+
if (o == null || getClass() != o.getClass()) return false;
175+
FollowConfig that = (FollowConfig) o;
176+
return Objects.equals(maxReadRequestOperationCount, that.maxReadRequestOperationCount) &&
177+
Objects.equals(maxOutstandingReadRequests, that.maxOutstandingReadRequests) &&
178+
Objects.equals(maxReadRequestSize, that.maxReadRequestSize) &&
179+
Objects.equals(maxWriteRequestOperationCount, that.maxWriteRequestOperationCount) &&
180+
Objects.equals(maxWriteRequestSize, that.maxWriteRequestSize) &&
181+
Objects.equals(maxOutstandingWriteRequests, that.maxOutstandingWriteRequests) &&
182+
Objects.equals(maxWriteBufferCount, that.maxWriteBufferCount) &&
183+
Objects.equals(maxWriteBufferSize, that.maxWriteBufferSize) &&
184+
Objects.equals(maxRetryDelay, that.maxRetryDelay) &&
185+
Objects.equals(readPollTimeout, that.readPollTimeout);
186+
}
187+
188+
@Override
189+
public int hashCode() {
190+
return Objects.hash(
191+
maxReadRequestOperationCount,
192+
maxOutstandingReadRequests,
193+
maxReadRequestSize,
194+
maxWriteRequestOperationCount,
195+
maxWriteRequestSize,
196+
maxOutstandingWriteRequests,
197+
maxWriteBufferCount,
198+
maxWriteBufferSize,
199+
maxRetryDelay,
200+
readPollTimeout
201+
);
202+
}
203+
}

0 commit comments

Comments
 (0)