Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private HttpTimeoutPolicyForPartitionFailover(bool isPointRead)
// For non-point reads: 3 attempts with timeouts of 6s, 6s, and 10s respectively.
private readonly IReadOnlyList<(TimeSpan requestTimeout, TimeSpan delayForNextRequest)> TimeoutsAndDelaysForPointReads = new List<(TimeSpan requestTimeout, TimeSpan delayForNextRequest)>()
{
(TimeSpan.FromSeconds(1), TimeSpan.Zero),
(TimeSpan.FromSeconds(ConfigurationManager.GetHttpFirstRetryTimeoutForPPAFPointReadsInSeconds()), TimeSpan.Zero),
(TimeSpan.FromSeconds(6), TimeSpan.Zero),
(TimeSpan.FromSeconds(6), TimeSpan.Zero),
};
Expand Down
22 changes: 21 additions & 1 deletion Microsoft.Azure.Cosmos/src/Util/ConfigurationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,12 @@ internal static class ConfigurationManager
/// By default length aware range comparator is enabled. Refer to Range.cs in Msdata project for more details. Range.LengthAwareMinComparer/LengthAwareMaxComparer.
/// Setting the value to false will disable length aware range comparator and switch to using the regular Range.MinComparer/MaxComparer.
/// </summary>
internal static readonly string UseLengthAwareRangeComparator = "AZURE_COSMOS_USE_LENGTH_AWARE_RANGE_COMPARATOR";
internal static readonly string UseLengthAwareRangeComparator = "AZURE_COSMOS_USE_LENGTH_AWARE_RANGE_COMPARATOR";

/// <summary>
/// A read-only string containing the environment variable name for capturing the http first retry timeout in seconds applicable for PPAF point reads
/// </summary>
internal static readonly string HttpFirstRetryTimeoutForPPAFPointReads = "AZURE_COSMOS_PPAF_POINT_READS_HTTP_FIRST_RETY_TIMEOUT_IN_SECONDS";

public static T GetEnvironmentVariable<T>(string variable, T defaultValue)
{
Expand Down Expand Up @@ -400,6 +405,21 @@ public static bool IsLengthAwareRangeComparatorEnabled()
.GetEnvironmentVariable(
variable: ConfigurationManager.UseLengthAwareRangeComparator,
defaultValue: defaultValue);
}

/// <summary>
/// Gets http retry timeout value for first retry in case of PPAF point reads.
/// The default value is 1 second. The user can set the respective
/// environment variable 'AZURE_COSMOS_PPAF_POINT_READS_HTTP_FIRST_RETY_TIMEOUT_IN_SECONDS'
/// to override the value.
/// </summary>
/// <returns>An integer representing the refresh interval in seconds.</returns>
public static int GetHttpFirstRetryTimeoutForPPAFPointReadsInSeconds()
{
return ConfigurationManager
.GetEnvironmentVariable(
variable: ConfigurationManager.HttpFirstRetryTimeoutForPPAFPointReads,
defaultValue: 1);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,38 @@ public void HttpTimeoutPolicyForParitionFailoverForReads()
}
}

[TestMethod]
public void HttpTimeoutPolicyForParitionFailoverConfigurableTimeoutForReads()
{
Environment.SetEnvironmentVariable(ConfigurationManager.HttpFirstRetryTimeoutForPPAFPointReads, "4");
try
{
HttpTimeoutPolicy httpTimeoutPolicyForQuery = HttpTimeoutPolicy.GetTimeoutPolicy(
documentServiceRequest: CosmosHttpClientCoreTests.CreateDocumentServiceRequestByOperation(ResourceType.Document, OperationType.Read),
isPartitionLevelFailoverEnabled: true,
isThinClientEnabled: false);
IEnumerator<(TimeSpan requestTimeout, TimeSpan delayForNextRequest)> availableRetries = httpTimeoutPolicyForQuery.GetTimeoutEnumerator();

int count = 0;
while (availableRetries.MoveNext())
{
if (count == 0)
{
Assert.AreEqual(new TimeSpan(0, 0, 4), availableRetries.Current.requestTimeout);
}
else if (count == 1 || count == 2)
{
Assert.AreEqual(new TimeSpan(0, 0, 6), availableRetries.Current.requestTimeout);
}
count++;
}
}
finally
{
Environment.SetEnvironmentVariable(ConfigurationManager.HttpFirstRetryTimeoutForPPAFPointReads, null);
}
}

private static DocumentServiceRequest CreateDocumentServiceRequestByOperation(
ResourceType resourceType,
OperationType operationType)
Expand Down
Loading