2323import java .io .IOException ;
2424import java .util .Objects ;
2525
26+ import static org .elasticsearch .action .ValidateActions .addValidationError ;
27+
2628public final class FollowIndexAction extends Action <AcknowledgedResponse > {
2729
2830 public static final FollowIndexAction INSTANCE = new FollowIndexAction ();
@@ -33,8 +35,9 @@ public final class FollowIndexAction extends Action<AcknowledgedResponse> {
3335 public static final int DEFAULT_MAX_CONCURRENT_READ_BATCHES = 1 ;
3436 public static final int DEFAULT_MAX_CONCURRENT_WRITE_BATCHES = 1 ;
3537 public static final long DEFAULT_MAX_BATCH_SIZE_IN_BYTES = Long .MAX_VALUE ;
36- public static final TimeValue DEFAULT_RETRY_TIMEOUT = new TimeValue (500 );
37- public static final TimeValue DEFAULT_IDLE_SHARD_RETRY_DELAY = TimeValue .timeValueSeconds (10 );
38+ static final TimeValue DEFAULT_MAX_RETRY_DELAY = new TimeValue (500 );
39+ static final TimeValue DEFAULT_IDLE_SHARD_RETRY_DELAY = TimeValue .timeValueSeconds (10 );
40+ static final TimeValue MAX_RETRY_DELAY = TimeValue .timeValueMinutes (5 );
3841
3942 private FollowIndexAction () {
4043 super (NAME );
@@ -54,7 +57,7 @@ public static class Request extends ActionRequest implements ToXContentObject {
5457 private static final ParseField MAX_BATCH_SIZE_IN_BYTES = new ParseField ("max_batch_size_in_bytes" );
5558 private static final ParseField MAX_CONCURRENT_WRITE_BATCHES = new ParseField ("max_concurrent_write_batches" );
5659 private static final ParseField MAX_WRITE_BUFFER_SIZE = new ParseField ("max_write_buffer_size" );
57- private static final ParseField MAX_RETRY_DELAY = new ParseField ("max_retry_delay" );
60+ private static final ParseField MAX_RETRY_DELAY_FIELD = new ParseField ("max_retry_delay" );
5861 private static final ParseField IDLE_SHARD_RETRY_DELAY = new ParseField ("idle_shard_retry_delay" );
5962 private static final ConstructingObjectParser <Request , String > PARSER = new ConstructingObjectParser <>(NAME , true ,
6063 (args , followerIndex ) -> {
@@ -75,8 +78,8 @@ public static class Request extends ActionRequest implements ToXContentObject {
7578 PARSER .declareInt (ConstructingObjectParser .optionalConstructorArg (), MAX_WRITE_BUFFER_SIZE );
7679 PARSER .declareField (
7780 ConstructingObjectParser .optionalConstructorArg (),
78- (p , c ) -> TimeValue .parseTimeValue (p .text (), MAX_RETRY_DELAY .getPreferredName ()),
79- MAX_RETRY_DELAY ,
81+ (p , c ) -> TimeValue .parseTimeValue (p .text (), MAX_RETRY_DELAY_FIELD .getPreferredName ()),
82+ MAX_RETRY_DELAY_FIELD ,
8083 ObjectParser .ValueType .STRING );
8184 PARSER .declareField (
8285 ConstructingObjectParser .optionalConstructorArg (),
@@ -202,7 +205,7 @@ public Request(
202205 throw new IllegalArgumentException (MAX_WRITE_BUFFER_SIZE .getPreferredName () + " must be larger than 0" );
203206 }
204207
205- final TimeValue actualRetryTimeout = maxRetryDelay == null ? DEFAULT_RETRY_TIMEOUT : maxRetryDelay ;
208+ final TimeValue actualRetryTimeout = maxRetryDelay == null ? DEFAULT_MAX_RETRY_DELAY : maxRetryDelay ;
206209 final TimeValue actualIdleShardRetryDelay = idleShardRetryDelay == null ? DEFAULT_IDLE_SHARD_RETRY_DELAY : idleShardRetryDelay ;
207210
208211 this .leaderIndex = leaderIndex ;
@@ -222,7 +225,20 @@ public Request() {
222225
223226 @ Override
224227 public ActionRequestValidationException validate () {
225- return null ;
228+ ActionRequestValidationException validationException = null ;
229+
230+ if (maxRetryDelay .millis () <= 0 ) {
231+ String message = "[" + MAX_RETRY_DELAY_FIELD .getPreferredName () + "] must be positive but was [" +
232+ maxRetryDelay .getStringRep () + "]" ;
233+ validationException = addValidationError (message , validationException );
234+ }
235+ if (maxRetryDelay .millis () > FollowIndexAction .MAX_RETRY_DELAY .millis ()) {
236+ String message = "[" + MAX_RETRY_DELAY_FIELD .getPreferredName () + "] must be less than [" + MAX_RETRY_DELAY +
237+ "] but was [" + maxRetryDelay .getStringRep () + "]" ;
238+ validationException = addValidationError (message , validationException );
239+ }
240+
241+ return validationException ;
226242 }
227243
228244 @ Override
@@ -264,7 +280,7 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa
264280 builder .field (MAX_WRITE_BUFFER_SIZE .getPreferredName (), maxWriteBufferSize );
265281 builder .field (MAX_CONCURRENT_READ_BATCHES .getPreferredName (), maxConcurrentReadBatches );
266282 builder .field (MAX_CONCURRENT_WRITE_BATCHES .getPreferredName (), maxConcurrentWriteBatches );
267- builder .field (MAX_RETRY_DELAY .getPreferredName (), maxRetryDelay .getStringRep ());
283+ builder .field (MAX_RETRY_DELAY_FIELD .getPreferredName (), maxRetryDelay .getStringRep ());
268284 builder .field (IDLE_SHARD_RETRY_DELAY .getPreferredName (), idleShardRetryDelay .getStringRep ());
269285 }
270286 builder .endObject ();
0 commit comments