This is an automated email from the ASF dual-hosted git repository.

miroslav pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 9adc3b9a56 OAK-11466 Replace Fixed to Exponential retries in 
oak-segment-azure (#2067)
9adc3b9a56 is described below

commit 9adc3b9a56a1d700ae3bfe409a95c989b867bba8
Author: Ieran Bogdan <[email protected]>
AuthorDate: Fri Feb 21 18:47:55 2025 +0200

    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
---
 .../segment/azure/util/AzureRequestOptions.java    | 66 +++++++++++++++++-----
 1 file changed, 52 insertions(+), 14 deletions(-)

diff --git 
a/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/util/AzureRequestOptions.java
 
b/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/util/AzureRequestOptions.java
index 14a3542468..3bc105f009 100644
--- 
a/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/util/AzureRequestOptions.java
+++ 
b/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/util/AzureRequestOptions.java
@@ -21,19 +21,32 @@ package org.apache.jackrabbit.oak.segment.azure.util;
 
 import com.azure.storage.common.policy.RequestRetryOptions;
 import com.azure.storage.common.policy.RetryPolicyType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class AzureRequestOptions {
+    private static final Logger log = 
LoggerFactory.getLogger(AzureRequestOptions.class);
+
+    static final String RETRY_POLICY_TYPE_PROP = "segment.retry.policy.type";
+    static final String RETRY_POLICY_TYPE_DEFAULT = "fixed";
 
     static final String RETRY_ATTEMPTS_PROP = "segment.azure.retry.attempts";
     static final int DEFAULT_RETRY_ATTEMPTS = 5;
 
-    static final String RETRY_BACKOFF_PROP = "segment.azure.retry.backoff";
-    static final int DEFAULT_RETRY_BACKOFF_SECONDS = 5;
+    static final String TIMEOUT_EXECUTION_PROP = "segment.timeout.execution";
+    static final int DEFAULT_TIMEOUT_EXECUTION = 30;
+
+    static final String RETRY_DELAY_MIN_PROP = "segment.retry.delay.min";
+    static final int DEFAULT_RETRY_DELAY_MIN = 100;
+
+    static final String RETRY_DELAY_MAX_PROP = "segment.retry.delay.max";
+    static final int DEFAULT_RETRY_DELAY_MAX = 5000;
+
+    static final String WRITE_TIMEOUT_EXECUTION_PROP = 
"segment.write.timeout.execution";
 
-    static final String TIMEOUT_INTERVAL_PROP = "segment.timeout.interval";
-    static final int DEFAULT_TIMEOUT_INTERVAL = 1;
+    static final String WRITE_RETRY_DELAY_MIN_PROP = 
"segment.write.retry.delay.min";
 
-    static final String WRITE_TIMEOUT_INTERVAL_PROP = 
"segment.write.timeout.interval";
+    static final String WRITE_RETRY_DELAY_MAX_PROP = 
"segment.write.retry.delay.max";
 
     private AzureRequestOptions() {
     }
@@ -44,12 +57,15 @@ public class AzureRequestOptions {
     }
 
     public static RequestRetryOptions getRetryOptionsDefault(String 
secondaryHost) {
+        RetryPolicyType retryPolicyType = getRetryPolicyType();
         int maxTries = Integer.getInteger(RETRY_ATTEMPTS_PROP, 
DEFAULT_RETRY_ATTEMPTS);
         int tryTimeoutInSeconds = getReadTryTimeoutInSeconds();
-        long retryDelayInMs = Integer.getInteger(RETRY_BACKOFF_PROP, 
DEFAULT_RETRY_BACKOFF_SECONDS) * 1_000L;
-        long maxRetryDelayInMs = retryDelayInMs;
+        long retryDelayInMs = getRetryDelayInMs();
+        long maxRetryDelayInMs = getMaxRetryDelayInMs();
 
-        return new RequestRetryOptions(RetryPolicyType.FIXED,
+        log.info("Azure retry policy type set to: {}", retryPolicyType);
+
+        return new RequestRetryOptions(retryPolicyType,
                 maxTries,
                 tryTimeoutInSeconds,
                 retryDelayInMs,
@@ -59,16 +75,20 @@ public class AzureRequestOptions {
 
     /**
      * secondaryHost is null because there is no writer in secondary
+     *
      * @return
      */
     public static RequestRetryOptions 
getRetryOperationsOptimiseForWriteOperations() {
+        RetryPolicyType retryPolicyType = getRetryPolicyType();
         int maxTries = Integer.getInteger(RETRY_ATTEMPTS_PROP, 
DEFAULT_RETRY_ATTEMPTS);
-        // if the value for write is not set use the read value
-        int tryTimeoutInSeconds = 
Integer.getInteger(WRITE_TIMEOUT_INTERVAL_PROP, getReadTryTimeoutInSeconds());
-        long retryDelayInMs = Integer.getInteger(WRITE_TIMEOUT_INTERVAL_PROP, 
DEFAULT_RETRY_BACKOFF_SECONDS) * 1_000L;
-        long maxRetryDelayInMs = retryDelayInMs;
+        // if the value for write are not set use the read value
+        int tryTimeoutInSeconds = 
Integer.getInteger(WRITE_TIMEOUT_EXECUTION_PROP, getReadTryTimeoutInSeconds());
+        long retryDelayInMs = Integer.getInteger(WRITE_RETRY_DELAY_MIN_PROP, 
getRetryDelayInMs());
+        long maxRetryDelayInMs = 
Integer.getInteger(WRITE_RETRY_DELAY_MAX_PROP, getMaxRetryDelayInMs());
+
+        log.info("Azure write retry policy type set to: {}", retryPolicyType);
 
-        return new RequestRetryOptions(RetryPolicyType.FIXED,
+        return new RequestRetryOptions(retryPolicyType,
                 maxTries,
                 tryTimeoutInSeconds,
                 retryDelayInMs,
@@ -77,7 +97,25 @@ public class AzureRequestOptions {
     }
 
     private static int getReadTryTimeoutInSeconds() {
-        return Integer.getInteger(TIMEOUT_INTERVAL_PROP, 
DEFAULT_TIMEOUT_INTERVAL);
+        return Integer.getInteger(TIMEOUT_EXECUTION_PROP, 
DEFAULT_TIMEOUT_EXECUTION);
+    }
+
+    private static int getRetryDelayInMs() {
+        return Integer.getInteger(RETRY_DELAY_MIN_PROP, 
DEFAULT_RETRY_DELAY_MIN);
+    }
+
+    private static int getMaxRetryDelayInMs() {
+        return Integer.getInteger(RETRY_DELAY_MAX_PROP, 
DEFAULT_RETRY_DELAY_MAX);
+    }
+
+    private static RetryPolicyType getRetryPolicyType() {
+        String envRetryPolicyType = System.getProperty(RETRY_POLICY_TYPE_PROP, 
RETRY_POLICY_TYPE_DEFAULT).toUpperCase();
+
+        try {
+            return RetryPolicyType.valueOf(envRetryPolicyType);
+        } catch (IllegalArgumentException e) {
+            throw new IllegalArgumentException(String.format("Retry policy 
'%s' not supported. Please use FIXED or EXPONENTIAL", envRetryPolicyType), e);
+        }
     }
 
 }
\ No newline at end of file

Reply via email to