Skip to content

Commit 37e0828

Browse files
brianlosssteveloughran
authored andcommitted
HADOOP-17811: ABFS ExponentialRetryPolicy doesn't pick up configuration values (#3221)
Contributed by Brian Loss. Change-Id: I5f24196d1d02de91336c3679abaf8d55cfaed746
1 parent b8a8821 commit 37e0828

File tree

5 files changed

+74
-11
lines changed

5 files changed

+74
-11
lines changed

hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/AzureBlobFileSystemStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1479,7 +1479,7 @@ private void initializeClient(URI uri, String fileSystemName,
14791479
private AbfsClientContext populateAbfsClientContext() {
14801480
return new AbfsClientContextBuilder()
14811481
.withExponentialRetryPolicy(
1482-
new ExponentialRetryPolicy(abfsConfiguration.getMaxIoRetries()))
1482+
new ExponentialRetryPolicy(abfsConfiguration))
14831483
.withAbfsCounters(abfsCounters)
14841484
.withAbfsPerfTracker(abfsPerfTracker)
14851485
.build();

hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ExponentialRetryPolicy.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.Random;
2222
import java.net.HttpURLConnection;
2323

24+
import org.apache.hadoop.fs.azurebfs.AbfsConfiguration;
2425
import org.apache.hadoop.thirdparty.com.google.common.annotations.VisibleForTesting;
2526

2627
/**
@@ -89,6 +90,16 @@ public ExponentialRetryPolicy(final int maxIoRetries) {
8990
DEFAULT_CLIENT_BACKOFF);
9091
}
9192

93+
/**
94+
* Initializes a new instance of the {@link ExponentialRetryPolicy} class.
95+
*
96+
* @param conf The {@link AbfsConfiguration} from which to retrieve retry configuration.
97+
*/
98+
public ExponentialRetryPolicy(AbfsConfiguration conf) {
99+
this(conf.getMaxIoRetries(), conf.getMinBackoffIntervalMilliseconds(), conf.getMaxBackoffIntervalMilliseconds(),
100+
conf.getBackoffIntervalMilliseconds());
101+
}
102+
92103
/**
93104
* Initializes a new instance of the {@link ExponentialRetryPolicy} class.
94105
*

hadoop-tools/hadoop-azure/src/site/markdown/abfs.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ with the following configurations.
338338
retries. Default value is 5.
339339
* `fs.azure.oauth.token.fetch.retry.min.backoff.interval`: Minimum back-off
340340
interval. Added to the retry interval computed from delta backoff. By
341-
default this si set as 0. Set the interval in milli seconds.
341+
default this is set as 0. Set the interval in milli seconds.
342342
* `fs.azure.oauth.token.fetch.retry.max.backoff.interval`: Maximum back-off
343343
interval. Default value is 60000 (sixty seconds). Set the interval in milli
344344
seconds.
@@ -778,9 +778,31 @@ The following configs are related to read and write operations.
778778

779779
`fs.azure.io.retry.max.retries`: Sets the number of retries for IO operations.
780780
Currently this is used only for the server call retry logic. Used within
781-
AbfsClient class as part of the ExponentialRetryPolicy. The value should be
781+
`AbfsClient` class as part of the ExponentialRetryPolicy. The value should be
782782
greater than or equal to 0.
783783

784+
`fs.azure.io.retry.min.backoff.interval`: Sets the minimum backoff interval for
785+
retries of IO operations. Currently this is used only for the server call retry
786+
logic. Used within `AbfsClient` class as part of the ExponentialRetryPolicy. This
787+
value indicates the smallest interval (in milliseconds) to wait before retrying
788+
an IO operation. The default value is 3000 (3 seconds).
789+
790+
`fs.azure.io.retry.max.backoff.interval`: Sets the maximum backoff interval for
791+
retries of IO operations. Currently this is used only for the server call retry
792+
logic. Used within `AbfsClient` class as part of the ExponentialRetryPolicy. This
793+
value indicates the largest interval (in milliseconds) to wait before retrying
794+
an IO operation. The default value is 30000 (30 seconds).
795+
796+
`fs.azure.io.retry.backoff.interval`: Sets the default backoff interval for
797+
retries of IO operations. Currently this is used only for the server call retry
798+
logic. Used within `AbfsClient` class as part of the ExponentialRetryPolicy. This
799+
value is used to compute a random delta between 80% and 120% of the specified
800+
value. This random delta is then multiplied by an exponent of the current IO
801+
retry number (i.e., the default is multiplied by `2^(retryNum - 1)`) and then
802+
contstrained within the range of [`fs.azure.io.retry.min.backoff.interval`,
803+
`fs.azure.io.retry.max.backoff.interval`] to determine the amount of time to
804+
wait before the next IO retry attempt. The default value is 3000 (3 seconds).
805+
784806
`fs.azure.write.request.size`: To set the write buffer size. Specify the value
785807
in bytes. The value should be between 16384 to 104857600 both inclusive (16 KB
786808
to 100 MB). The default value will be 8388608 (8 MB).
@@ -837,7 +859,7 @@ when there are too many writes from the same process.
837859

838860
### <a name="securityconfigoptions"></a> Security Options
839861
`fs.azure.always.use.https`: Enforces to use HTTPS instead of HTTP when the flag
840-
is made true. Irrespective of the flag, AbfsClient will use HTTPS if the secure
862+
is made true. Irrespective of the flag, `AbfsClient` will use HTTPS if the secure
841863
scheme (ABFSS) is used or OAuth is used for authentication. By default this will
842864
be set to true.
843865

hadoop-tools/hadoop-azure/src/site/markdown/testing_azure.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ use requires the presence of secret credentials, where tests may be slow,
448448
and where finding out why something failed from nothing but the test output
449449
is critical.
450450

451-
#### Subclasses Existing Shared Base Blasses
451+
#### Subclasses Existing Shared Base Classes
452452

453453
There are a set of base classes which should be extended for Azure tests and
454454
integration tests.
@@ -602,7 +602,7 @@ various test combinations, it will:
602602
2. Run tests for all combinations
603603
3. Summarize results across all the test combination runs.
604604

605-
As a pre-requiste step, fill config values for test accounts and credentials
605+
As a pre-requisite step, fill config values for test accounts and credentials
606606
needed for authentication in `src/test/resources/azure-auth-keys.xml.template`
607607
and rename as `src/test/resources/azure-auth-keys.xml`.
608608

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestExponentialRetryPolicy.java

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818

1919
package org.apache.hadoop.fs.azurebfs.services;
2020

21+
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.AZURE_BACKOFF_INTERVAL;
22+
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.AZURE_MAX_BACKOFF_INTERVAL;
23+
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.AZURE_MAX_IO_RETRIES;
24+
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.AZURE_MIN_BACKOFF_INTERVAL;
25+
2126
import java.util.Random;
2227

2328
import org.junit.Assert;
@@ -32,7 +37,6 @@
3237
* Unit test TestExponentialRetryPolicy.
3338
*/
3439
public class TestExponentialRetryPolicy extends AbstractAbfsIntegrationTest {
35-
3640
private final int maxRetryCount = 30;
3741
private final int noRetryCount = 0;
3842
private final int retryCount = new Random().nextInt(maxRetryCount);
@@ -57,12 +61,38 @@ public void testDifferentMaxIORetryCount() throws Exception {
5761
@Test
5862
public void testDefaultMaxIORetryCount() throws Exception {
5963
AbfsConfiguration abfsConfig = getAbfsConfig();
60-
Assert.assertTrue(
64+
Assert.assertEquals(
6165
String.format("default maxIORetry count is %s.", maxRetryCount),
62-
abfsConfig.getMaxIoRetries() == maxRetryCount);
66+
maxRetryCount, abfsConfig.getMaxIoRetries());
6367
testMaxIOConfig(abfsConfig);
6468
}
6569

70+
@Test
71+
public void testAbfsConfigConstructor() throws Exception {
72+
// Ensure we choose expected values that are not defaults
73+
ExponentialRetryPolicy template = new ExponentialRetryPolicy(
74+
getAbfsConfig().getMaxIoRetries());
75+
int testModifier = 1;
76+
int expectedMaxRetries = template.getRetryCount() + testModifier;
77+
int expectedMinBackoff = template.getMinBackoff() + testModifier;
78+
int expectedMaxBackoff = template.getMaxBackoff() + testModifier;
79+
int expectedDeltaBackoff = template.getDeltaBackoff() + testModifier;
80+
81+
Configuration config = new Configuration(this.getRawConfiguration());
82+
config.setInt(AZURE_MAX_IO_RETRIES, expectedMaxRetries);
83+
config.setInt(AZURE_MIN_BACKOFF_INTERVAL, expectedMinBackoff);
84+
config.setInt(AZURE_MAX_BACKOFF_INTERVAL, expectedMaxBackoff);
85+
config.setInt(AZURE_BACKOFF_INTERVAL, expectedDeltaBackoff);
86+
87+
ExponentialRetryPolicy policy = new ExponentialRetryPolicy(
88+
new AbfsConfiguration(config, "dummyAccountName"));
89+
90+
Assert.assertEquals("Max retry count was not set as expected.", expectedMaxRetries, policy.getRetryCount());
91+
Assert.assertEquals("Min backoff interval was not set as expected.", expectedMinBackoff, policy.getMinBackoff());
92+
Assert.assertEquals("Max backoff interval was not set as expected.", expectedMaxBackoff, policy.getMaxBackoff());
93+
Assert.assertEquals("Delta backoff interval was not set as expected.", expectedDeltaBackoff, policy.getDeltaBackoff());
94+
}
95+
6696
private AbfsConfiguration getAbfsConfig() throws Exception {
6797
Configuration
6898
config = new Configuration(this.getRawConfiguration());
@@ -81,8 +111,8 @@ private void testMaxIOConfig(AbfsConfiguration abfsConfig) {
81111
localRetryCount++;
82112
}
83113

84-
Assert.assertTrue(
114+
Assert.assertEquals(
85115
"When all retries are exhausted, the retryCount will be same as max configured",
86-
localRetryCount == abfsConfig.getMaxIoRetries());
116+
abfsConfig.getMaxIoRetries(), localRetryCount);
87117
}
88118
}

0 commit comments

Comments
 (0)