Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import static org.apache.hadoop.fs.azurebfs.AbfsStatistic.DIRECTORIES_CREATED;
import static org.apache.hadoop.fs.azurebfs.AbfsStatistic.DIRECTORIES_DELETED;
import static org.apache.hadoop.fs.azurebfs.AbfsStatistic.ERROR_IGNORED;
import static org.apache.hadoop.fs.azurebfs.AbfsStatistic.FILES_COPIED;
import static org.apache.hadoop.fs.azurebfs.AbfsStatistic.FILES_CREATED;
import static org.apache.hadoop.fs.azurebfs.AbfsStatistic.FILES_DELETED;
import static org.apache.hadoop.fs.azurebfs.AbfsStatistic.GET_RESPONSES;
Expand Down Expand Up @@ -134,7 +135,8 @@ public class AbfsCountersImpl implements AbfsCounters {
SERVER_UNAVAILABLE,
RENAME_RECOVERY,
METADATA_INCOMPLETE_RENAME_FAILURES,
RENAME_PATH_ATTEMPTS
RENAME_PATH_ATTEMPTS,
FILES_COPIED
};

private static final AbfsStatistic[] DURATION_TRACKER_LIST = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ public enum AbfsStatistic {
"Number of times rename operation failed due to metadata being "
+ "incomplete"),
RENAME_PATH_ATTEMPTS("rename_path_attempts",
"Number of times we attempt to rename a path internally");
"Number of times we attempt to rename a path internally"),
FILES_COPIED("files_copied",
"Total number of files copied from the object store.");

