-
Notifications
You must be signed in to change notification settings - Fork 9.1k
HADOOP-19595. ABFS: AbfsConfiguration should store account type information (HNS or FNS) #7765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
37d6a1e
179a18e
8e13f7b
ad210ef
fd0d14e
fa95fcf
71c8148
c4703b2
67c1562
5eb0616
6032492
ef93413
0b909fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -186,7 +186,6 @@ public class AzureBlobFileSystemStore implements Closeable, ListingSupport { | |
|
||
private final AbfsConfiguration abfsConfiguration; | ||
private Set<String> azureInfiniteLeaseDirSet; | ||
private volatile Trilean isNamespaceEnabled; | ||
private final AuthType authType; | ||
private final UserGroupInformation userGroupInformation; | ||
private final IdentityTransformerInterface identityTransformer; | ||
|
@@ -234,8 +233,6 @@ public AzureBlobFileSystemStore( | |
|
||
LOG.trace("AbfsConfiguration init complete"); | ||
|
||
this.isNamespaceEnabled = abfsConfiguration.getIsNamespaceEnabledAccount(); | ||
|
||
this.userGroupInformation = UserGroupInformation.getCurrentUser(); | ||
this.userName = userGroupInformation.getShortUserName(); | ||
LOG.trace("UGI init complete"); | ||
|
@@ -287,18 +284,6 @@ public AzureBlobFileSystemStore( | |
"abfs-bounded"); | ||
} | ||
|
||
/** | ||
* Updates the client with the namespace information. | ||
* | ||
* @param tracingContext the tracing context to be used for the operation | ||
* @throws AzureBlobFileSystemException if an error occurs while updating the client | ||
*/ | ||
public void updateClientWithNamespaceInfo(TracingContext tracingContext) | ||
throws AzureBlobFileSystemException { | ||
boolean isNamespaceEnabled = getIsNamespaceEnabled(tracingContext); | ||
AbfsClient.setIsNamespaceEnabled(isNamespaceEnabled); | ||
} | ||
|
||
/** | ||
* Checks if the given key in Azure Storage should be stored as a page | ||
* blob instead of block blob. | ||
|
@@ -409,32 +394,32 @@ public boolean getIsNamespaceEnabled(TracingContext tracingContext) | |
|
||
private synchronized boolean getNamespaceEnabledInformationFromServer( | ||
final TracingContext tracingContext) throws AzureBlobFileSystemException { | ||
if (isNamespaceEnabled != Trilean.UNKNOWN) { | ||
return isNamespaceEnabled.toBoolean(); | ||
if (abfsConfiguration.getIsNamespaceEnabledAccount() != Trilean.UNKNOWN) { | ||
return isNamespaceEnabled(); | ||
} | ||
try { | ||
LOG.debug("Get root ACL status"); | ||
getClient(AbfsServiceType.DFS).getAclStatus(AbfsHttpConstants.ROOT_PATH, tracingContext); | ||
// If getAcl succeeds, namespace is enabled. | ||
isNamespaceEnabled = Trilean.getTrilean(true); | ||
setNamespaceEnabled(Trilean.TRUE); | ||
} catch (AbfsRestOperationException ex) { | ||
// Get ACL status is a HEAD request, its response doesn't contain errorCode | ||
// So can only rely on its status code to determine account type. | ||
if (HttpURLConnection.HTTP_BAD_REQUEST != ex.getStatusCode()) { | ||
// If getAcl fails with anything other than 400, namespace is enabled. | ||
isNamespaceEnabled = Trilean.getTrilean(true); | ||
setNamespaceEnabled(Trilean.TRUE); | ||
// Continue to throw exception as earlier. | ||
LOG.debug("Failed to get ACL status with non 400. Inferring namespace enabled", ex); | ||
throw ex; | ||
} | ||
// If getAcl fails with 400, namespace is disabled. | ||
LOG.debug("Failed to get ACL status with 400. " | ||
+ "Inferring namespace disabled and ignoring error", ex); | ||
isNamespaceEnabled = Trilean.getTrilean(false); | ||
setNamespaceEnabled(Trilean.FALSE); | ||
} catch (AzureBlobFileSystemException ex) { | ||
throw ex; | ||
} | ||
return isNamespaceEnabled.toBoolean(); | ||
return isNamespaceEnabled(); | ||
} | ||
|
||
/** | ||
|
@@ -443,7 +428,7 @@ private synchronized boolean getNamespaceEnabledInformationFromServer( | |
*/ | ||
@VisibleForTesting | ||
boolean isNamespaceEnabled() throws TrileanConversionException { | ||
return this.isNamespaceEnabled.toBoolean(); | ||
return abfsConfiguration.getIsNamespaceEnabledAccount().toBoolean(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here also should we have a try-catch block for TrileanConversionException like we have in AbfsClient-line 1722? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method should throw an exception if namespace enabled isn't initialized, so a try-catch block isn't necessary here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better to use getter here and other places for abfsconfiguration. This will make sure same object is being referred everywhere and can easily be mocked if needed in future. |
||
} | ||
|
||
@VisibleForTesting | ||
|
@@ -2028,7 +2013,7 @@ DataBlocks.BlockFactory getBlockFactory() { | |
|
||
@VisibleForTesting | ||
void setNamespaceEnabled(Trilean isNamespaceEnabled){ | ||
this.isNamespaceEnabled = isNamespaceEnabled; | ||
abfsConfiguration.setIsNamespaceEnabledAccount(isNamespaceEnabled); | ||
} | ||
|
||
@VisibleForTesting | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -282,6 +282,9 @@ private void ensureGetAclDetermineHnsStatusAccuratelyInternal(int statusCode, | |
boolean isHnsEnabled = store.getIsNamespaceEnabled( | ||
getTestTracingContext(getFileSystem(), false)); | ||
Assertions.assertThat(isHnsEnabled).isEqualTo(expectedValue); | ||
Assertions.assertThat(store.getClient().getIsNamespaceEnabled()) | ||
.describedAs("ABFS Client should return same isNameSpace value as store") | ||
.isEqualTo(expectedValue); | ||
|
||
// GetAcl() should be called only once to determine the HNS status. | ||
Mockito.verify(mockClient, times(1)) | ||
|
@@ -341,6 +344,76 @@ public void testAccountSpecificConfig() throws Exception { | |
} | ||
} | ||
|
||
/** | ||
* Tests the behavior of AbfsConfiguration when the namespace-enabled | ||
* configuration set based on config provided. | ||
* | ||
* Expects the namespace value based on config provided. | ||
* | ||
* @throws Exception if any error occurs during configuration setup or evaluation | ||
*/ | ||
@Test | ||
public void testNameSpaceConfig() throws Exception { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here also validate that client returns the same value as what is set in the config There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added. |
||
Configuration configuration = getRawConfiguration(); | ||
configuration.unset(FS_AZURE_ACCOUNT_IS_HNS_ENABLED); | ||
configuration.unset(accountProperty(FS_AZURE_ACCOUNT_IS_HNS_ENABLED, this.getAccountName())); | ||
AzureBlobFileSystem abfs = (AzureBlobFileSystem) FileSystem.newInstance(configuration); | ||
AbfsConfiguration abfsConfig = new AbfsConfiguration(configuration, "bogusAccountName"); | ||
|
||
// Test that the namespace value when config is not set | ||
Assertions.assertThat(abfsConfig.getIsNamespaceEnabledAccount()) | ||
.describedAs("Namespace enabled should be unknown in case config is not set") | ||
.isEqualTo(Trilean.UNKNOWN); | ||
|
||
// In case no namespace config is present, file system init calls getAcl() to determine account type. | ||
Assertions.assertThat(abfs.getIsNamespaceEnabled(getTestTracingContext(abfs, false))) | ||
.describedAs("getIsNamespaceEnabled should return account type based on getAcl() call") | ||
.isEqualTo(abfs.getAbfsClient().getIsNamespaceEnabled()); | ||
|
||
// In case no namespace config is present, file system init calls getAcl() to determine account type. | ||
Assertions.assertThat(abfs.getAbfsStore().getAbfsConfiguration().getIsNamespaceEnabledAccount()) | ||
.describedAs("getIsNamespaceEnabled() should return updated account type based on getAcl() call") | ||
.isNotEqualTo(Trilean.UNKNOWN); | ||
|
||
configuration.set(FS_AZURE_ACCOUNT_IS_HNS_ENABLED, TRUE_STR); | ||
abfs = (AzureBlobFileSystem) FileSystem.newInstance(configuration); | ||
abfsConfig = new AbfsConfiguration(configuration, "bogusAccountName"); | ||
|
||
// Test that the namespace enabled config is set correctly | ||
Assertions.assertThat(abfsConfig.getIsNamespaceEnabledAccount()) | ||
.describedAs("Namespace enabled should be true in case config is set to true") | ||
.isEqualTo(Trilean.TRUE); | ||
|
||
// In case namespace config is present, same value will be return. | ||
Assertions.assertThat(abfs.getIsNamespaceEnabled(getTestTracingContext(abfs, false))) | ||
.describedAs("getIsNamespaceEnabled() should return true when config is set to true") | ||
.isEqualTo(true); | ||
|
||
// In case namespace config is present, same value will be return. | ||
Assertions.assertThat(abfs.getAbfsClient().getIsNamespaceEnabled()) | ||
.describedAs("Client's getIsNamespaceEnabled() should return true when config is set to true") | ||
.isEqualTo(true); | ||
|
||
configuration.set(FS_AZURE_ACCOUNT_IS_HNS_ENABLED, FALSE_STR); | ||
abfs = (AzureBlobFileSystem) FileSystem.newInstance(configuration); | ||
abfsConfig = new AbfsConfiguration(configuration, "bogusAccountName"); | ||
|
||
// Test that the namespace enabled config is set correctly | ||
Assertions.assertThat(abfsConfig.getIsNamespaceEnabledAccount()) | ||
.describedAs("Namespace enabled should be false in case config is set to false") | ||
.isEqualTo(Trilean.FALSE); | ||
|
||
// In case namespace config is present, same value will be return. | ||
Assertions.assertThat(abfs.getIsNamespaceEnabled(getTestTracingContext(abfs, false))) | ||
.describedAs("getIsNamespaceEnabled() should return false when config is set to false") | ||
.isEqualTo(false); | ||
|
||
// In case namespace config is present, same value will be return. | ||
Assertions.assertThat(abfs.getAbfsClient().getIsNamespaceEnabled()) | ||
.describedAs("Client's getIsNamespaceEnabled() should return false when config is set to false") | ||
.isEqualTo(false); | ||
} | ||
|
||
private void assertFileSystemInitWithExpectedHNSSettings( | ||
Configuration configuration, boolean expectedIsHnsEnabledValue) throws IOException { | ||
try (AzureBlobFileSystem fs = (AzureBlobFileSystem) FileSystem.newInstance(configuration)) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be setting this value on abfsconfiguration object only when we know the exact value. Do we really need this to be Trilean? I think we should pass the definitive argument and do the Boolean to Trilean conversion here just to make sure that no one accidently sets UNKNOWN here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sense, made changes accordingly.