Skip to content

Commit 73ac0b9

Browse files
HADOOP-19448: [ABFS][FNSOverBlob][Optimizations] Reduce Network Calls In Create and Mkdir Flow (#7353)
Contributed by Anmol Asrani Signed off by: Anuj Modi<[email protected]>
1 parent d552670 commit 73ac0b9

15 files changed

+1839
-991
lines changed

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

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
import org.apache.hadoop.fs.azurebfs.constants.HttpHeaderConfigurations;
7171
import org.apache.hadoop.fs.azurebfs.contracts.exceptions.AbfsRestOperationException;
7272
import org.apache.hadoop.fs.azurebfs.contracts.exceptions.AzureBlobFileSystemException;
73-
import org.apache.hadoop.fs.azurebfs.contracts.exceptions.ConcurrentWriteOperationDetectedException;
7473
import org.apache.hadoop.fs.azurebfs.contracts.exceptions.FileSystemOperationUnhandledException;
7574
import org.apache.hadoop.fs.azurebfs.contracts.exceptions.InvalidAbfsRestOperationException;
7675
import org.apache.hadoop.fs.azurebfs.contracts.exceptions.InvalidFileSystemPropertyException;
@@ -762,53 +761,8 @@ private AbfsRestOperation conditionalCreateOverwriteFile(final String relativePa
762761
final TracingContext tracingContext) throws IOException {
763762
AbfsRestOperation op;
764763
AbfsClient createClient = getClientHandler().getIngressClient();
765-
try {
766-
// Trigger a create with overwrite=false first so that eTag fetch can be
767-
// avoided for cases when no pre-existing file is present (major portion
768-
// of create file traffic falls into the case of no pre-existing file).
769-
op = createClient.createPath(relativePath, true, false, permissions,
770-
isAppendBlob, null, contextEncryptionAdapter, tracingContext);
771-
772-
} catch (AbfsRestOperationException e) {
773-
if (e.getStatusCode() == HttpURLConnection.HTTP_CONFLICT) {
774-
// File pre-exists, fetch eTag
775-
try {
776-
op = getClient().getPathStatus(relativePath, false, tracingContext, null);
777-
} catch (AbfsRestOperationException ex) {
778-
if (ex.getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND) {
779-
// Is a parallel access case, as file which was found to be
780-
// present went missing by this request.
781-
throw new ConcurrentWriteOperationDetectedException(
782-
"Parallel access to the create path detected. Failing request "
783-
+ "to honor single writer semantics");
784-
} else {
785-
throw ex;
786-
}
787-
}
788-
789-
String eTag = extractEtagHeader(op.getResult());
790-
791-
try {
792-
// overwrite only if eTag matches with the file properties fetched befpre
793-
op = createClient.createPath(relativePath, true, true, permissions,
794-
isAppendBlob, eTag, contextEncryptionAdapter, tracingContext);
795-
} catch (AbfsRestOperationException ex) {
796-
if (ex.getStatusCode() == HttpURLConnection.HTTP_PRECON_FAILED) {
797-
// Is a parallel access case, as file with eTag was just queried
798-
// and precondition failure can happen only when another file with
799-
// different etag got created.
800-
throw new ConcurrentWriteOperationDetectedException(
801-
"Parallel access to the create path detected. Failing request "
802-
+ "to honor single writer semantics");
803-
} else {
804-
throw ex;
805-
}
806-
}
807-
} else {
808-
throw e;
809-
}
810-
}
811-
764+
op = createClient.conditionalCreateOverwriteFile(relativePath, statistics,
765+
permissions, isAppendBlob, contextEncryptionAdapter, tracingContext);
812766
return op;
813767
}
814768

hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/contracts/exceptions/ConcurrentWriteOperationDetectedException.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,29 @@
2020

2121
/**
2222
* Thrown when a concurrent write operation is detected.
23+
* This exception is used to indicate that parallel access to the create path
24+
* has been detected, which violates the single writer semantics.
2325
*/
2426
@org.apache.hadoop.classification.InterfaceAudience.Public
2527
@org.apache.hadoop.classification.InterfaceStability.Evolving
2628
public class ConcurrentWriteOperationDetectedException
2729
extends AzureBlobFileSystemException {
2830

31+
private static final String ERROR_MESSAGE = "Parallel access to the create path detected. Failing request "
32+
+ "to honor single writer semantics";
33+
34+
/**
35+
* Constructs a new ConcurrentWriteOperationDetectedException with a default error message.
36+
*/
37+
public ConcurrentWriteOperationDetectedException() {
38+
super(ERROR_MESSAGE);
39+
}
40+
41+
/**
42+
* Constructs a new ConcurrentWriteOperationDetectedException with the specified error message.
43+
*
44+
* @param message the detail message.
45+
*/
2946
public ConcurrentWriteOperationDetectedException(String message) {
3047
super(message);
3148
}

0 commit comments

Comments
 (0)