Skip to content

Commit feeaebe

Browse files
joshelsersteveloughran
authored andcommitted
HADOOP-17934. ABFS: Make sure the AbfsHttpOperation is non-null before using it (#3477)
Contributed by: Josh Elser Change-Id: I24a2e0322d8cae2d72d65c7f3d8a74580a418317
1 parent 31b44c5 commit feeaebe

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.util.concurrent.TimeUnit;
4040

4141
import org.apache.hadoop.thirdparty.com.google.common.annotations.VisibleForTesting;
42+
import org.apache.hadoop.thirdparty.com.google.common.base.Preconditions;
4243
import org.apache.hadoop.thirdparty.com.google.common.base.Strings;
4344
import org.apache.hadoop.thirdparty.com.google.common.util.concurrent.FutureCallback;
4445
import org.apache.hadoop.thirdparty.com.google.common.util.concurrent.Futures;
@@ -383,6 +384,10 @@ public AbfsRestOperation createPath(final String path, final boolean isFile, fin
383384
try {
384385
op.execute(tracingContext);
385386
} catch (AzureBlobFileSystemException ex) {
387+
// If we have no HTTP response, throw the original exception.
388+
if (!op.hasResult()) {
389+
throw ex;
390+
}
386391
if (!isFile && op.getResult().getStatusCode() == HttpURLConnection.HTTP_CONFLICT) {
387392
String existingResource =
388393
op.getResult().getResponseHeader(X_MS_EXISTING_RESOURCE_TYPE);
@@ -506,6 +511,10 @@ public AbfsRestOperation renamePath(String source, final String destination,
506511
try {
507512
op.execute(tracingContext);
508513
} catch (AzureBlobFileSystemException e) {
514+
// If we have no HTTP response, throw the original exception.
515+
if (!op.hasResult()) {
516+
throw e;
517+
}
509518
final AbfsRestOperation idempotencyOp = renameIdempotencyCheckOp(
510519
renameRequestStartTime, op, destination, tracingContext);
511520
if (idempotencyOp.getResult().getStatusCode()
@@ -530,7 +539,7 @@ public AbfsRestOperation renamePath(String source, final String destination,
530539
* the one initiated from this ABFS filesytem instance as it was retried. This
531540
* should be a corner case hence going ahead with LMT check.
532541
* @param renameRequestStartTime startTime for the rename request
533-
* @param op Rename request REST operation response
542+
* @param op Rename request REST operation response with non-null HTTP response
534543
* @param destination rename destination path
535544
* @param tracingContext Tracks identifiers for request header
536545
* @return REST operation response post idempotency check
@@ -541,6 +550,7 @@ public AbfsRestOperation renameIdempotencyCheckOp(
541550
final AbfsRestOperation op,
542551
final String destination,
543552
TracingContext tracingContext) throws AzureBlobFileSystemException {
553+
Preconditions.checkArgument(op.hasResult(), "Operations has null HTTP response");
544554
if ((op.isARetriedRequest())
545555
&& (op.getResult().getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND)) {
546556
// Server has returned HTTP 404, which means rename source no longer
@@ -612,6 +622,10 @@ public AbfsRestOperation append(final String path, final byte[] buffer,
612622
try {
613623
op.execute(tracingContext);
614624
} catch (AzureBlobFileSystemException e) {
625+
// If we have no HTTP response, throw the original exception.
626+
if (!op.hasResult()) {
627+
throw e;
628+
}
615629
if (reqParams.isAppendBlob()
616630
&& appendSuccessCheckOp(op, path,
617631
(reqParams.getPosition() + reqParams.getLength()), tracingContext)) {
@@ -796,6 +810,10 @@ public AbfsRestOperation deletePath(final String path, final boolean recursive,
796810
try {
797811
op.execute(tracingContext);
798812
} catch (AzureBlobFileSystemException e) {
813+
// If we have no HTTP response, throw the original exception.
814+
if (!op.hasResult()) {
815+
throw e;
816+
}
799817
final AbfsRestOperation idempotencyOp = deleteIdempotencyCheckOp(op);
800818
if (idempotencyOp.getResult().getStatusCode()
801819
== op.getResult().getStatusCode()) {
@@ -822,10 +840,11 @@ public AbfsRestOperation deletePath(final String path, final boolean recursive,
822840
* delete issued from this filesystem instance.
823841
* These are few corner cases and usually returning a success at this stage
824842
* should help the job to continue.
825-
* @param op Delete request REST operation response
843+
* @param op Delete request REST operation response with non-null HTTP response
826844
* @return REST operation response post idempotency check
827845
*/
828846
public AbfsRestOperation deleteIdempotencyCheckOp(final AbfsRestOperation op) {
847+
Preconditions.checkArgument(op.hasResult(), "Operations has null HTTP response");
829848
if ((op.isARetriedRequest())
830849
&& (op.getResult().getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND)
831850
&& DEFAULT_DELETE_CONSIDERED_IDEMPOTENT) {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ public class AbfsRestOperation {
7171
private AbfsHttpOperation result;
7272
private AbfsCounters abfsCounters;
7373

74+
/**
75+
* Checks if there is non-null HTTP response.
76+
* @return true if there is a non-null HTTP response from the ABFS call.
77+
*/
78+
public boolean hasResult() {
79+
return result != null;
80+
}
81+
7482
public AbfsHttpOperation getResult() {
7583
return result;
7684
}

0 commit comments

Comments
 (0)