Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ internal class CrossRegionHedgingAvailabilityStrategy : AvailabilityStrategyInte
{
private const string HedgeContext = "Hedge Context";
private const string HedgeConfig = "Hedge Config";
private const string ResponseRegion = "Response Region";

/// <summary>
/// Latency threshold which activates the first region hedging
Expand Down Expand Up @@ -206,6 +207,10 @@ internal override async Task<ResponseMessage> ExecuteAvailabilityStrategyAsync(
((CosmosTraceDiagnostics)hedgeResponse.ResponseMessage.Diagnostics).Value.AddOrUpdateDatum(
HedgeContext,
hedgeRegions.Take(requestNumber + 1));
// Note that the target region can be seperate than the actual region that serviced the request depending on the scenario
((CosmosTraceDiagnostics)hedgeResponse.ResponseMessage.Diagnostics).Value.AddOrUpdateDatum(
ResponseRegion,
hedgeResponse.TargetRegionName);
return hedgeResponse.ResponseMessage;
}
}
Expand Down Expand Up @@ -234,6 +239,10 @@ internal override async Task<ResponseMessage> ExecuteAvailabilityStrategyAsync(
((CosmosTraceDiagnostics)hedgeResponse.ResponseMessage.Diagnostics).Value.AddOrUpdateDatum(
HedgeContext,
hedgeRegions);
// Note that the target region can be seperate than the actual region that serviced the request depending on the scenario
((CosmosTraceDiagnostics)hedgeResponse.ResponseMessage.Diagnostics).Value.AddOrUpdateDatum(
ResponseRegion,
hedgeResponse.TargetRegionName);
return hedgeResponse.ResponseMessage;
}
}
Expand Down Expand Up @@ -278,6 +287,7 @@ private async Task<HedgingResponse> CloneAndSendAsync(
return await this.RequestSenderAndResultCheckAsync(
sender,
clonedRequest,
hedgeRegions.ElementAt(requestNumber),
cancellationToken,
cancellationTokenSource,
trace);
Expand All @@ -287,6 +297,7 @@ private async Task<HedgingResponse> CloneAndSendAsync(
private async Task<HedgingResponse> RequestSenderAndResultCheckAsync(
Func<RequestMessage, CancellationToken, Task<ResponseMessage>> sender,
RequestMessage request,
string targetRegionName,
CancellationToken cancellationToken,
CancellationTokenSource cancellationTokenSource,
ITrace trace)
Expand All @@ -301,10 +312,10 @@ private async Task<HedgingResponse> RequestSenderAndResultCheckAsync(
cancellationTokenSource.Cancel();
}

return new HedgingResponse(true, response);
return new HedgingResponse(true, response, targetRegionName);
}

return new HedgingResponse(false, response);
return new HedgingResponse(false, response, targetRegionName);
}
catch (OperationCanceledException oce) when (cancellationTokenSource.IsCancellationRequested)
{
Expand Down Expand Up @@ -346,11 +357,13 @@ private sealed class HedgingResponse
{
public readonly bool IsNonTransient;
public readonly ResponseMessage ResponseMessage;
public readonly string TargetRegionName;

public HedgingResponse(bool isNonTransient, ResponseMessage responseMessage)
public HedgingResponse(bool isNonTransient, ResponseMessage responseMessage, string targetRegionName)
{
this.IsNonTransient = isNonTransient;
this.ResponseMessage = responseMessage;
this.TargetRegionName = targetRegionName;
}
}
}
Expand Down
Loading