Skip to content

Commit 37d6a1e

Browse files
committed
Moved namespace details to configuration class
1 parent 6eae158 commit 37d6a1e

File tree

7 files changed

+91
-42
lines changed

7 files changed

+91
-42
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public class AbfsConfiguration{
9595
private final AbfsServiceType fsConfiguredServiceType;
9696
private final boolean isSecure;
9797
private static final Logger LOG = LoggerFactory.getLogger(AbfsConfiguration.class);
98+
private Trilean isNamespaceEnabled = null;
9899

99100
@StringConfigurationValidatorAnnotation(ConfigurationKey = FS_AZURE_ACCOUNT_IS_HNS_ENABLED,
100101
DefaultValue = DEFAULT_FS_AZURE_ACCOUNT_IS_HNS_ENABLED)
@@ -525,8 +526,11 @@ public AbfsConfiguration(final Configuration rawConfig, String accountName)
525526
* @return TRUE/FALSE value if configured, UNKNOWN if not configured.
526527
*/
527528
public Trilean getIsNamespaceEnabledAccount() {
528-
return Trilean.getTrilean(
529-
getString(FS_AZURE_ACCOUNT_IS_HNS_ENABLED, isNamespaceEnabledAccount));
529+
if (isNamespaceEnabled == null) {
530+
isNamespaceEnabled = Trilean.getTrilean(
531+
getString(FS_AZURE_ACCOUNT_IS_HNS_ENABLED, isNamespaceEnabledAccount));
532+
}
533+
return isNamespaceEnabled;
530534
}
531535

532536
/**
@@ -1525,8 +1529,8 @@ void setMaxBackoffIntervalMilliseconds(int maxBackoffInterval) {
15251529
}
15261530

15271531
@VisibleForTesting
1528-
void setIsNamespaceEnabledAccount(String isNamespaceEnabledAccount) {
1529-
this.isNamespaceEnabledAccount = isNamespaceEnabledAccount;
1532+
public void setIsNamespaceEnabledAccount(Trilean isNamespaceEnabledAccount) {
1533+
isNamespaceEnabled = isNamespaceEnabledAccount;
15301534
}
15311535

15321536
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ public void initialize(URI uri, Configuration configuration)
229229
* HNS Account Cannot have Blob Endpoint URI.
230230
*/
231231
try {
232+
// This will update namespaceEnable based on getAcl in case config is not set.
233+
// This Information will be stored in abfsConfiguration class.
232234
abfsConfiguration.validateConfiguredServiceType(
233235
tryGetIsNamespaceEnabled(initFSTracingContext));
234236
} catch (InvalidConfigurationValueException ex) {
@@ -296,7 +298,6 @@ public void initialize(URI uri, Configuration configuration)
296298
}
297299
}
298300
}
299-
getAbfsStore().updateClientWithNamespaceInfo(new TracingContext(initFSTracingContext));
300301

