Skip to content

Commit

Permalink
[Internal][PartitionMerge] Add SDKSupportedCapabilities to hint that …
Browse files Browse the repository at this point in the history
…SDK has merge (#3111)

* Revert "[Internal] API Version: Updates DefaultAPIVersion to v2019_10_14 to indicate merge support (#3015)"

This reverts commit 83d4d0c.

* [PartitionMerge] Add SDKSupportedCapabilities to hint that SDK has merge support

* caching the header value and adding tests

Co-authored-by: j82w <j82w@users.noreply.github.com>
  • Loading branch information
ramarag and j82w authored Mar 24, 2022
1 parent bedeabb commit a2e910a
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Microsoft.Azure.Cosmos/src/CosmosClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ static CosmosClient()
#if PREVIEW
HttpConstants.Versions.CurrentVersion = HttpConstants.Versions.v2020_07_15;
#else
HttpConstants.Versions.CurrentVersion = HttpConstants.Versions.v2019_10_14;
HttpConstants.Versions.CurrentVersion = HttpConstants.Versions.v2018_12_31;
#endif
HttpConstants.Versions.CurrentVersionUTF8 = Encoding.UTF8.GetBytes(HttpConstants.Versions.CurrentVersion);

Expand Down
2 changes: 2 additions & 0 deletions Microsoft.Azure.Cosmos/src/Handler/RequestInvokerHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ public virtual async Task<ResponseMessage> SendAsync(
Content = streamPayload,
};

request.Headers[HttpConstants.HttpHeaders.SDKSupportedCapabilities] = Headers.SDKSupportedCapabilities;

if (feedRange != null)
{
if (feedRange is FeedRangePartitionKey feedRangePartitionKey)
Expand Down
5 changes: 5 additions & 0 deletions Microsoft.Azure.Cosmos/src/Headers/Headers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ namespace Microsoft.Azure.Cosmos
/// <seealso cref="RequestMessage"/>
public class Headers : IEnumerable
{
private static readonly string sdkSupportedCapabilities = SDKSupportedCapabilitiesHelpers.GetSDKSupportedCapabilities().ToString(
CultureInfo.InvariantCulture);

internal virtual SubStatusCodes SubStatusCode
{
get => Headers.GetSubStatusCodes(this.SubStatusCodeLiteral);
Expand Down Expand Up @@ -395,5 +398,7 @@ internal static SubStatusCodes GetSubStatusCodes(string value)

return null;
}

internal static string SDKSupportedCapabilities => Headers.sdkSupportedCapabilities;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ internal class StoreRequestNameValueCollection : CosmosMessageHeadersInternal, I
public string RemainingTimeInMsOnClientRequest { get; set; }
public string ResourceTokenExpiry { get; set; }
public string ResourceTypes { get; set; }
public string SDKSupportedCapabilities { get; set; }
public override string SessionToken { get; set; }
public string ShouldBatchContinueOnError { get; set; }
public string TargetGlobalCommittedLsn { get; set; }
Expand Down Expand Up @@ -98,6 +99,7 @@ public override void Clear()
this.RemainingTimeInMsOnClientRequest = null;
this.ResourceTokenExpiry = null;
this.ResourceTypes = null;
this.SDKSupportedCapabilities = null;
this.SessionToken = null;
this.ShouldBatchContinueOnError = null;
this.TargetGlobalCommittedLsn = null;
Expand Down Expand Up @@ -140,6 +142,7 @@ public override INameValueCollection Clone()
RemainingTimeInMsOnClientRequest = this.RemainingTimeInMsOnClientRequest,
ResourceTokenExpiry = this.ResourceTokenExpiry,
ResourceTypes = this.ResourceTypes,
SDKSupportedCapabilities = this.SDKSupportedCapabilities,
SessionToken = this.SessionToken,
ShouldBatchContinueOnError = this.ShouldBatchContinueOnError,
TargetGlobalCommittedLsn = this.TargetGlobalCommittedLsn,
Expand Down Expand Up @@ -172,7 +175,7 @@ public override string[] GetValues(string key)
{
return new string[] { value };
}

return null;
}

Expand Down Expand Up @@ -234,6 +237,10 @@ public override IEnumerable<string> Keys()
{
yield return HttpConstants.HttpHeaders.ResourceTokenExpiry;
}
if (this.SDKSupportedCapabilities != null)
{
yield return HttpConstants.HttpHeaders.SDKSupportedCapabilities;
}
if (this.SessionToken != null)
{
yield return HttpConstants.HttpHeaders.SessionToken;
Expand Down Expand Up @@ -311,42 +318,42 @@ public override string Get(string key)
{
return this.HttpDate;
}

break;
case 6:
if (string.Equals(HttpConstants.HttpHeaders.Prefer, key, StringComparison.OrdinalIgnoreCase))
{
return this.Prefer;
}

break;
case 9:
if (string.Equals(HttpConstants.HttpHeaders.XDate, key, StringComparison.OrdinalIgnoreCase))
{
return this.XDate;
}

break;
case 12:
if (string.Equals(HttpConstants.HttpHeaders.Version, key, StringComparison.OrdinalIgnoreCase))
{
return this.Version;
}

break;
case 13:
if (string.Equals(HttpConstants.HttpHeaders.Authorization, key, StringComparison.OrdinalIgnoreCase))
{
return this.Authorization;
}

break;
case 15:
if (string.Equals(HttpConstants.HttpHeaders.TargetLsn, key, StringComparison.OrdinalIgnoreCase))
{
return this.TargetLsn;
}

break;
case 17:
if (object.ReferenceEquals(HttpConstants.HttpHeaders.Continuation, key))
Expand All @@ -361,40 +368,40 @@ public override string Get(string key)
{
return this.Continuation;
}

if (string.Equals(WFConstants.BackendHeaders.TransactionId, key, StringComparison.OrdinalIgnoreCase))
{
return this.TransactionId;
}

break;
case 18:
if (string.Equals(HttpConstants.HttpHeaders.SessionToken, key, StringComparison.OrdinalIgnoreCase))
{
return this.SessionToken;
}

break;
case 21:
if (string.Equals(WFConstants.BackendHeaders.TransactionCommit, key, StringComparison.OrdinalIgnoreCase))
{
return this.TransactionCommit;
}

break;
case 22:
if (string.Equals(HttpConstants.HttpHeaders.ConsistencyLevel, key, StringComparison.OrdinalIgnoreCase))
{
return this.ConsistencyLevel;
}

break;
case 24:
if (string.Equals(HttpConstants.HttpHeaders.IsBatchAtomic, key, StringComparison.OrdinalIgnoreCase))
{
return this.IsBatchAtomic;
}

break;
case 25:
if (object.ReferenceEquals(HttpConstants.HttpHeaders.IsBatchOrdered, key))
Expand All @@ -417,22 +424,22 @@ public override string Get(string key)
{
return this.IsBatchOrdered;
}

if (string.Equals(HttpConstants.HttpHeaders.IsUpsert, key, StringComparison.OrdinalIgnoreCase))
{
return this.IsUpsert;
}

if (string.Equals(HttpConstants.HttpHeaders.TransportRequestID, key, StringComparison.OrdinalIgnoreCase))
{
return this.TransportRequestID;
}

if (string.Equals(WFConstants.BackendHeaders.ResourceTypes, key, StringComparison.OrdinalIgnoreCase))
{
return this.ResourceTypes;
}

break;
case 28:
if (object.ReferenceEquals(HttpConstants.HttpHeaders.PartitionKey, key))
Expand All @@ -451,17 +458,17 @@ public override string Get(string key)
{
return this.PartitionKey;
}

if (string.Equals(WFConstants.BackendHeaders.EffectivePartitionKey, key, StringComparison.OrdinalIgnoreCase))
{
return this.EffectivePartitionKey;
}

if (string.Equals(WFConstants.BackendHeaders.TimeToLiveInSeconds, key, StringComparison.OrdinalIgnoreCase))
{
return this.TimeToLiveInSeconds;
}

break;
case 30:
if (object.ReferenceEquals(HttpConstants.HttpHeaders.ResourceTokenExpiry, key))
Expand All @@ -480,31 +487,31 @@ public override string Get(string key)
{
return this.ResourceTokenExpiry;
}

if (string.Equals(WFConstants.BackendHeaders.CollectionRid, key, StringComparison.OrdinalIgnoreCase))
{
return this.CollectionRid;
}

if (string.Equals(WFConstants.BackendHeaders.ExcludeSystemProperties, key, StringComparison.OrdinalIgnoreCase))
{
return this.ExcludeSystemProperties;
}

break;
case 31:
if (string.Equals(HttpConstants.HttpHeaders.ClientRetryAttemptCount, key, StringComparison.OrdinalIgnoreCase))
{
return this.ClientRetryAttemptCount;
}

break;
case 32:
if (string.Equals(HttpConstants.HttpHeaders.TargetGlobalCommittedLsn, key, StringComparison.OrdinalIgnoreCase))
{
return this.TargetGlobalCommittedLsn;
}

break;
case 35:
if (object.ReferenceEquals(HttpConstants.HttpHeaders.RemainingTimeInMsOnClientRequest, key))
Expand All @@ -519,12 +526,19 @@ public override string Get(string key)
{
return this.RemainingTimeInMsOnClientRequest;
}

if (string.Equals(HttpConstants.HttpHeaders.ShouldBatchContinueOnError, key, StringComparison.OrdinalIgnoreCase))
{
return this.ShouldBatchContinueOnError;
}


break;
case 38:
if (string.Equals(HttpConstants.HttpHeaders.SDKSupportedCapabilities, key, StringComparison.OrdinalIgnoreCase))
{
return this.SDKSupportedCapabilities;
}

break;
default:
break;
Expand All @@ -535,7 +549,7 @@ public override string Get(string key)
{
return value;
}

return null;
}

Expand All @@ -552,8 +566,8 @@ public override void Add(string key, string value)
}

this.UpdateHelper(
key: key,
value: value,
key: key,
value: value,
throwIfAlreadyExists: true);
}

