anmolanmol1234 commented on code in PR #7265:
URL: https://github.com/apache/hadoop/pull/7265#discussion_r1912744844
##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsBlobClient.java:
##########
@@ -1318,6 +1421,128 @@ public static String getDirectoryQueryParameter(final
String path) {
return directory;
}
+ public boolean isAtomicRenameKey(String key) {
+ return isKeyForDirectorySet(key, azureAtomicRenameDirSet);
+ }
+
+ /**
+ * Action to be taken when atomic-key is present on a getPathStatus path.
+ *
+ * @param path path of the pendingJson for the atomic path.
+ * @param pathLease lease on the path.
+ * @param tracingContext tracing context.
+ *
+ * @throws AzureBlobFileSystemException server error or the path is
renamePending json file and action is taken.
+ */
+ public void takeGetPathStatusAtomicRenameKeyAction(final Path path,
+ final AbfsLease pathLease,
+ final TracingContext
tracingContext)
+ throws AzureBlobFileSystemException {
+ if (path == null || path.isRoot() ||
!isAtomicRenameKey(path.toUri().getPath())) {
+ return;
+ }
+ AbfsRestOperation pendingJsonFileStatus;
+ Path pendingJsonPath = new Path(path.getParent(),
+ path.toUri().getPath() + RenameAtomicity.SUFFIX);
+ try {
+ pendingJsonFileStatus = getPathStatus(
+ pendingJsonPath.toUri().getPath(), tracingContext, null, false);
+ if (checkIsDir(pendingJsonFileStatus.getResult())) {
+ return;
+ }
+ } catch (AbfsRestOperationException ex) {
+ if (ex.getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND) {
+ return;
+ }
+ throw ex;
+ }
+
+ boolean renameSrcHasChanged;
+ try {
+ RenameAtomicity renameAtomicity = getRedoRenameAtomicity(
+ pendingJsonPath,
Integer.parseInt(pendingJsonFileStatus.getResult()
+
.getResponseHeader(HttpHeaderConfigurations.CONTENT_LENGTH)),
+ tracingContext, pathLease);
+ renameAtomicity.redo();
+ renameSrcHasChanged = false;
+ } catch (AbfsRestOperationException ex) {
+ /*
+ * At this point, the source marked by the renamePending json file,
might have
+ * already got renamed by some parallel thread, or at this point, the
path
+ * would have got modified which would result in eTag change, which
would lead
+ * to a HTTP_CONFLICT. In this case, no more operation needs to be
taken, and
+ * the calling getPathStatus can return this source path as result.
+ */
+ if (ex.getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND
+ || ex.getStatusCode() == HttpURLConnection.HTTP_CONFLICT) {
+ renameSrcHasChanged = true;
+ } else {
+ throw ex;
+ }
+ }
+ if (!renameSrcHasChanged) {
+ throw new AbfsRestOperationException(
+ AzureServiceErrorCode.PATH_NOT_FOUND.getStatusCode(),
+ AzureServiceErrorCode.PATH_NOT_FOUND.getErrorCode(),
+ ATOMIC_DIR_RENAME_RECOVERY_ON_GET_PATH_EXCEPTION,
+ null);
+ }
+ }
+
+ /**
+ * Action to be taken when atomic-key is present on a listPath path.
+ *
+ * @param path path of the pendingJson for the atomic path.
+ * @param renamePendingJsonLen length of the pendingJson file.
+ * @param tracingContext tracing context.
+ *
+ * @return true if action is taken.
+ * @throws AzureBlobFileSystemException server error
+ */
+ private boolean takeListPathAtomicRenameKeyAction(final Path path,
+ final int
renamePendingJsonLen,
+ final TracingContext
tracingContext)
+ throws AzureBlobFileSystemException {
+ if (path == null || path.isRoot() || !isAtomicRenameKey(
+ path.toUri().getPath()) || !path.toUri()
+ .getPath()
+ .endsWith(RenameAtomicity.SUFFIX)) {
+ return false;
+ }
+ try {
+ RenameAtomicity renameAtomicity
+ = getRedoRenameAtomicity(path, renamePendingJsonLen,
+ tracingContext, null);
+ renameAtomicity.redo();
+ } catch (AbfsRestOperationException ex) {
+ /*
+ * At this point, the source marked by the renamePending json file,
might have
+ * already got renamed by some parallel thread, or at this point, the
path
+ * would have got modified which would result in eTag change, which
would lead
+ * to a HTTP_CONFLICT. In this case, no more operation needs to be
taken, but
+ * since this is a renamePendingJson file and would be deleted by the
redo operation,
+ * the calling listPath should not return this json path as result.
+ */
+ if (ex.getStatusCode() != HttpURLConnection.HTTP_NOT_FOUND
+ && ex.getStatusCode() != HttpURLConnection.HTTP_CONFLICT) {
+ throw ex;
+ }
+ }
+ return true;
Review Comment:
why are we directly returning true here and not checking for
renameSrchasChanged as in the previous method ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]