You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by mi...@apache.org on 2023/11/30 10:20:34 UTC
(jackrabbit-oak) branch issue/OAK-10573_azure_write_timeout updated: OAK-10573 introduce AzureRequestOptions util class
This is an automated email from the ASF dual-hosted git repository.
miroslav pushed a commit to branch issue/OAK-10573_azure_write_timeout
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
The following commit(s) were added to refs/heads/issue/OAK-10573_azure_write_timeout by this push:
new 477613d076 OAK-10573 introduce AzureRequestOptions util class
477613d076 is described below
commit 477613d0766b0af23b55c138d05a6e67a69b03a5
Author: Miroslav Smiljanic <mi...@apache.com>
AuthorDate: Thu Nov 30 11:20:15 2023 +0100
OAK-10573 introduce AzureRequestOptions util class
---
.../segment/azure/util/AzureRequestOptions.java | 35 ++++++++-----
.../azure/util/AzureRequestOptionsTest.java | 59 ++++++++++++++++++++++
2 files changed, 82 insertions(+), 12 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 485612371d..9a6ffbfb3f 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
@@ -7,22 +7,26 @@ import java.util.concurrent.TimeUnit;
public class AzureRequestOptions {
- private static final String RETRY_ATTEMPTS_PROP = "segment.azure.retry.attempts";
- private static final int DEFAULT_RETRY_ATTEMPTS = 5;
+ static final String RETRY_ATTEMPTS_PROP = "segment.azure.retry.attempts";
+ static final int DEFAULT_RETRY_ATTEMPTS = 5;
- private static final String RETRY_BACKOFF_PROP = "segment.azure.retry.backoff";
- private static final int DEFAULT_RETRY_BACKOFF_SECONDS = 5;
+ static final String RETRY_BACKOFF_PROP = "segment.azure.retry.backoff";
+ static final int DEFAULT_RETRY_BACKOFF_SECONDS = 5;
- private static final String TIMEOUT_EXECUTION_PROP = "segment.timeout.execution";
- private static final int DEFAULT_TIMEOUT_EXECUTION = 30;
+ static final String TIMEOUT_EXECUTION_PROP = "segment.timeout.execution";
+ static final int DEFAULT_TIMEOUT_EXECUTION = 30;
- private static final String TIMEOUT_INTERVAL_PROP = "segment.timeout.interval";
- private static final int DEFAULT_TIMEOUT_INTERVAL = 1;
+ static final String TIMEOUT_INTERVAL_PROP = "segment.timeout.interval";
+ static final int DEFAULT_TIMEOUT_INTERVAL = 1;
- private static final String WRITE_TIMEOUT_EXECUTION_PROP = "segment.write.timeout.execution";
+ static final String WRITE_TIMEOUT_EXECUTION_PROP = "segment.write.timeout.execution";
- private static final String WRITE_TIMEOUT_INTERVAL_PROP = "segment.write.timeout.interval";
+ static final String WRITE_TIMEOUT_INTERVAL_PROP = "segment.write.timeout.interval";
+ /**
+ * Apply default request options to the blobRequestOptions if they are not already set.
+ * @param blobRequestOptions
+ */
public static void applyDefaultRequestOptions(BlobRequestOptions blobRequestOptions) {
if (blobRequestOptions.getRetryPolicyFactory() == null) {
int retryAttempts = Integer.getInteger(RETRY_ATTEMPTS_PROP, DEFAULT_RETRY_ATTEMPTS);
@@ -45,17 +49,24 @@ public class AzureRequestOptions {
}
}
+ /**
+ * Optimise the blob request options for write operations. This method does not change the original blobRequestOptions.
+ * This method also applies the default request options if they are not already set, by calling {@link #applyDefaultRequestOptions(BlobRequestOptions)}
+ * @param blobRequestOptions
+ * @return write optimised blobRequestOptions
+ */
public static BlobRequestOptions optimiseForWriteOperations(BlobRequestOptions blobRequestOptions) {
BlobRequestOptions writeOptimisedBlobRequestOptions = new BlobRequestOptions(blobRequestOptions);
+ applyDefaultRequestOptions(writeOptimisedBlobRequestOptions);
Integer writeTimeoutExecution = Integer.getInteger(WRITE_TIMEOUT_EXECUTION_PROP);
if (writeTimeoutExecution != null) {
- writeOptimisedBlobRequestOptions.setMaximumExecutionTimeInMs(writeTimeoutExecution);
+ writeOptimisedBlobRequestOptions.setMaximumExecutionTimeInMs((int) TimeUnit.SECONDS.toMillis(writeTimeoutExecution));
}
Integer writeTimeoutInterval = Integer.getInteger(WRITE_TIMEOUT_INTERVAL_PROP);
if (writeTimeoutInterval != null) {
- writeOptimisedBlobRequestOptions.setTimeoutIntervalInMs(writeTimeoutInterval);
+ writeOptimisedBlobRequestOptions.setTimeoutIntervalInMs((int) TimeUnit.SECONDS.toMillis(writeTimeoutInterval));
}
return writeOptimisedBlobRequestOptions;
diff --git a/oak-segment-azure/src/test/java/org/apache/jackrabbit/oak/segment/azure/util/AzureRequestOptionsTest.java b/oak-segment-azure/src/test/java/org/apache/jackrabbit/oak/segment/azure/util/AzureRequestOptionsTest.java
new file mode 100644
index 0000000000..35586b8889
--- /dev/null
+++ b/oak-segment-azure/src/test/java/org/apache/jackrabbit/oak/segment/azure/util/AzureRequestOptionsTest.java
@@ -0,0 +1,59 @@
+package org.apache.jackrabbit.oak.segment.azure.util;
+
+import com.microsoft.azure.storage.blob.BlobRequestOptions;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.Assert.assertEquals;
+
+public class AzureRequestOptionsTest {
+
+ private BlobRequestOptions blobRequestOptions;
+
+ @Before
+ public void setUp() {
+ blobRequestOptions = new BlobRequestOptions();
+ }
+
+ @Test
+ public void testApplyDefaultRequestOptions() {
+ AzureRequestOptions.applyDefaultRequestOptions(blobRequestOptions);
+ assertEquals(Long.valueOf(TimeUnit.SECONDS.toMillis(AzureRequestOptions.DEFAULT_TIMEOUT_EXECUTION)), Long.valueOf(blobRequestOptions.getMaximumExecutionTimeInMs()));
+ assertEquals(Long.valueOf(TimeUnit.SECONDS.toMillis(AzureRequestOptions.DEFAULT_TIMEOUT_INTERVAL)), Long.valueOf(blobRequestOptions.getTimeoutIntervalInMs()));
+ }
+
+ @Test
+ public void testApplyDefaultRequestOptionsWithCustomTimeouts() {
+ System.setProperty(AzureRequestOptions.TIMEOUT_EXECUTION_PROP, "10");
+ System.setProperty(AzureRequestOptions.TIMEOUT_INTERVAL_PROP, "5");
+
+ AzureRequestOptions.applyDefaultRequestOptions(blobRequestOptions);
+ assertEquals(Long.valueOf(TimeUnit.SECONDS.toMillis(10)), Long.valueOf(blobRequestOptions.getMaximumExecutionTimeInMs()));
+ assertEquals(Long.valueOf(TimeUnit.SECONDS.toMillis(5)), Long.valueOf(blobRequestOptions.getTimeoutIntervalInMs()));
+
+ System.clearProperty(AzureRequestOptions.TIMEOUT_EXECUTION_PROP);
+ System.clearProperty(AzureRequestOptions.TIMEOUT_INTERVAL_PROP);
+ }
+
+ @Test
+ public void testOptimiseForWriteOperations() {
+ BlobRequestOptions writeBlobRequestoptions = AzureRequestOptions.optimiseForWriteOperations(blobRequestOptions);
+ assertEquals(Long.valueOf(TimeUnit.SECONDS.toMillis(AzureRequestOptions.DEFAULT_TIMEOUT_EXECUTION)), Long.valueOf(writeBlobRequestoptions.getMaximumExecutionTimeInMs()));
+ assertEquals(Long.valueOf(TimeUnit.SECONDS.toMillis(AzureRequestOptions.DEFAULT_TIMEOUT_INTERVAL)), Long.valueOf(writeBlobRequestoptions.getTimeoutIntervalInMs()));
+ }
+
+ @Test
+ public void testOptimiseForWriteOperationsWithCustomTimeouts() {
+ System.setProperty(AzureRequestOptions.WRITE_TIMEOUT_EXECUTION_PROP, "10");
+ System.setProperty(AzureRequestOptions.WRITE_TIMEOUT_INTERVAL_PROP, "5");
+
+ BlobRequestOptions writeBlobRequestoptions = AzureRequestOptions.optimiseForWriteOperations(blobRequestOptions);
+ assertEquals(Long.valueOf(TimeUnit.SECONDS.toMillis(10)), Long.valueOf(writeBlobRequestoptions.getMaximumExecutionTimeInMs()));
+ assertEquals(Long.valueOf(TimeUnit.SECONDS.toMillis(5)), Long.valueOf(writeBlobRequestoptions.getTimeoutIntervalInMs()));
+
+ System.clearProperty(AzureRequestOptions.WRITE_TIMEOUT_EXECUTION_PROP);
+ System.clearProperty(AzureRequestOptions.WRITE_TIMEOUT_INTERVAL_PROP);
+ }
+}