Skip to content

Commit 9adc3b9

Browse files
authored
OAK-11466 Replace Fixed to Exponential retries in oak-segment-azure (#2067)
* OAK-11466 Replace Fixed to Exponential retries in oak-segment-azure * OAK-11466 Replace Fixed to Exponential retries in oak-segment-azure * OAK-11466 Replace Fixed to Exponential retries in oak-segment-azure
1 parent 5fee417 commit 9adc3b9

File tree

1 file changed

+52
-14
lines changed

1 file changed

+52
-14
lines changed

oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/util/AzureRequestOptions.java

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,32 @@
2121

2222
import com.azure.storage.common.policy.RequestRetryOptions;
2323
import com.azure.storage.common.policy.RetryPolicyType;
24+
import org.slf4j.Logger;
25+
import org.slf4j.LoggerFactory;
2426

2527
public class AzureRequestOptions {
28+
private static final Logger log = LoggerFactory.getLogger(AzureRequestOptions.class);
29+
30+
static final String RETRY_POLICY_TYPE_PROP = "segment.retry.policy.type";
31+
static final String RETRY_POLICY_TYPE_DEFAULT = "fixed";
2632

2733
static final String RETRY_ATTEMPTS_PROP = "segment.azure.retry.attempts";
2834
static final int DEFAULT_RETRY_ATTEMPTS = 5;
2935

30-
static final String RETRY_BACKOFF_PROP = "segment.azure.retry.backoff";
31-
static final int DEFAULT_RETRY_BACKOFF_SECONDS = 5;
36+
static final String TIMEOUT_EXECUTION_PROP = "segment.timeout.execution";
37+
static final int DEFAULT_TIMEOUT_EXECUTION = 30;
38+
39+
static final String RETRY_DELAY_MIN_PROP = "segment.retry.delay.min";
40+
static final int DEFAULT_RETRY_DELAY_MIN = 100;
41+
42+
static final String RETRY_DELAY_MAX_PROP = "segment.retry.delay.max";
43+
static final int DEFAULT_RETRY_DELAY_MAX = 5000;
44+
45+
static final String WRITE_TIMEOUT_EXECUTION_PROP = "segment.write.timeout.execution";
3246

33-
static final String TIMEOUT_INTERVAL_PROP = "segment.timeout.interval";
34-
static final int DEFAULT_TIMEOUT_INTERVAL = 1;
47+
static final String WRITE_RETRY_DELAY_MIN_PROP = "segment.write.retry.delay.min";
3548

36-
static final String WRITE_TIMEOUT_INTERVAL_PROP = "segment.write.timeout.interval";
49+
static final String WRITE_RETRY_DELAY_MAX_PROP = "segment.write.retry.delay.max";
3750

3851
private AzureRequestOptions() {
3952
}
@@ -44,12 +57,15 @@ public static RequestRetryOptions getRetryOptionsDefault() {
4457
}
4558

4659
public static RequestRetryOptions getRetryOptionsDefault(String secondaryHost) {
60+
RetryPolicyType retryPolicyType = getRetryPolicyType();
4761
int maxTries = Integer.getInteger(RETRY_ATTEMPTS_PROP, DEFAULT_RETRY_ATTEMPTS);
4862
int tryTimeoutInSeconds = getReadTryTimeoutInSeconds();
49-
long retryDelayInMs = Integer.getInteger(RETRY_BACKOFF_PROP, DEFAULT_RETRY_BACKOFF_SECONDS) * 1_000L;
50-
long maxRetryDelayInMs = retryDelayInMs;
63+
long retryDelayInMs = getRetryDelayInMs();
64+
long maxRetryDelayInMs = getMaxRetryDelayInMs();
5165

52-
return new RequestRetryOptions(RetryPolicyType.FIXED,
66+
log.info("Azure retry policy type set to: {}", retryPolicyType);
67+
68+
return new RequestRetryOptions(retryPolicyType,
5369
maxTries,
5470
tryTimeoutInSeconds,
5571
retryDelayInMs,
@@ -59,16 +75,20 @@ public static RequestRetryOptions getRetryOptionsDefault(String secondaryHost) {
5975

6076
/**
6177
* secondaryHost is null because there is no writer in secondary
78+
*
6279
* @return
6380
*/
6481
public static RequestRetryOptions getRetryOperationsOptimiseForWriteOperations() {
82+
RetryPolicyType retryPolicyType = getRetryPolicyType();
6583
int maxTries = Integer.getInteger(RETRY_ATTEMPTS_PROP, DEFAULT_RETRY_ATTEMPTS);
66-
// if the value for write is not set use the read value
67-
int tryTimeoutInSeconds = Integer.getInteger(WRITE_TIMEOUT_INTERVAL_PROP, getReadTryTimeoutInSeconds());
68-
long retryDelayInMs = Integer.getInteger(WRITE_TIMEOUT_INTERVAL_PROP, DEFAULT_RETRY_BACKOFF_SECONDS) * 1_000L;
69-
long maxRetryDelayInMs = retryDelayInMs;
84+
// if the value for write are not set use the read value
85+
int tryTimeoutInSeconds = Integer.getInteger(WRITE_TIMEOUT_EXECUTION_PROP, getReadTryTimeoutInSeconds());
86+
long retryDelayInMs = Integer.getInteger(WRITE_RETRY_DELAY_MIN_PROP, getRetryDelayInMs());
87+
long maxRetryDelayInMs = Integer.getInteger(WRITE_RETRY_DELAY_MAX_PROP, getMaxRetryDelayInMs());
88+
89+
log.info("Azure write retry policy type set to: {}", retryPolicyType);
7090

71-
return new RequestRetryOptions(RetryPolicyType.FIXED,
91+
return new RequestRetryOptions(retryPolicyType,
7292
maxTries,
7393
tryTimeoutInSeconds,
7494
retryDelayInMs,
@@ -77,7 +97,25 @@ public static RequestRetryOptions getRetryOperationsOptimiseForWriteOperations()
7797
}
7898

7999
private static int getReadTryTimeoutInSeconds() {
80-
return Integer.getInteger(TIMEOUT_INTERVAL_PROP, DEFAULT_TIMEOUT_INTERVAL);
100+
return Integer.getInteger(TIMEOUT_EXECUTION_PROP, DEFAULT_TIMEOUT_EXECUTION);
101+
}
102+
103+
private static int getRetryDelayInMs() {
104+
return Integer.getInteger(RETRY_DELAY_MIN_PROP, DEFAULT_RETRY_DELAY_MIN);
105+
}
106+
107+
private static int getMaxRetryDelayInMs() {
108+
return Integer.getInteger(RETRY_DELAY_MAX_PROP, DEFAULT_RETRY_DELAY_MAX);
109+
}
110+
111+
private static RetryPolicyType getRetryPolicyType() {
112+
String envRetryPolicyType = System.getProperty(RETRY_POLICY_TYPE_PROP, RETRY_POLICY_TYPE_DEFAULT).toUpperCase();
113+
114+
try {
115+
return RetryPolicyType.valueOf(envRetryPolicyType);
116+
} catch (IllegalArgumentException e) {
117+
throw new IllegalArgumentException(String.format("Retry policy '%s' not supported. Please use FIXED or EXPONENTIAL", envRetryPolicyType), e);
118+
}
81119
}
82120

83121
}

0 commit comments

Comments
 (0)