2525import java .io .IOException ;
2626import java .util .Objects ;
2727
28+ import static org .elasticsearch .action .ValidateActions .addValidationError ;
29+
2830public final class FollowIndexAction extends Action <
2931 FollowIndexAction .Request ,
3032 AcknowledgedResponse ,
@@ -38,8 +40,9 @@ public final class FollowIndexAction extends Action<
3840 public static final int DEFAULT_MAX_CONCURRENT_READ_BATCHES = 1 ;
3941 public static final int DEFAULT_MAX_CONCURRENT_WRITE_BATCHES = 1 ;
4042 public static final long DEFAULT_MAX_BATCH_SIZE_IN_BYTES = Long .MAX_VALUE ;
41- public static final TimeValue DEFAULT_RETRY_TIMEOUT = new TimeValue (500 );
42- public static final TimeValue DEFAULT_IDLE_SHARD_RETRY_DELAY = TimeValue .timeValueSeconds (10 );
43+ static final TimeValue DEFAULT_MAX_RETRY_DELAY = new TimeValue (500 );
44+ static final TimeValue DEFAULT_IDLE_SHARD_RETRY_DELAY = TimeValue .timeValueSeconds (10 );
45+ static final TimeValue MAX_RETRY_DELAY = TimeValue .timeValueMinutes (5 );
4346
4447 private FollowIndexAction () {
4548 super (NAME );
@@ -59,7 +62,7 @@ public static class Request extends ActionRequest implements ToXContentObject {
5962 private static final ParseField MAX_BATCH_SIZE_IN_BYTES = new ParseField ("max_batch_size_in_bytes" );
6063 private static final ParseField MAX_CONCURRENT_WRITE_BATCHES = new ParseField ("max_concurrent_write_batches" );
6164 private static final ParseField MAX_WRITE_BUFFER_SIZE = new ParseField ("max_write_buffer_size" );
62- private static final ParseField MAX_RETRY_DELAY = new ParseField ("max_retry_delay" );
65+ private static final ParseField MAX_RETRY_DELAY_FIELD = new ParseField ("max_retry_delay" );
6366 private static final ParseField IDLE_SHARD_RETRY_DELAY = new ParseField ("idle_shard_retry_delay" );
6467 private static final ConstructingObjectParser <Request , String > PARSER = new ConstructingObjectParser <>(NAME , true ,
6568 (args , followerIndex ) -> {
@@ -80,8 +83,8 @@ public static class Request extends ActionRequest implements ToXContentObject {
8083 PARSER .declareInt (ConstructingObjectParser .optionalConstructorArg (), MAX_WRITE_BUFFER_SIZE );
8184 PARSER .declareField (
8285 ConstructingObjectParser .optionalConstructorArg (),
83- (p , c ) -> TimeValue .parseTimeValue (p .text (), MAX_RETRY_DELAY .getPreferredName ()),
84- MAX_RETRY_DELAY ,
86+ (p , c ) -> TimeValue .parseTimeValue (p .text (), MAX_RETRY_DELAY_FIELD .getPreferredName ()),
87+ MAX_RETRY_DELAY_FIELD ,
8588 ObjectParser .ValueType .STRING );
8689 PARSER .declareField (
8790 ConstructingObjectParser .optionalConstructorArg (),
@@ -207,7 +210,7 @@ public Request(
207210 throw new IllegalArgumentException (MAX_WRITE_BUFFER_SIZE .getPreferredName () + " must be larger than 0" );
208211 }
209212
210- final TimeValue actualRetryTimeout = maxRetryDelay == null ? DEFAULT_RETRY_TIMEOUT : maxRetryDelay ;
213+ final TimeValue actualRetryTimeout = maxRetryDelay == null ? DEFAULT_MAX_RETRY_DELAY : maxRetryDelay ;
211214 final TimeValue actualIdleShardRetryDelay = idleShardRetryDelay == null ? DEFAULT_IDLE_SHARD_RETRY_DELAY : idleShardRetryDelay ;
212215
213216 this .leaderIndex = leaderIndex ;
@@ -227,7 +230,20 @@ public Request() {
227230
228231 @ Override
229232 public ActionRequestValidationException validate () {
230- return null ;
233+ ActionRequestValidationException validationException = null ;
234+
235+ if (maxRetryDelay .millis () <= 0 ) {
236+ String message = "[" + MAX_RETRY_DELAY_FIELD .getPreferredName () + "] must be positive but was [" +
237+ maxRetryDelay .getStringRep () + "]" ;
238+ validationException = addValidationError (message , validationException );
239+ }
240+ if (maxRetryDelay .millis () > FollowIndexAction .MAX_RETRY_DELAY .millis ()) {
241+ String message = "[" + MAX_RETRY_DELAY_FIELD .getPreferredName () + "] must be less than [" + MAX_RETRY_DELAY +
242+ "] but was [" + maxRetryDelay .getStringRep () + "]" ;
243+ validationException = addValidationError (message , validationException );
244+ }
245+
246+ return validationException ;
231247 }
232248
233249 @ Override
@@ -269,7 +285,7 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa
269285 builder .field (MAX_WRITE_BUFFER_SIZE .getPreferredName (), maxWriteBufferSize );
270286 builder .field (MAX_CONCURRENT_READ_BATCHES .getPreferredName (), maxConcurrentReadBatches );
271287 builder .field (MAX_CONCURRENT_WRITE_BATCHES .getPreferredName (), maxConcurrentWriteBatches );
272- builder .field (MAX_RETRY_DELAY .getPreferredName (), maxRetryDelay .getStringRep ());
288+ builder .field (MAX_RETRY_DELAY_FIELD .getPreferredName (), maxRetryDelay .getStringRep ());
273289 builder .field (IDLE_SHARD_RETRY_DELAY .getPreferredName (), idleShardRetryDelay .getStringRep ());
274290 }
275291 builder .endObject ();
0 commit comments