Skip to content

Commit

Permalink
Pass down hns enabled or not info to client (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
anmolanmol1234 authored Dec 2, 2024
1 parent 79422c9 commit 2377397
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ public void initialize(URI uri, Configuration configuration)
}
}
}
getAbfsStore().updateClientWithNamespaceInfo(tracingContext);

/*
* Non-hierarchical-namespace account can not have a customer-provided-key(CPK).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,18 @@ 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);
getClient().setIsNamespaceEnabled(isNamespaceEnabled);
}

/**
* Checks if the given key in Azure Storage should be stored as a page
* blob instead of block blob.
Expand Down Expand Up @@ -664,7 +676,7 @@ public OutputStream createFile(final Path path,
isAppendBlob,
null,
contextEncryptionAdapter,
tracingContext, isNamespaceEnabled);
tracingContext);

}
perfInfo.registerResult(op.getResult()).registerSuccess(true);
Expand Down Expand Up @@ -708,7 +720,7 @@ private AbfsRestOperation conditionalCreateOverwriteFile(final String relativePa
// of create file traffic falls into the case of no pre-existing file).
op = createClient.createPath(relativePath, true, false, permissions,
isAppendBlob, null, contextEncryptionAdapter,
tracingContext, getIsNamespaceEnabled(tracingContext));
tracingContext);

} catch (AbfsRestOperationException e) {
if (e.getStatusCode() == HttpURLConnection.HTTP_CONFLICT) {
Expand All @@ -733,7 +745,7 @@ private AbfsRestOperation conditionalCreateOverwriteFile(final String relativePa
// overwrite only if eTag matches with the file properties fetched befpre
op = createClient.createPath(relativePath, true, true, permissions,
isAppendBlob, eTag, contextEncryptionAdapter,
tracingContext, getIsNamespaceEnabled(tracingContext));
tracingContext);
} catch (AbfsRestOperationException ex) {
if (ex.getStatusCode() == HttpURLConnection.HTTP_PRECON_FAILED) {
// Is a parallel access case, as file with eTag was just queried
Expand Down Expand Up @@ -839,7 +851,7 @@ public void createDirectory(final Path path, final FsPermission permission,
permission, umask);
final AbfsRestOperation op = createClient.createPath(getRelativePath(path),
false, overwrite, permissions, false, null, null,
tracingContext, isNamespaceEnabled);
tracingContext);
perfInfo.registerResult(op.getResult()).registerSuccess(true);
}
}
Expand Down Expand Up @@ -1097,11 +1109,9 @@ public boolean rename(final Path source,

do {
try (AbfsPerfInfo perfInfo = startTracking("rename", "renamePath")) {
boolean isNamespaceEnabled = getIsNamespaceEnabled(tracingContext);
final AbfsClientRenameResult abfsClientRenameResult =
getClient().renamePath(sourceRelativePath, destinationRelativePath,
continuation, tracingContext, sourceEtag, false,
isNamespaceEnabled);
continuation, tracingContext, sourceEtag, false);


AbfsRestOperation op = abfsClientRenameResult.getOp();
Expand Down Expand Up @@ -1148,7 +1158,7 @@ public void delete(final Path path, final boolean recursive,
do {
try (AbfsPerfInfo perfInfo = startTracking("delete", "deletePath")) {
AbfsRestOperation op = getClient().deletePath(relativePath, recursive,
continuation, tracingContext, getIsNamespaceEnabled(tracingContext));
continuation, tracingContext);
/*
* Blob endpoint does not have a directory delete API. The AbfsBlobClient would
* perform multiple operation to delete a path, hence, the client would not return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,11 @@ public AbfsRestOperation createPath(final String path,
final boolean isAppendBlob,
final String eTag,
final ContextEncryptionAdapter contextEncryptionAdapter,
final TracingContext tracingContext, final boolean isNamespaceEnabled)
final TracingContext tracingContext)
throws AzureBlobFileSystemException {
return createPath(path, isFile, overwrite, permissions, isAppendBlob,
eTag,
contextEncryptionAdapter, tracingContext, isNamespaceEnabled, false);
contextEncryptionAdapter, tracingContext, false);
}

@VisibleForTesting
Expand All @@ -405,10 +405,9 @@ public AbfsRestOperation createPath(final String path,
final String eTag,
final ContextEncryptionAdapter contextEncryptionAdapter,
final TracingContext tracingContext,
final boolean isNamespaceEnabled,
boolean isCreateCalledFromMarkers) throws AzureBlobFileSystemException {
final List<AbfsHttpHeader> requestHeaders = createDefaultHeaders();
if (!isNamespaceEnabled && !isCreateCalledFromMarkers) {
if (!getIsNamespaceEnabled() && !isCreateCalledFromMarkers) {
AbfsHttpOperation op1Result = null;
try {
op1Result = getPathStatus(path, tracingContext,
Expand All @@ -432,7 +431,7 @@ public AbfsRestOperation createPath(final String path,
Path parentPath = new Path(path).getParent();
if (parentPath != null && !parentPath.isRoot()) {
createMarkers(parentPath, overwrite, permissions, isAppendBlob, eTag,
contextEncryptionAdapter, tracingContext, isNamespaceEnabled);
contextEncryptionAdapter, tracingContext);
}
}
if (isFile) {
Expand Down Expand Up @@ -506,13 +505,13 @@ private void createMarkers(final Path path,
final boolean isAppendBlob,
final String eTag,
final ContextEncryptionAdapter contextEncryptionAdapter,
final TracingContext tracingContext, final boolean isNamespaceEnabled) throws AzureBlobFileSystemException {
final TracingContext tracingContext) throws AzureBlobFileSystemException {
ArrayList<Path> keysToCreateAsFolder = new ArrayList<>();
checkParentChainForFile(path, tracingContext,
keysToCreateAsFolder);
for (Path pathToCreate : keysToCreateAsFolder) {
createPath(pathToCreate.toUri().getPath(), false, overwrite, permissions,
isAppendBlob, eTag, contextEncryptionAdapter, tracingContext, isNamespaceEnabled, true);
isAppendBlob, eTag, contextEncryptionAdapter, tracingContext, true);
}
}

Expand Down Expand Up @@ -844,7 +843,6 @@ public AbfsRestOperation breakLease(final String path,
* @param sourceEtag etag of source file. may be null or empty
* @param isMetadataIncompleteState was there a rename failure due to
* incomplete metadata state?
* @param isNamespaceEnabled whether namespace enabled account or not
*
* @return AbfsClientRenameResult result of rename operation indicating the
* AbfsRest operation, rename recovery and incomplete metadata state failure.
Expand All @@ -857,8 +855,7 @@ public AbfsClientRenameResult renamePath(final String source,
final String continuation,
final TracingContext tracingContext,
String sourceEtag,
boolean isMetadataIncompleteState,
boolean isNamespaceEnabled)
boolean isMetadataIncompleteState)
throws IOException {
BlobRenameHandler blobRenameHandler = getBlobRenameHandler(source,
destination, sourceEtag, isAtomicRenameKey(source), tracingContext
Expand Down Expand Up @@ -1252,16 +1249,14 @@ public AbfsRestOperation getPathStatus(final String path,
* @param recursive if the path is a directory, delete recursively.
* @param continuation to specify continuation token.
* @param tracingContext
* @param isNamespaceEnabled
* @return executed rest operation containing response from server.
* @throws AzureBlobFileSystemException if rest operation fails.
*/
@Override
public AbfsRestOperation deletePath(final String path,
final boolean recursive,
final String continuation,
final TracingContext tracingContext,
final boolean isNamespaceEnabled) throws AzureBlobFileSystemException {
final TracingContext tracingContext) throws AzureBlobFileSystemException {
getBlobDeleteHandler(path, recursive, tracingContext).execute();
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public abstract class AbfsClient implements Closeable {
private KeepAliveCache keepAliveCache;

private AbfsApacheHttpClient abfsApacheHttpClient;
private static boolean isNamespaceEnabled = false;

/**
* logging the rename failure if metadata is in an incomplete state.
Expand Down Expand Up @@ -475,7 +476,7 @@ public abstract AbfsRestOperation createPath(final String path,
final boolean isAppendBlob,
final String eTag,
final ContextEncryptionAdapter contextEncryptionAdapter,
final TracingContext tracingContext, boolean isNamespaceEnabled) throws AzureBlobFileSystemException;
final TracingContext tracingContext) throws AzureBlobFileSystemException;

/**
* Performs a pre-check for a createNonRecursive operation. Checks if parentPath
Expand Down Expand Up @@ -539,7 +540,7 @@ public abstract AbfsRestOperation breakLease(final String path,
* @param sourceEtag etag of source file. may be null or empty
* @param isMetadataIncompleteState was there a rename failure due to
* incomplete metadata state?
* @param isNamespaceEnabled whether namespace enabled account or not
* @return AbfsClientRenameResult result of rename operation indicating the
* AbfsRest operation, rename recovery and incomplete metadata state failure.
* @throws AzureBlobFileSystemException failure, excluding any recovery from overload failures.
Expand All @@ -550,8 +551,7 @@ public abstract AbfsClientRenameResult renamePath(
final String continuation,
final TracingContext tracingContext,
String sourceEtag,
boolean isMetadataIncompleteState,
boolean isNamespaceEnabled) throws IOException;
boolean isMetadataIncompleteState) throws IOException;

public abstract boolean checkIsDir(AbfsHttpOperation result);

Expand Down Expand Up @@ -725,8 +725,7 @@ public abstract AbfsRestOperation read(final String path,
public abstract AbfsRestOperation deletePath(final String path,
final boolean recursive,
final String continuation,
TracingContext tracingContext,
final boolean isNamespaceEnabled)
TracingContext tracingContext)
throws AzureBlobFileSystemException;

/**
Expand Down Expand Up @@ -1416,4 +1415,12 @@ public abstract Hashtable<String, String> getXMSProperties(AbfsHttpOperation res
public abstract byte[] encodeAttribute(String value) throws UnsupportedEncodingException;

public abstract String decodeAttribute(byte[] value) throws UnsupportedEncodingException;

public boolean getIsNamespaceEnabled() {
return isNamespaceEnabled;
}

public void setIsNamespaceEnabled(final boolean namespaceEnabled) {
isNamespaceEnabled = namespaceEnabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public AbfsRestOperation createPath(final String path,
final boolean isAppendBlob,
final String eTag,
final ContextEncryptionAdapter contextEncryptionAdapter,
final TracingContext tracingContext, final boolean isNamespaceEnabled)
final TracingContext tracingContext)
throws AzureBlobFileSystemException {
final List<AbfsHttpHeader> requestHeaders = createDefaultHeaders();
if (isFile) {
Expand Down Expand Up @@ -526,7 +526,7 @@ public AbfsRestOperation breakLease(final String path, TracingContext tracingCon
* @param sourceEtag etag of source file. may be null or empty
* @param isMetadataIncompleteState was there a rename failure due to
* incomplete metadata state?
* @param isNamespaceEnabled whether namespace enabled account or not
*
* @return AbfsClientRenameResult result of rename operation indicating the
* AbfsRest operation, rename recovery and incomplete metadata state failure.
Expand All @@ -540,14 +540,13 @@ public AbfsClientRenameResult renamePath(
final String continuation,
final TracingContext tracingContext,
String sourceEtag,
boolean isMetadataIncompleteState,
boolean isNamespaceEnabled)
boolean isMetadataIncompleteState)
throws IOException {
final List<AbfsHttpHeader> requestHeaders = createDefaultHeaders();

final boolean hasEtag = !isEmpty(sourceEtag);

boolean shouldAttemptRecovery = renameResilience && isNamespaceEnabled;
boolean shouldAttemptRecovery = renameResilience && getIsNamespaceEnabled();
if (!hasEtag && shouldAttemptRecovery) {
// in case eTag is already not supplied to the API
// and rename resilience is expected and it is an HNS enabled account
Expand Down Expand Up @@ -626,7 +625,7 @@ public AbfsClientRenameResult renamePath(
sourceEtagAfterFailure = extractEtagHeader(sourceStatusResult);
}
renamePath(source, destination, continuation, tracingContext,
sourceEtagAfterFailure, isMetadataIncompleteState, isNamespaceEnabled);
sourceEtagAfterFailure, isMetadataIncompleteState);
}
// if we get out of the condition without a successful rename, then
// it isn't metadata incomplete state issue.
Expand Down Expand Up @@ -989,15 +988,13 @@ public AbfsRestOperation read(final String path,
* @param recursive if the path is a directory, delete recursively.
* @param continuation to specify continuation token.
* @param tracingContext
* @param isNamespaceEnabled
* @return executed rest operation containing response from server.
* @throws AzureBlobFileSystemException if rest operation fails.
*/
@Override
public AbfsRestOperation deletePath(final String path, final boolean recursive,
final String continuation,
TracingContext tracingContext,
final boolean isNamespaceEnabled)
TracingContext tracingContext)
throws AzureBlobFileSystemException {
/*
* If Pagination is enabled and current API version is old,
Expand All @@ -1007,13 +1004,13 @@ public AbfsRestOperation deletePath(final String path, final boolean recursive,
* If pagination is disabled, use the current API version only.
*/
final List<AbfsHttpHeader> requestHeaders = (isPaginatedDelete(recursive,
isNamespaceEnabled) && xMsVersion.compareTo(
getIsNamespaceEnabled()) && xMsVersion.compareTo(
AbfsHttpConstants.ApiVersion.AUG_03_2023) < 0)
? createDefaultHeaders(AbfsHttpConstants.ApiVersion.AUG_03_2023)
: createDefaultHeaders();
final AbfsUriQueryBuilder abfsUriQueryBuilder = createDefaultUriQueryBuilder();

if (isPaginatedDelete(recursive, isNamespaceEnabled)) {
if (isPaginatedDelete(recursive, getIsNamespaceEnabled())) {
// Add paginated query parameter
abfsUriQueryBuilder.addQuery(QUERY_PARAM_PAGINATED, TRUE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,11 @@ private AbfsRestOperation callOperation(AzureBlobFileSystem fs,
case RENAME:
TracingContext tc = getTestTracingContext(fs, true);
return client.renamePath(path, new Path(path + "_2").toString(),
null, tc, null, false, fs.getIsNamespaceEnabled(tc)).getOp();
null, tc, null, false).getOp();
case DELETE:
TracingContext testTC = getTestTracingContext(fs, false);
return client.deletePath(path, false, null,
testTC, fs.getIsNamespaceEnabled(testTC));
testTC);
case GET_ATTR:
return client.getPathStatus(path, true,
getTestTracingContext(fs, false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public void testCreateOverDfsAppendOverBlob() throws IOException {
fs.getAbfsStore().getClientHandler().getDfsClient().
createPath(makeQualified(TEST_FILE_PATH).toUri().getPath(), true, false,
permissions, false, null,
null, getTestTracingContext(fs, true), getIsNamespaceEnabled(fs));
null, getTestTracingContext(fs, true));
fs.getAbfsStore()
.getAbfsConfiguration()
.set(FS_AZURE_INGRESS_SERVICE_TYPE, AbfsServiceType.BLOB.name());
Expand Down Expand Up @@ -265,7 +265,7 @@ public void testCreateOverBlobAppendOverDfs() throws IOException {
fs.getAbfsStore().getClientHandler().getBlobClient().
createPath(makeQualified(TEST_FILE_PATH).toUri().getPath(), true, false,
permissions, false, null,
null, getTestTracingContext(fs, true), getIsNamespaceEnabled(fs));
null, getTestTracingContext(fs, true));
FSDataOutputStream outputStream = fs.append(TEST_FILE_PATH);
outputStream.write(10);
outputStream.hsync();
Expand Down Expand Up @@ -310,7 +310,7 @@ public void testCreateAppendBlobOverBlobEndpointAppendOverDfs()
fs.getAbfsStore().getClientHandler().getBlobClient().
createPath(makeQualified(TEST_FILE_PATH).toUri().getPath(), true, false,
permissions, true, null,
null, getTestTracingContext(fs, true), getIsNamespaceEnabled(fs));
null, getTestTracingContext(fs, true));
FSDataOutputStream outputStream = fs.append(TEST_FILE_PATH);
outputStream.write(10);
outputStream.hsync();
Expand Down Expand Up @@ -348,7 +348,7 @@ public void testCreateAppendBlobOverDfsEndpointAppendOverBlob()
fs.getAbfsStore().getClientHandler().getDfsClient().
createPath(makeQualified(TEST_FILE_PATH).toUri().getPath(), true, false,
permissions, true, null,
null, getTestTracingContext(fs, true), getIsNamespaceEnabled(fs));
null, getTestTracingContext(fs, true));
fs.getAbfsStore()
.getAbfsConfiguration()
.set(FS_AZURE_INGRESS_SERVICE_TYPE, AbfsServiceType.BLOB.name());
Expand Down Expand Up @@ -451,7 +451,7 @@ public void testCreateExplicitDirectoryOverDfsAppendOverBlob()
fs.getAbfsStore().getClientHandler().getDfsClient().
createPath(makeQualified(folderPath).toUri().getPath(), false, false,
permissions, false, null,
null, getTestTracingContext(fs, true), getIsNamespaceEnabled(fs));
null, getTestTracingContext(fs, true));
FSDataOutputStream outputStream = fs.append(folderPath);
outputStream.write(10);
outputStream.hsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ public void testNegativeScenariosForCreateOverwriteDisabled()
.when(mockClient)
.createPath(any(String.class), eq(true), eq(false),
any(AzureBlobFileSystemStore.Permissions.class), any(boolean.class), eq(null), any(),
any(TracingContext.class), any(boolean.class));
any(TracingContext.class));

doThrow(fileNotFoundResponseEx) // Scn1: GFS fails with Http404
.doThrow(serverErrorResponseEx) // Scn2: GFS fails with Http500
Expand All @@ -483,7 +483,7 @@ public void testNegativeScenariosForCreateOverwriteDisabled()
.when(mockClient)
.createPath(any(String.class), eq(true), eq(true),
any(AzureBlobFileSystemStore.Permissions.class), any(boolean.class), eq(null), any(),
any(TracingContext.class), any(boolean.class));
any(TracingContext.class));

// Scn1: GFS fails with Http404
// Sequence of events expected:
Expand Down Expand Up @@ -1346,7 +1346,7 @@ public void testImplicitExplicitFolder() throws Exception {
AbfsBlobClient blobClient = (AbfsBlobClient) fs.getAbfsStore().getClient(AbfsServiceType.BLOB);
blobClient.createPath(path.toUri().getPath(), false, true,
null, false, null, null, getTestTracingContext(fs, true),
true, true);
true);

fs.mkdirs(new Path("a/b/c/d"));

Expand Down
Loading

0 comments on commit 2377397

Please sign in to comment.