Expand All @@ -565,8 +579,8 @@ public override void Remove(string key)
}

this.UpdateHelper(
key: key,
value: null,
key: key,
value: null,
throwIfAlreadyExists: false);
}

Expand All @@ -584,13 +598,13 @@ public override void Set(string key, string value)
}

this.UpdateHelper(
key: key,
value: value,
key: key,
value: value,
throwIfAlreadyExists: false);
}

public void UpdateHelper(
string key,
string key,
string value,
bool throwIfAlreadyExists)
{
Expand Down Expand Up @@ -1035,6 +1049,18 @@ public void UpdateHelper(
return;
}
break;
case 38:
if (string.Equals(HttpConstants.HttpHeaders.SDKSupportedCapabilities, key, StringComparison.OrdinalIgnoreCase))
{
if (throwIfAlreadyExists && this.SDKSupportedCapabilities != null)
{
throw new ArgumentException($"The {key} already exists in the collection");
}

this.SDKSupportedCapabilities = value;
return;
}
break;
default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
("HttpConstants.HttpHeaders.Prefer", "Prefer", false),
("HttpConstants.HttpHeaders.RemainingTimeInMsOnClientRequest", "x-ms-remaining-time-in-ms-on-client", false),
("HttpConstants.HttpHeaders.ResourceTokenExpiry", "x-ms-documentdb-expiry-seconds", false),
("HttpConstants.HttpHeaders.SDKSupportedCapabilities","x-ms-cosmos-sdk-supported-capabilities", false),
("HttpConstants.HttpHeaders.SessionToken", "x-ms-session-token", true),
("HttpConstants.HttpHeaders.ShouldBatchContinueOnError", "x-ms-cosmos-batch-continue-on-error", false),
("HttpConstants.HttpHeaders.TargetGlobalCommittedLsn", "x-ms-target-global-committed-lsn", false),
Expand Down
3 changes: 3 additions & 0 deletions Microsoft.Azure.Cosmos/src/HttpClient/CosmosHttpClientCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ private static CosmosHttpClient CreateHelper(
httpClient.DefaultRequestHeaders.Add(HttpConstants.HttpHeaders.Version,
HttpConstants.Versions.CurrentVersion);

httpClient.DefaultRequestHeaders.Add(HttpConstants.HttpHeaders.SDKSupportedCapabilities,
Headers.SDKSupportedCapabilities);

httpClient.DefaultRequestHeaders.Add(HttpConstants.HttpHeaders.Accept, RuntimeConstants.MediaTypes.Json);

return new CosmosHttpClientCore(
Expand Down
15 changes: 15 additions & 0 deletions Microsoft.Azure.Cosmos/src/SDKSupportedCapabilities.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// ------------------------------------------------------------

namespace Microsoft.Azure.Cosmos
{
using System;

[Flags]
internal enum SDKSupportedCapabilities : ulong
{
None = 0,
PartitionMerge = 1 << 0,
}
}
Loading

0 comments on commit a2e910a

Please sign in to comment.