Skip to content

Commit 1d03c69

Browse files
authored
HADOOP-17811: ABFS ExponentialRetryPolicy doesn't pick up configuration values (#3221)
Contributed by Brian Loss.
1 parent e001f8e commit 1d03c69

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
@@ -1524,7 +1524,7 @@ private void initializeClient(URI uri, String fileSystemName,
15241524
private AbfsClientContext populateAbfsClientContext() {
15251525
return new AbfsClientContextBuilder()
15261526
.withExponentialRetryPolicy(
1527-
new ExponentialRetryPolicy(abfsConfiguration.getMaxIoRetries()))
1527+
new ExponentialRetryPolicy(abfsConfiguration))
15281528
.withAbfsCounters(abfsCounters)
15291529
.withAbfsPerfTracker(abfsPerfTracker)
15301530
.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.
@@ -800,9 +800,31 @@ The following configs are related to read and write operations.
800800

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

806+
`fs.azure.io.retry.min.backoff.interval`: Sets the minimum backoff interval for
807+
retries of IO operations. Currently this is used only for the server call retry
808+
logic. Used within `AbfsClient` class as part of the ExponentialRetryPolicy. This
809+
value indicates the smallest interval (in milliseconds) to wait before retrying
810+
an IO operation. The default value is 3000 (3 seconds).
811+
812+
`fs.azure.io.retry.max.backoff.interval`: Sets the maximum backoff interval for
813+
retries of IO operations. Currently this is used only for the server call retry
814+
logic. Used within `AbfsClient` class as part of the ExponentialRetryPolicy. This
815+
value indicates the largest interval (in milliseconds) to wait before retrying
816+
an IO operation. The default value is 30000 (30 seconds).
817+
818+
`fs.azure.io.retry.backoff.interval`: Sets the default backoff interval for
819+
retries of IO operations. Currently this is used only for the server call retry
820+
logic. Used within `AbfsClient` class as part of the ExponentialRetryPolicy. This
821+
value is used to compute a random delta between 80% and 120% of the specified
822+
value. This random delta is then multiplied by an exponent of the current IO
823+
retry number (i.e., the default is multiplied by `2^(retryNum - 1)`) and then
824+
contstrained within the range of [`fs.azure.io.retry.min.backoff.interval`,
825+
`fs.azure.io.retry.max.backoff.interval`] to determine the amount of time to
826+
wait before the next IO retry attempt. The default value is 3000 (3 seconds).
827+
806828
`fs.azure.write.request.size`: To set the write buffer size. Specify the value
807829
in bytes. The value should be between 16384 to 104857600 both inclusive (16 KB
808830
to 100 MB). The default value will be 8388608 (8 MB).
@@ -859,7 +881,7 @@ when there are too many writes from the same process.
859881

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

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)