Skip to content

Commit

Permalink
Merge branch 'master' into users/akotalwar/TurnOnODEByDefault
Browse files Browse the repository at this point in the history
  • Loading branch information
akotalwar committed Jan 6, 2024
2 parents cc1db80 + 17bbdab commit ab69838
Show file tree
Hide file tree
Showing 53 changed files with 5,362 additions and 374 deletions.
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ClientOfficialVersion>3.37.0</ClientOfficialVersion>
<ClientPreviewVersion>3.37.0</ClientPreviewVersion>
<ClientOfficialVersion>3.37.1</ClientOfficialVersion>
<ClientPreviewVersion>3.37.1</ClientPreviewVersion>
<ClientPreviewSuffixVersion>preview</ClientPreviewSuffixVersion>
<DirectVersion>3.31.5</DirectVersion>
<EncryptionOfficialVersion>2.0.4</EncryptionOfficialVersion>
Expand Down
1,611 changes: 1,611 additions & 0 deletions Microsoft.Azure.Cosmos/contracts/API_3.37.1-preview.txt

Large diffs are not rendered by default.

1,552 changes: 1,552 additions & 0 deletions Microsoft.Azure.Cosmos/contracts/API_3.37.1.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ public override async Task AddOrUpdateLeaseAsync(DocumentServiceLease lease)
throw;
}

PartitionSupervisor supervisor = this.partitionSupervisorFactory.Create(lease);
this.ProcessPartitionAsync(supervisor, lease).LogException();
this.ProcessPartitionAsync(lease).LogException();
}

public override async Task ShutdownAsync()
Expand Down Expand Up @@ -146,8 +145,10 @@ private async Task RemoveLeaseAsync(DocumentServiceLease lease, bool wasAcquired
}
}

private async Task ProcessPartitionAsync(PartitionSupervisor partitionSupervisor, DocumentServiceLease lease)
private async Task ProcessPartitionAsync(DocumentServiceLease lease)
{
using PartitionSupervisor partitionSupervisor = this.partitionSupervisorFactory.Create(lease);

try
{
await partitionSupervisor.RunAsync(this.shutdownCts.Token).ConfigureAwait(false);
Expand Down
14 changes: 14 additions & 0 deletions Microsoft.Azure.Cosmos/src/ClientRetryPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ public async Task<ShouldRetryResult> ShouldRetryAsync(
}
}

// Any metadata request will throw a cosmos exception from CosmosHttpClientCore if
// it receives a 503 service unavailable from gateway. This check is to add retry
// mechanism for the metadata requests in such cases.
if (exception is CosmosException cosmosException)
{
ShouldRetryResult shouldRetryResult = await this.ShouldRetryInternalAsync(
cosmosException.StatusCode,
cosmosException.Headers.SubStatusCode);
if (shouldRetryResult != null)
{
return shouldRetryResult;
}
}

return await this.throttlingRetry.ShouldRetryAsync(exception, cancellationToken);
}

Expand Down
4 changes: 2 additions & 2 deletions Microsoft.Azure.Cosmos/src/DocumentClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ private async Task OpenPrivateAsync(CancellationToken cancellationToken)
tokenProvider: this,
retryPolicy: this.retryPolicy,
telemetryToServiceHelper: this.telemetryToServiceHelper);
this.partitionKeyRangeCache = new PartitionKeyRangeCache(this, this.GatewayStoreModel, this.collectionCache);
this.partitionKeyRangeCache = new PartitionKeyRangeCache(this, this.GatewayStoreModel, this.collectionCache, this.GlobalEndpointManager);

DefaultTrace.TraceWarning("{0} occurred while OpenAsync. Exception Message: {1}", ex.ToString(), ex.Message);
}
Expand Down Expand Up @@ -1033,7 +1033,7 @@ private async Task<bool> GetInitializationTaskAsync(IStoreClientFactory storeCli
tokenProvider: this,
retryPolicy: this.retryPolicy,
telemetryToServiceHelper: this.telemetryToServiceHelper);
this.partitionKeyRangeCache = new PartitionKeyRangeCache(this, this.GatewayStoreModel, this.collectionCache);
this.partitionKeyRangeCache = new PartitionKeyRangeCache(this, this.GatewayStoreModel, this.collectionCache, this.GlobalEndpointManager);
this.ResetSessionTokenRetryPolicy = new ResetSessionTokenRetryPolicyFactory(this.sessionContainer, this.collectionCache, this.retryPolicy);

