diff --git a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/utils/TracingContext.java b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/utils/TracingContext.java index e3046d3b5a57a..d09cd4ebc7e14 100644 --- a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/utils/TracingContext.java +++ b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/utils/TracingContext.java @@ -153,8 +153,8 @@ public void setListener(Listener listener) { * X_MS_CLIENT_REQUEST_ID header of the http operation * @param httpOperation AbfsHttpOperation instance to set header into * connection - * @param previousFailure List of failures seen before this API trigger on - * same operation from AbfsClient. + * @param previousFailure Failure seen before this API trigger on + * same operation from AbfsClient. It shall be non-null if it is a retry-iteration. */ public void constructHeader(AbfsHttpOperation httpOperation, String previousFailure) { clientRequestId = UUID.randomUUID().toString(); @@ -162,7 +162,7 @@ public void constructHeader(AbfsHttpOperation httpOperation, String previousFail case ALL_ID_FORMAT: // Optional IDs (e.g. streamId) may be empty header = clientCorrelationID + ":" + clientRequestId + ":" + fileSystemID + ":" - + getPrimaryRequestIdForHeader(previousFailure) + ":" + streamID + + getPrimaryRequestIdForHeader(previousFailure != null) + ":" + streamID + ":" + opType + ":" + retryCount; header = addFailureReasons(header, previousFailure); break; @@ -176,6 +176,12 @@ public void constructHeader(AbfsHttpOperation httpOperation, String previousFail listener.callTracingHeaderValidator(header, format); } httpOperation.setRequestProperty(HttpHeaderConfigurations.X_MS_CLIENT_REQUEST_ID, header); + /* + * In case the primaryRequestId is an empty-string and if it is the first try to + * API call (previousFailure shall be null), maintain the last part of clientRequestId's + * UUID in primaryRequestIdForRetry. This field shall be used as primaryRequestId part + * of the x-ms-client-request-id header in case of retry of the same API-request. + * */ if (primaryRequestId.isEmpty() && previousFailure == null) { String[] clientRequestIdParts = clientRequestId.split("-"); primaryRequestIdForRetry = clientRequestIdParts[ @@ -183,8 +189,15 @@ public void constructHeader(AbfsHttpOperation httpOperation, String previousFail } } - private String getPrimaryRequestIdForHeader(final String previousFailure) { - if (!primaryRequestId.isEmpty() || previousFailure == null) { + /** + * Provide value to be used as primaryRequestId part of x-ms-client-request-id header. + * @param isRetry define if it's for a retry case. + * @return {@link #primaryRequestIdForRetry}:If the {@link #primaryRequestId} + * is an empty-string, and it's a retry iteration. + * {@link #primaryRequestId} for other cases. + * */ + private String getPrimaryRequestIdForHeader(final Boolean isRetry) { + if (!primaryRequestId.isEmpty() || !isRetry) { return primaryRequestId; } return primaryRequestIdForRetry;