private String statName;
private String statDescription;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -993,8 +993,6 @@ public Void call() throws Exception {
delete(fs.getPath(), fs.isDirectory());
if (fs.isDirectory()) {
statIncrement(DIRECTORIES_DELETED);
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should call incrementAbfsDeleteFile ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are incrementing Delete Files in Client.

statIncrement(FILES_DELETED);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public enum AzureServiceErrorCode {
OTHER_SERVER_THROTTLING("ServerBusy", HttpURLConnection.HTTP_UNAVAILABLE,
"The server is currently unable to receive requests. Please retry your request."),
INVALID_QUERY_PARAMETER_VALUE("InvalidQueryParameterValue", HttpURLConnection.HTTP_BAD_REQUEST, null),
INVALID_RENAME_DESTINATION("InvalidRenameDestinationPath", HttpURLConnection.HTTP_BAD_REQUEST, null),
AUTHORIZATION_PERMISSION_MISS_MATCH("AuthorizationPermissionMismatch", HttpURLConnection.HTTP_FORBIDDEN, null),
ACCOUNT_REQUIRES_HTTPS("AccountRequiresHttps", HttpURLConnection.HTTP_BAD_REQUEST, null),
MD5_MISMATCH("Md5Mismatch", HttpURLConnection.HTTP_BAD_REQUEST,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
import static java.net.HttpURLConnection.HTTP_OK;
import static java.net.HttpURLConnection.HTTP_PRECON_FAILED;
import static org.apache.hadoop.fs.azurebfs.AzureBlobFileSystemStore.extractEtagHeader;
import static org.apache.hadoop.fs.azurebfs.AbfsStatistic.CALL_GET_FILE_STATUS;
import static org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants.ACQUIRE_LEASE_ACTION;
import static org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants.AND_MARK;
import static org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants.APPEND_BLOB_TYPE;
Expand Down Expand Up @@ -424,7 +423,7 @@ private void fixAtomicEntriesInListResults(final AbfsRestOperation op,
}
List<BlobListResultEntrySchema> filteredEntries = new ArrayList<>();
for (BlobListResultEntrySchema entry : listResultSchema.paths()) {
if (!takeListPathAtomicRenameKeyAction(entry.path(),
if (!takeListPathAtomicRenameKeyAction(entry.path(), entry.isDirectory(),
entry.contentLength().intValue(), tracingContext)) {
filteredEntries.add(entry);
}
Expand All @@ -444,15 +443,14 @@ public void createNonRecursivePreCheck(Path parentPath,
}
getPathStatus(parentPath.toUri().getPath(), false,
tracingContext, null);
incrementAbfsGetPathStatus();
} catch (AbfsRestOperationException ex) {
if (ex.getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new FileNotFoundException("Cannot create file "
+ parentPath.toUri().getPath()
+ " because parent folder does not exist.");
}
throw ex;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The increase will not get implemented if getPathStatus call fails

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved it to finally block

} finally {
getAbfsCounters().incrementCounter(CALL_GET_FILE_STATUS, 1);
}
}

Expand Down Expand Up @@ -510,6 +508,7 @@ protected AbfsRestOperation createMarkerAtPath(final String path,
final String eTag,
final ContextEncryptionAdapter contextEncryptionAdapter,
final TracingContext tracingContext) throws AzureBlobFileSystemException {
incrementAbfsCreateFile();
return createPathRestOp(path, false, false, false, eTag,
contextEncryptionAdapter, tracingContext);
}
Expand Down Expand Up @@ -807,7 +806,6 @@ public AbfsClientRenameResult renamePath(final String source,
BlobRenameHandler blobRenameHandler = getBlobRenameHandler(source,
destination, sourceEtag, isAtomicRenameKey(source), tracingContext
);
incrementAbfsRenamePath();
if (blobRenameHandler.execute()) {
final AbfsUriQueryBuilder abfsUriQueryBuilder
= createDefaultUriQueryBuilder();
Expand Down Expand Up @@ -1751,6 +1749,7 @@ public void takeGetPathStatusAtomicRenameKeyAction(final Path path,
pendingJsonFileStatus = getPathStatus(
pendingJsonPath.toUri().getPath(), tracingContext,
null, false);
incrementAbfsGetPathStatus();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some places we are incrementing before the operation and at some places after the operation is executed, we must keep it consitent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this call in finally block everywhere.

if (checkIsDir(pendingJsonFileStatus.getResult())) {
return;
}
Expand Down Expand Up @@ -1805,11 +1804,11 @@ public void takeGetPathStatusAtomicRenameKeyAction(final Path path,
* @throws AzureBlobFileSystemException server error
*/
private boolean takeListPathAtomicRenameKeyAction(final Path path,
final int renamePendingJsonLen,
final boolean isDirectory, final int renamePendingJsonLen,
final TracingContext tracingContext)
throws AzureBlobFileSystemException {
if (path == null || path.isRoot() || !isAtomicRenameKey(
path.toUri().getPath()) || !path.toUri()
path.toUri().getPath()) || isDirectory || !path.toUri()
.getPath()
.endsWith(RenameAtomicity.SUFFIX)) {
return false;
Expand Down Expand Up @@ -1837,7 +1836,7 @@ private boolean takeListPathAtomicRenameKeyAction(final Path path,
}

@VisibleForTesting
RenameAtomicity getRedoRenameAtomicity(final Path renamePendingJsonPath,
public RenameAtomicity getRedoRenameAtomicity(final Path renamePendingJsonPath,
int fileLen,
final TracingContext tracingContext) {
return new RenameAtomicity(renamePendingJsonPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@
import org.apache.hadoop.util.concurrent.HadoopExecutors;

import static org.apache.commons.lang3.StringUtils.isNotEmpty;
import static org.apache.hadoop.fs.azurebfs.AbfsStatistic.CALL_GET_FILE_STATUS;
import static org.apache.hadoop.fs.azurebfs.AbfsStatistic.FILES_COPIED;
import static org.apache.hadoop.fs.azurebfs.AbfsStatistic.FILES_CREATED;
import static org.apache.hadoop.fs.azurebfs.AbfsStatistic.FILES_DELETED;
import static org.apache.hadoop.fs.azurebfs.AbfsStatistic.RENAME_PATH_ATTEMPTS;
import static org.apache.hadoop.fs.azurebfs.AzureBlobFileSystemStore.extractEtagHeader;
import static org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants.APN_VERSION;
Expand Down Expand Up @@ -693,6 +697,34 @@ protected void incrementAbfsRenamePath() {
abfsCounters.incrementCounter(RENAME_PATH_ATTEMPTS, 1);
}

/**
* Increments AbfsCounters for get path status by 1.
*/
protected void incrementAbfsGetPathStatus() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

counter increment should not be in abfsclient class in my opinion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, this is just a placeholder so that we can use the same method in both DFS and Blob client.

abfsCounters.incrementCounter(CALL_GET_FILE_STATUS, 1);
}

/**
* Increments AbfsCounters for Delete File by 1.
*/
protected void incrementAbfsDeleteFile() {
abfsCounters.incrementCounter(FILES_DELETED, 1);
}

/**
* Increments AbfsCounters for Create File by 1.
*/
protected void incrementAbfsCreateFile() {
abfsCounters.incrementCounter(FILES_CREATED, 1);
}

/**
* Increments AbfsCounters for Copy Files by 1.
*/
protected void incrementAbfsCopyFile() {
abfsCounters.incrementCounter(FILES_COPIED, 1);
}

/**
* Check if the rename request failure is post a retry and if earlier rename
* request might have succeeded at back-end.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,8 @@ public AbfsRestOperation deletePath(final String path,
} else {
return idempotencyOp;
}
} finally {
incrementAbfsDeleteFile();
}

return op;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ int getMaxConsumptionParallelism() {
private boolean deleteInternal(final Path path)
throws AzureBlobFileSystemException {
getAbfsClient().deleteBlobPath(path, null, tracingContext);
getAbfsClient().incrementAbfsDeleteFile();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to finally block

deleteCount.incrementAndGet();
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

import org.apache.hadoop.classification.VisibleForTesting;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.PathIOException;
import org.apache.hadoop.fs.azurebfs.contracts.exceptions.AbfsRestOperationException;
import org.apache.hadoop.fs.azurebfs.contracts.exceptions.AzureBlobFileSystemException;
import org.apache.hadoop.fs.azurebfs.contracts.exceptions.TimeoutException;
Expand Down Expand Up @@ -121,6 +120,7 @@ int getMaxConsumptionParallelism() {
* @throws AzureBlobFileSystemException if server call fails
*/
public boolean execute() throws AzureBlobFileSystemException {
getAbfsClient().incrementAbfsRenamePath();
PathInformation pathInformation = getPathInformation(src, tracingContext);
boolean result = false;
if (preCheck(src, dst, pathInformation)) {
Expand Down Expand Up @@ -257,36 +257,14 @@ private boolean containsColon(Path p) {
private boolean preCheck(final Path src, final Path dst,
final PathInformation pathInformation)
throws AzureBlobFileSystemException {
validateDestinationPath(src, dst);
validateDestinationIsNotSubDir(src, dst);
validateSourcePath(pathInformation);
validateDestinationPathNotExist(src, dst, pathInformation);
validateDestinationParentExist(src, dst, pathInformation);

return true;
}

/**
* Validate if the format of the destination path is correct and if the destination
* path is not a sub-directory of the source path.
*
* @param src source path
* @param dst destination path
*
* @throws AbfsRestOperationException if the destination path is invalid
*/
private void validateDestinationPath(final Path src, final Path dst)
throws AbfsRestOperationException {
if (containsColon(dst)) {
throw new AbfsRestOperationException(
HttpURLConnection.HTTP_BAD_REQUEST,
AzureServiceErrorCode.INVALID_RENAME_DESTINATION.getErrorCode(), null,
new PathIOException(dst.toUri().getPath(),
"Destination path contains colon"));
}

validateDestinationIsNotSubDir(src, dst);
}

/**
* Validate if the destination path is not a sub-directory of the source path.
*
Expand Down Expand Up @@ -439,7 +417,9 @@ private boolean renameInternal(final Path path,
boolean operated = false;
try {
copyPath(path, destinationPathForBlobPartOfRenameSrcDir, leaseId);
getAbfsClient().incrementAbfsCopyFile();
getAbfsClient().deleteBlobPath(path, leaseId, tracingContext);
getAbfsClient().incrementAbfsDeleteFile();
operated = true;
} finally {
if (abfsLease != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.hadoop.fs.azurebfs.AbfsConfiguration;
import org.apache.hadoop.fs.azurebfs.contracts.exceptions.AbfsRestOperationException;
import org.apache.hadoop.fs.azurebfs.contracts.exceptions.AzureBlobFileSystemException;
import org.apache.hadoop.fs.azurebfs.contracts.exceptions.FileSystemOperationUnhandledException;
import org.apache.hadoop.fs.azurebfs.contracts.exceptions.InvalidConfigurationValueException;
import org.apache.hadoop.fs.azurebfs.contracts.services.BlobListResultSchema;
import org.apache.hadoop.fs.azurebfs.contracts.services.ListResultEntrySchema;
Expand Down Expand Up @@ -119,7 +120,14 @@ private boolean takeAction(List<Path> paths)
LOG.debug("Thread interrupted while taking action on path: {}",
path.toUri().getPath());
} catch (ExecutionException e) {
executionException = (AzureBlobFileSystemException) e.getCause();
LOG.debug("Execution exception while taking action on path: {}",
path.toUri().getPath());
if (e.getCause() instanceof AzureBlobFileSystemException) {
executionException = (AzureBlobFileSystemException) e.getCause();
} else {
executionException =
new FileSystemOperationUnhandledException(executionException);
}
}
}
if (executionException != null) {
Expand Down Expand Up @@ -261,7 +269,7 @@ protected String listAndEnqueue(final ListBlobQueue listBlobQueue,
protected void addPaths(final List<Path> paths,
final ListResultSchema retrievedSchema) {
for (ListResultEntrySchema entry : retrievedSchema.paths()) {
Path entryPath = new Path(ROOT_PATH, entry.name());
Path entryPath = new Path(ROOT_PATH + entry.name());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed offline, this change is needed because of new Path() behavior in hadoop common.

if (!entryPath.equals(this.path)) {
paths.add(entryPath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ public int preRename() throws AzureBlobFileSystemException {
}
}
throw e;
} finally {
abfsClient.incrementAbfsCreateFile();
}
}

Expand Down Expand Up @@ -310,6 +312,8 @@ private void deleteRenamePendingJson() throws AzureBlobFileSystemException {
return;
}
throw e;
} finally {
abfsClient.incrementAbfsDeleteFile();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,13 @@ private static String replacedUrl(String baseUrl, String oldString, String newSt
*/
public static boolean isKeyForDirectorySet(String key, Set<String> dirSet) {
for (String dir : dirSet) {
if (dir.isEmpty() || key.startsWith(
dir + AbfsHttpConstants.FORWARD_SLASH)) {
// Ensure the directory ends with a forward slash
if (StringUtils.isNotEmpty(dir)
&& !dir.endsWith(AbfsHttpConstants.FORWARD_SLASH)) {
dir += AbfsHttpConstants.FORWARD_SLASH;
}
// Return true if the directory is empty or the key starts with the directory
if (dir.isEmpty() || key.startsWith(dir)) {
return true;
}

Expand Down
Loading