6
6
package org.opensearch.indexmanagement.spi.indexstatemanagement.model
7
7
8
8
import org.apache.logging.log4j.LogManager
9
+ import org.opensearch.common.unit.TimeValue
9
10
import org.opensearch.core.common.io.stream.StreamInput
10
11
import org.opensearch.core.common.io.stream.StreamOutput
11
12
import org.opensearch.core.common.io.stream.Writeable
12
- import org.opensearch.common.unit.TimeValue
13
13
import org.opensearch.core.xcontent.ToXContent
14
14
import org.opensearch.core.xcontent.ToXContentFragment
15
15
import org.opensearch.core.xcontent.XContentBuilder
@@ -23,10 +23,11 @@ import kotlin.math.pow
23
23
data class ActionRetry (
24
24
val count : Long ,
25
25
val backoff : Backoff = Backoff .EXPONENTIAL ,
26
- val delay : TimeValue = TimeValue .timeValueMinutes(1)
26
+ val delay : TimeValue = TimeValue .timeValueMinutes(1),
27
27
) : ToXContentFragment, Writeable {
28
-
29
- init { require(count >= 0 ) { " Count for ActionRetry must be a non-negative number" } }
28
+ init {
29
+ require(count >= 0 ) { " Count for ActionRetry must be a non-negative number" }
30
+ }
30
31
31
32
override fun toXContent (builder : XContentBuilder , params : ToXContent .Params ): XContentBuilder {
32
33
builder
@@ -42,7 +43,7 @@ data class ActionRetry(
42
43
constructor (sin: StreamInput ) : this (
43
44
count = sin.readLong(),
44
45
backoff = sin.readEnum(Backoff ::class .java),
45
- delay = sin.readTimeValue()
46
+ delay = sin.readTimeValue(),
46
47
)
47
48
48
49
@Throws(IOException ::class )
@@ -80,7 +81,7 @@ data class ActionRetry(
80
81
return ActionRetry (
81
82
count = requireNotNull(count) { " ActionRetry count is null" },
82
83
backoff = backoff,
83
- delay = delay
84
+ delay = delay,
84
85
)
85
86
}
86
87
}
@@ -90,20 +91,21 @@ data class ActionRetry(
90
91
" exponential" ,
91
92
{ consumedRetries, timeValue ->
92
93
(2.0 .pow(consumedRetries - 1 )).toLong() * timeValue.millis
93
- }
94
+ },
94
95
),
95
96
CONSTANT (
96
97
" constant" ,
97
98
{ _, timeValue ->
98
99
timeValue.millis
99
- }
100
+ },
100
101
),
101
102
LINEAR (
102
103
" linear" ,
103
104
{ consumedRetries, timeValue ->
104
105
consumedRetries * timeValue.millis
105
- }
106
- );
106
+ },
107
+ ),
108
+ ;
107
109
108
110
private val logger = LogManager .getLogger(javaClass)
109
111
@@ -120,8 +122,9 @@ data class ActionRetry(
120
122
121
123
if (actionMetaData.consumedRetries > 0 ) {
122
124
if (actionMetaData.lastRetryTime != null ) {
123
- val remainingTime = getNextRetryTime(actionMetaData.consumedRetries, actionRetry.delay) -
124
- (Instant .now().toEpochMilli() - actionMetaData.lastRetryTime)
125
+ val remainingTime =
126
+ getNextRetryTime(actionMetaData.consumedRetries, actionRetry.delay) -
127
+ (Instant .now().toEpochMilli() - actionMetaData.lastRetryTime)
125
128
126
129
return Pair (remainingTime > 0 , remainingTime)
127
130
}
0 commit comments