gatewayStoreModel.SetCaches(this.partitionKeyRangeCache, this.collectionCache);
Expand Down
13 changes: 10 additions & 3 deletions Microsoft.Azure.Cosmos/src/HttpClient/HttpTimeoutPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,15 @@ public static HttpTimeoutPolicy GetTimeoutPolicy(
return HttpTimeoutPolicyControlPlaneRetriableHotPath.InstanceShouldThrow503OnTimeout;
}

//Partition Key Requests
if (documentServiceRequest.ResourceType == ResourceType.PartitionKeyRange)
//Get Partition Key Range Requests
if (documentServiceRequest.ResourceType == ResourceType.PartitionKeyRange
&& documentServiceRequest.OperationType == OperationType.ReadFeed)
{
return HttpTimeoutPolicyControlPlaneRetriableHotPath.InstanceShouldThrow503OnTimeout;
}

//Get Addresses Requests
if (documentServiceRequest.ResourceType == ResourceType.Address)
{
return HttpTimeoutPolicyControlPlaneRetriableHotPath.Instance;
}
Expand All @@ -44,7 +51,7 @@ public static HttpTimeoutPolicy GetTimeoutPolicy(
//Meta Data Read
if (HttpTimeoutPolicy.IsMetaData(documentServiceRequest) && documentServiceRequest.IsReadOnlyRequest)
{
return HttpTimeoutPolicyDefault.InstanceShouldThrow503OnTimeout;
return HttpTimeoutPolicyControlPlaneRetriableHotPath.InstanceShouldThrow503OnTimeout;
}

//Default behavior
Expand Down
8 changes: 4 additions & 4 deletions Microsoft.Azure.Cosmos/src/Linq/CosmosLinqQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ namespace Microsoft.Azure.Cosmos.Linq
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos.Diagnostics;
using Microsoft.Azure.Cosmos.Query;
using Microsoft.Azure.Cosmos.Query.Core;
using Microsoft.Azure.Cosmos.Serializer;
using Microsoft.Azure.Cosmos.Tracing;
using Newtonsoft.Json;

Expand All @@ -32,7 +32,7 @@ internal sealed class CosmosLinqQuery<T> : IDocumentQuery<T>, IOrderedQueryable<
private readonly QueryRequestOptions cosmosQueryRequestOptions;
private readonly bool allowSynchronousQueryExecution = false;
private readonly string continuationToken;
private readonly CosmosLinqSerializerOptions linqSerializationOptions;
private readonly CosmosLinqSerializerOptionsInternal linqSerializationOptions;

public CosmosLinqQuery(
ContainerInternal container,
Expand All @@ -42,7 +42,7 @@ public CosmosLinqQuery(
QueryRequestOptions cosmosQueryRequestOptions,
Expression expression,
bool allowSynchronousQueryExecution,
CosmosLinqSerializerOptions linqSerializationOptions = null)
CosmosLinqSerializerOptionsInternal linqSerializationOptions = null)
{
this.container = container ?? throw new ArgumentNullException(nameof(container));
this.responseFactory = responseFactory ?? throw new ArgumentNullException(nameof(responseFactory));
Expand Down Expand Up @@ -72,7 +72,7 @@ public CosmosLinqQuery(
string continuationToken,
QueryRequestOptions cosmosQueryRequestOptions,
bool allowSynchronousQueryExecution,
CosmosLinqSerializerOptions linqSerializerOptions = null)
CosmosLinqSerializerOptionsInternal linqSerializerOptions = null)
: this(
container,
responseFactory,
Expand Down
5 changes: 2 additions & 3 deletions Microsoft.Azure.Cosmos/src/Linq/CosmosLinqQueryProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Microsoft.Azure.Cosmos.Linq
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
Expand All @@ -24,7 +23,7 @@ internal sealed class CosmosLinqQueryProvider : IQueryProvider
private readonly bool allowSynchronousQueryExecution;
private readonly Action<IQueryable> onExecuteScalarQueryCallback;
private readonly string continuationToken;
private readonly CosmosLinqSerializerOptions linqSerializerOptions;
private readonly CosmosLinqSerializerOptionsInternal linqSerializerOptions;

public CosmosLinqQueryProvider(
ContainerInternal container,
Expand All @@ -34,7 +33,7 @@ public CosmosLinqQueryProvider(
QueryRequestOptions cosmosQueryRequestOptions,
bool allowSynchronousQueryExecution,
Action<IQueryable> onExecuteScalarQueryCallback = null,
CosmosLinqSerializerOptions linqSerializerOptions = null)
CosmosLinqSerializerOptionsInternal linqSerializerOptions = null)
{
this.container = container;
this.responseFactory = responseFactory;
Expand Down
56 changes: 56 additions & 0 deletions Microsoft.Azure.Cosmos/src/Linq/CustomCosmosLinqSerializer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace Microsoft.Azure.Cosmos.Linq
{
using System;
using System.Globalization;
using System.IO;
using System.Linq.Expressions;
using System.Reflection;

internal class CustomCosmosLinqSerializer : ICosmosLinqSerializerInternal
{
private readonly CosmosLinqSerializer CustomCosmosSerializer;

public CustomCosmosLinqSerializer(CosmosLinqSerializer customCosmosLinqSerializer)
{
this.CustomCosmosSerializer = customCosmosLinqSerializer;
}

public bool RequiresCustomSerialization(MemberExpression memberExpression, Type memberType)
{
return true;
}

public string Serialize(object value, MemberExpression memberExpression, Type memberType)
{
return this.SerializeWithCustomSerializer(value);
}

public string SerializeScalarExpression(ConstantExpression inputExpression)
{
return this.SerializeWithCustomSerializer(inputExpression.Value);
}

public string SerializeMemberName(MemberInfo memberInfo)
{
return this.CustomCosmosSerializer.SerializeMemberName(memberInfo);
}

private string SerializeWithCustomSerializer(object value)
{
StringWriter writer = new StringWriter(CultureInfo.InvariantCulture);

using (Stream stream = this.CustomCosmosSerializer.ToStream(value))
{
using (StreamReader streamReader = new StreamReader(stream))
{
string propertyValue = streamReader.ReadToEnd();
writer.Write(propertyValue);
return writer.ToString();
}
}
}
}
}
23 changes: 11 additions & 12 deletions Microsoft.Azure.Cosmos/src/Linq/DefaultCosmosLinqSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@ namespace Microsoft.Azure.Cosmos.Linq
using Microsoft.Azure.Documents;
using Newtonsoft.Json;

internal class DefaultCosmosLinqSerializer : ICosmosLinqSerializer
internal class DefaultCosmosLinqSerializer : ICosmosLinqSerializerInternal
{
private readonly CosmosPropertyNamingPolicy PropertyNamingPolicy;

public DefaultCosmosLinqSerializer(CosmosPropertyNamingPolicy propertyNamingPolicy)
{
this.PropertyNamingPolicy = propertyNamingPolicy;
}

public bool RequiresCustomSerialization(MemberExpression memberExpression, Type memberType)
{
// There are two ways to specify a custom attribute
Expand Down Expand Up @@ -63,9 +70,9 @@ public string SerializeScalarExpression(ConstantExpression inputExpression)
return JsonConvert.SerializeObject(inputExpression.Value);
}

public string SerializeMemberName(MemberInfo memberInfo, CosmosLinqSerializerOptions linqSerializerOptions = null)
public string SerializeMemberName(MemberInfo memberInfo)
{
string memberName = null;
string memberName = memberInfo.Name;

// Check if Newtonsoft JsonExtensionDataAttribute is present on the member, if so, return empty member name.
Newtonsoft.Json.JsonExtensionDataAttribute jsonExtensionDataAttribute = memberInfo.GetCustomAttribute<Newtonsoft.Json.JsonExtensionDataAttribute>(true);
Expand Down Expand Up @@ -94,15 +101,7 @@ public string SerializeMemberName(MemberInfo memberInfo, CosmosLinqSerializerOpt
}
}

if (memberName == null)
{
memberName = memberInfo.Name;
}

if (linqSerializerOptions != null)
{
memberName = CosmosSerializationUtil.GetStringWithPropertyNamingPolicy(linqSerializerOptions, memberName);
}
memberName = CosmosSerializationUtil.GetStringWithPropertyNamingPolicy(this.PropertyNamingPolicy, memberName);

return memberName;
}
Expand Down
4 changes: 2 additions & 2 deletions Microsoft.Azure.Cosmos/src/Linq/DocumentQueryEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal static class DocumentQueryEvaluator

public static SqlQuerySpec Evaluate(
Expression expression,
CosmosLinqSerializerOptions linqSerializerOptions = null,
CosmosLinqSerializerOptionsInternal linqSerializerOptions = null,
IDictionary<object, string> parameters = null)
{
switch (expression.NodeType)
Expand Down Expand Up @@ -76,7 +76,7 @@ private static SqlQuerySpec HandleEmptyQuery(ConstantExpression expression)
private static SqlQuerySpec HandleMethodCallExpression(
MethodCallExpression expression,
IDictionary<object, string> parameters,
CosmosLinqSerializerOptions linqSerializerOptions = null)
CosmosLinqSerializerOptionsInternal linqSerializerOptions = null)
{
if (DocumentQueryEvaluator.IsTransformExpression(expression))
{
Expand Down
8 changes: 4 additions & 4 deletions Microsoft.Azure.Cosmos/src/Linq/ExpressionToSQL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ namespace Microsoft.Azure.Cosmos.Linq
using System.Linq.Expressions;
using System.Reflection;
using Microsoft.Azure.Cosmos.CosmosElements;
using Microsoft.Azure.Cosmos.Serializer;
using Microsoft.Azure.Cosmos.Spatial;
using Microsoft.Azure.Cosmos.SqlObjects;
using Microsoft.Azure.Documents;
using Newtonsoft.Json;
using static Microsoft.Azure.Cosmos.Linq.FromParameterBindings;

// ReSharper disable UnusedParameter.Local
Expand Down Expand Up @@ -88,7 +88,7 @@ public static class LinqMethods
public static SqlQuery TranslateQuery(
Expression inputExpression,
IDictionary<object, string> parameters,
CosmosLinqSerializerOptions linqSerializerOptions)
CosmosLinqSerializerOptionsInternal linqSerializerOptions)
{
TranslationContext context = new TranslationContext(linqSerializerOptions, parameters);
ExpressionToSql.Translate(inputExpression, context); // ignore result here
Expand Down Expand Up @@ -503,8 +503,8 @@ private static SqlScalarExpression ApplyCustomConverters(Expression left, SqlLit
memberType = memberType.NullableUnderlyingType();
}

bool requiresCustomSerializatior = context.CosmosLinqSerializer.RequiresCustomSerialization(memberExpression, memberType);
if (requiresCustomSerializatior)
bool requiresCustomSerialization = context.CosmosLinqSerializer.RequiresCustomSerialization(memberExpression, memberType);
if (requiresCustomSerialization)
{
object value = default(object);
// Enum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Microsoft.Azure.Cosmos.Linq
using System.Linq.Expressions;
using System.Reflection;

internal interface ICosmosLinqSerializer
internal interface ICosmosLinqSerializerInternal
{
/// <summary>
/// Returns true if there are custom attributes on a member expression.
Expand All @@ -28,6 +28,6 @@ internal interface ICosmosLinqSerializer
/// <summary>
/// Serializes a member name with LINQ serializer options applied.
/// </summary>
string SerializeMemberName(MemberInfo memberInfo, CosmosLinqSerializerOptions linqSerializerOptions = null);
string SerializeMemberName(MemberInfo memberInfo);
}
}
7 changes: 4 additions & 3 deletions Microsoft.Azure.Cosmos/src/Linq/SQLTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Microsoft.Azure.Cosmos.Linq
using System.Collections.Generic;
using System.Linq.Expressions;
using Microsoft.Azure.Cosmos.Query.Core;
using Microsoft.Azure.Cosmos.Serializer;
using Microsoft.Azure.Cosmos.SqlObjects;

/// <summary>
Expand All @@ -21,7 +22,7 @@ internal static class SqlTranslator
/// <returns>A string describing the expression translation.</returns>
internal static string TranslateExpression(
Expression inputExpression,
CosmosLinqSerializerOptions linqSerializerOptions = null)
CosmosLinqSerializerOptionsInternal linqSerializerOptions = null)
{
TranslationContext context = new TranslationContext(linqSerializerOptions);

Expand All @@ -32,7 +33,7 @@ internal static string TranslateExpression(

internal static string TranslateExpressionOld(
Expression inputExpression,
CosmosLinqSerializerOptions linqSerializerOptions = null)
CosmosLinqSerializerOptionsInternal linqSerializerOptions = null)
{
TranslationContext context = new TranslationContext(linqSerializerOptions);

Expand All @@ -43,7 +44,7 @@ internal static string TranslateExpressionOld(

internal static SqlQuerySpec TranslateQuery(
Expression inputExpression,
CosmosLinqSerializerOptions linqSerializerOptions,
CosmosLinqSerializerOptionsInternal linqSerializerOptions,
IDictionary<object, string> parameters)
{
inputExpression = ConstantEvaluator.PartialEval(inputExpression);
Expand Down
Loading

0 comments on commit ab69838

Please sign in to comment.