301302
LOG.trace("Initiate check for delegation token manager");
302303
if (UserGroupInformation.isSecurityEnabled()) {

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

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ public class AzureBlobFileSystemStore implements Closeable, ListingSupport {
186186

187187
private final AbfsConfiguration abfsConfiguration;
188188
private Set<String> azureInfiniteLeaseDirSet;
189-
private volatile Trilean isNamespaceEnabled;
190189
private final AuthType authType;
191190
private final UserGroupInformation userGroupInformation;
192191
private final IdentityTransformerInterface identityTransformer;
@@ -234,8 +233,6 @@ public AzureBlobFileSystemStore(
234233

235234
LOG.trace("AbfsConfiguration init complete");
236235

237-
this.isNamespaceEnabled = abfsConfiguration.getIsNamespaceEnabledAccount();
238-
239236
this.userGroupInformation = UserGroupInformation.getCurrentUser();
240237
this.userName = userGroupInformation.getShortUserName();
241238
LOG.trace("UGI init complete");
@@ -287,18 +284,6 @@ public AzureBlobFileSystemStore(
287284
"abfs-bounded");
288285
}
289286

290-
/**
291-
* Updates the client with the namespace information.
292-
*
293-
* @param tracingContext the tracing context to be used for the operation
294-
* @throws AzureBlobFileSystemException if an error occurs while updating the client
295-
*/
296-
public void updateClientWithNamespaceInfo(TracingContext tracingContext)
297-
throws AzureBlobFileSystemException {
298-
boolean isNamespaceEnabled = getIsNamespaceEnabled(tracingContext);
299-
AbfsClient.setIsNamespaceEnabled(isNamespaceEnabled);
300-
}
301-
302287
/**
303288
* Checks if the given key in Azure Storage should be stored as a page
304289
* blob instead of block blob.
@@ -409,32 +394,32 @@ public boolean getIsNamespaceEnabled(TracingContext tracingContext)
409394

410395
private synchronized boolean getNamespaceEnabledInformationFromServer(
411396
final TracingContext tracingContext) throws AzureBlobFileSystemException {
412-
if (isNamespaceEnabled != Trilean.UNKNOWN) {
413-
return isNamespaceEnabled.toBoolean();
397+
if (abfsConfiguration.getIsNamespaceEnabledAccount() != Trilean.UNKNOWN) {
398+
return isNamespaceEnabled();
414399
}
415400
try {
416401
LOG.debug("Get root ACL status");
417402
getClient(AbfsServiceType.DFS).getAclStatus(AbfsHttpConstants.ROOT_PATH, tracingContext);
418403
// If getAcl succeeds, namespace is enabled.
419-
isNamespaceEnabled = Trilean.getTrilean(true);
404+
setNamespaceEnabled(Trilean.TRUE);
420405
} catch (AbfsRestOperationException ex) {
421406
// Get ACL status is a HEAD request, its response doesn't contain errorCode
422407
// So can only rely on its status code to determine account type.
423408
if (HttpURLConnection.HTTP_BAD_REQUEST != ex.getStatusCode()) {
424409
// If getAcl fails with anything other than 400, namespace is enabled.
425-
isNamespaceEnabled = Trilean.getTrilean(true);
410+
setNamespaceEnabled(Trilean.TRUE);
426411
// Continue to throw exception as earlier.
427412
LOG.debug("Failed to get ACL status with non 400. Inferring namespace enabled", ex);
428413
throw ex;
429414
}
430415
// If getAcl fails with 400, namespace is disabled.
431416
LOG.debug("Failed to get ACL status with 400. "
432417
+ "Inferring namespace disabled and ignoring error", ex);
433-
isNamespaceEnabled = Trilean.getTrilean(false);
418+
setNamespaceEnabled(Trilean.FALSE);
434419
} catch (AzureBlobFileSystemException ex) {
435420
throw ex;
436421
}
437-
return isNamespaceEnabled.toBoolean();
422+
return isNamespaceEnabled();
438423
}
439424

440425
/**
@@ -443,7 +428,7 @@ private synchronized boolean getNamespaceEnabledInformationFromServer(
443428
*/
444429
@VisibleForTesting
445430
boolean isNamespaceEnabled() throws TrileanConversionException {
446-
return this.isNamespaceEnabled.toBoolean();
431+
return abfsConfiguration.getIsNamespaceEnabledAccount().toBoolean();
447432
}
448433

449434
@VisibleForTesting
@@ -2028,7 +2013,7 @@ DataBlocks.BlockFactory getBlockFactory() {
20282013

20292014
@VisibleForTesting
20302015
void setNamespaceEnabled(Trilean isNamespaceEnabled){
2031-
this.isNamespaceEnabled = isNamespaceEnabled;
2016+
abfsConfiguration.setIsNamespaceEnabledAccount(isNamespaceEnabled);
20322017
}
20332018

20342019
@VisibleForTesting

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import org.apache.hadoop.fs.azurebfs.contracts.exceptions.InvalidFileSystemPropertyException;
7070
import org.apache.hadoop.fs.azurebfs.contracts.exceptions.InvalidUriException;
7171
import org.apache.hadoop.fs.azurebfs.contracts.exceptions.SASTokenProviderException;
72+
import org.apache.hadoop.fs.azurebfs.contracts.exceptions.TrileanConversionException;
7273
import org.apache.hadoop.fs.azurebfs.contracts.services.AppendRequestParameters;
7374
import org.apache.hadoop.fs.azurebfs.contracts.services.AzureServiceErrorCode;
7475
import org.apache.hadoop.fs.azurebfs.contracts.services.ListResultEntrySchema;
@@ -194,7 +195,6 @@ public abstract class AbfsClient implements Closeable {
194195
private KeepAliveCache keepAliveCache;
195196

196197
private AbfsApacheHttpClient abfsApacheHttpClient;
197-
private static boolean isNamespaceEnabled = false;
198198

199199
/**
200200
* logging the rename failure if metadata is in an incomplete state.
@@ -1717,17 +1717,13 @@ protected String getUserAgent() {
17171717
*
17181718
* @return True if the namespace is enabled, false otherwise.
17191719
*/
1720-
public static boolean getIsNamespaceEnabled() {
1721-
return isNamespaceEnabled;
1722-
}
1723-
1724-
/**
1725-
* Sets the namespace enabled status.
1726-
*
1727-
* @param namespaceEnabled True to enable the namespace, false to disable it.
1728-
*/
1729-
public static void setIsNamespaceEnabled(final boolean namespaceEnabled) {
1730-
isNamespaceEnabled = namespaceEnabled;
1720+
public boolean getIsNamespaceEnabled() throws TrileanConversionException {
1721+
try {
1722+
return abfsConfiguration.getIsNamespaceEnabledAccount().toBoolean();
1723+
} catch (TrileanConversionException ex) {
1724+
LOG.error("Failed to convert namespace enabled account property to boolean", ex);
1725+
throw ex;
1726+
}
17311727
}
17321728

17331729
protected boolean isRenameResilience() {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1565,7 +1565,8 @@ private Hashtable<String, String> parseCommaSeparatedXmsProperties(String xMsPro
15651565
* @return client transaction id
15661566
*/
15671567
@VisibleForTesting
1568-
public String addClientTransactionIdToHeader(List<AbfsHttpHeader> requestHeaders) {
1568+
public String addClientTransactionIdToHeader(List<AbfsHttpHeader> requestHeaders)
1569+
throws AzureBlobFileSystemException{
15691570
String clientTransactionId = null;
15701571
// Set client transaction ID if the namespace and client transaction ID config are enabled.
15711572
if (getIsNamespaceEnabled() && getAbfsConfiguration().getIsClientTransactionIdEnabled()) {

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.apache.hadoop.fs.azurebfs.contracts.annotations.ConfigurationValidationAnnotations.LongConfigurationValidatorAnnotation;
3232
import org.apache.hadoop.fs.azurebfs.contracts.annotations.ConfigurationValidationAnnotations.Base64StringConfigurationValidatorAnnotation;
3333
import org.apache.hadoop.fs.azurebfs.contracts.exceptions.KeyProviderException;
34+
import org.apache.hadoop.fs.azurebfs.enums.Trilean;
3435
import org.apache.hadoop.fs.azurebfs.utils.Base64;
3536

3637
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_SSL_CHANNEL_MODE_KEY;
@@ -210,6 +211,66 @@ public void testSSLSocketFactoryConfiguration()
210211
.isEqualTo(DelegatingSSLSocketFactory.SSLChannelMode.OpenSSL);
211212
}
212213

214+
/**
215+
* Tests the behavior of AbfsConfiguration when the namespace-enabled
216+
* configuration is not explicitly set (i.e., set to an empty string).
217+
*
218+
* Expects the namespace value to be set as UNKNOWN.
219+
*
220+
* @throws Exception if any error occurs during configuration setup or evaluation
221+
*/
222+
@Test
223+
public void testNameSpaceConfigNotSet() throws Exception {
224+
Configuration configuration = new Configuration();
225+
configuration.set(ConfigurationKeys.FS_AZURE_ACCOUNT_IS_HNS_ENABLED, "");
226+
AbfsConfiguration abfsConfig = new AbfsConfiguration(configuration, "bogusAccountName");
227+
228+
// Test that the namespace enabled config is set correctly
229+
Assertions.assertThat(abfsConfig.getIsNamespaceEnabledAccount())
230+
.describedAs("Namespace enabled should be unknown in case config is not set")
231+
.isEqualTo(Trilean.UNKNOWN);
232+
}
233+
234+
/**
235+
* Tests the behavior of AbfsConfiguration when the namespace-enabled
236+
* configuration is explicitly set to "true".
237+
*
238+
* Expects the namespace value to be set as TRUE.
239+
*
240+
* @throws Exception if any error occurs during configuration setup or evaluation
241+
*/
242+
@Test
243+
public void testNameSpaceConfigSetToTrue() throws Exception {
244+
Configuration configuration = new Configuration();
245+
configuration.set(ConfigurationKeys.FS_AZURE_ACCOUNT_IS_HNS_ENABLED, "true");
246+
AbfsConfiguration abfsConfig = new AbfsConfiguration(configuration, "bogusAccountName");
247+
248+
// Test that the namespace enabled config is set correctly
249+
Assertions.assertThat(abfsConfig.getIsNamespaceEnabledAccount())
250+
.describedAs("Namespace enabled should be true in case config is set to true")
251+
.isEqualTo(Trilean.TRUE);
252+
}
253+
254+
/**
255+
* Tests the behavior of AbfsConfiguration when the namespace-enabled
256+
* configuration is explicitly set to "false".
257+
*
258+
* Expects the namespace value to be set as FALSE.
259+
*
260+
* @throws Exception if any error occurs during configuration setup or evaluation
261+
*/
262+
@Test
263+
public void testNameSpaceConfigSetToFalse() throws Exception {
264+
Configuration configuration = new Configuration();
265+
configuration.set(ConfigurationKeys.FS_AZURE_ACCOUNT_IS_HNS_ENABLED, "false");
266+
AbfsConfiguration abfsConfig = new AbfsConfiguration(configuration, "bogusAccountName");
267+
268+
// Test that the namespace enabled config is set correctly
269+
Assertions.assertThat(abfsConfig.getIsNamespaceEnabledAccount())
270+
.describedAs("Namespace enabled should be false in case config is set to false")
271+
.isEqualTo(Trilean.FALSE);
272+
}
273+
213274
public static AbfsConfiguration updateRetryConfigs(AbfsConfiguration abfsConfig,
214275
int retryCount,
215276
int backoffTime) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.mockito.invocation.InvocationOnMock;
4040
import org.mockito.stubbing.Answer;
4141

42+
import org.apache.hadoop.fs.azurebfs.contracts.exceptions.AzureBlobFileSystemException;
4243
import org.apache.hadoop.fs.azurebfs.utils.TracingContext;
4344
import org.apache.hadoop.util.functional.FunctionRaisingIOE;
4445

@@ -370,7 +371,7 @@ public static void mockGetRenameBlobHandler(AbfsBlobClient blobClient,
370371
* @param clientTransactionId An array to hold the generated transaction ID.
371372
*/
372373
public static void mockAddClientTransactionIdToHeader(AbfsDfsClient abfsDfsClient,
373-
String[] clientTransactionId) {
374+
String[] clientTransactionId) throws AzureBlobFileSystemException {
374375
Mockito.doAnswer(addClientTransactionId -> {
375376
clientTransactionId[0] = UUID.randomUUID().toString();
376377
List<AbfsHttpHeader> headers = addClientTransactionId.getArgument(0);

0 commit comments

Comments
 (0)