Skip to content

Commit

Permalink
Porting 3.0.0.11-preview fixes into master (#245)
Browse files Browse the repository at this point in the history
* Raising version to 22-preview

* Merge master into release (CF Pull internal API) (#115)

* Assemblyinfo clean-up (#104)

* Signed build assembly info fix

* Assembly info clean-up

* Including test projects internal visible to (#107)

* Stand By Feed and ChangeFeed pull model (#105)

* Adding initial files

* Using Etag for continuation

* Removing unused

* Refactoring to reduce variables

* Refactoring to use CompositeToken

* Adding feed test

* Refactor through Options

* Adding public methods and comments

* Routing through the point transport handler

* Moving to outer if

* Adding split logic

* Adding unit tests

* Adding logic to detect invalid continuation tokens

* Adding JSON validation

* Routing based on PKRangeId

* Renaming and adding more tests

* Moving logic into the token

* Forcing refresh on split

* Addressing final coments

* Addressing feedback

* Added test to cover CT passing

* Refactoring and adding pkrangedelegate

* Argument checks

* Moving contract to CosmosRequestMessage

* Refactoring make EnsureInitialized async

* Moving tests to a new file

* Adding PKrange assert

* Refactored back to parameters outside Options

* UT split

* Adding Start* checks

* Adding new tests and renames

* Addressing comments

* Refactoring for cache tests

* Adding comments to tests

* Adding factory method

* Addressing comments

* Refactoring PKRange outside options

* Addressing comments

* Removing StartFromBeginning

* Removing extra lines

* Removing unnecessary ToList

* Raising version to 22-preview (#113)

* fix bugs

* Fixing signing issue

* Hot fixes for CosmosSerializationOptions and query partition key issues (#207)

* Hot fixes for CosmosSerializationOptions and query partition key.

* initial commit (#193)

* Fixed formatting

* added new system strings (#210)

* Ignoring TestLazyIndexAllTerms (#211)

* PartitionedCRUDTest ignored (#217)

* Exception-less Streaming API for non-existing NP container scenarios (#227)

* First cut of fix

* Refreshing syntax as per C#7

* ComosContextCore depenency on ExecUtils removed.
Few proxy methods from ExecUtils are removed.

* SDK version to 3.0.0.11-preview and Direct dependency to 3.0.0.27-preview

* Cherry pick 15a9e26 into 3.0.0.11_preview (#235)

* Query routing with partition key definition (#213)

* Fix breaks for the release

* Remove unused usings

* Adding a unit test to verify setting PartitionKeyDefinition works. (#226)

* More

* Revert "Fixing samples build break (#236)"

This reverts commit cda8903.

* Force samples to Nuget.org only

* Fixes for query pipeline

* Some more fixes

* Np tests and quarantine open-partition tests

* small correction

* Direct contract test pruning

* Few test fixes

* Bug fix for paramaterised queries

* Including NP query tests

* One more test fix

* Fix for MixedModeTypoes unit test

* MixedMode multi-targeting tests clean.

* Enabling Distinct and TopOrderBy for NP.

* Quarantine TestQueryCrossPartitionAggregateFunctionsWithMixedTypes

* Test fixes.

* BadRequestException fixes

* Owner attribute removed
  • Loading branch information
kirankumarkolli committed May 12, 2019
1 parent a0b2449 commit 0e21285
Show file tree
Hide file tree
Showing 17 changed files with 8,045 additions and 122 deletions.
4 changes: 4 additions & 0 deletions Microsoft.Azure.Cosmos/src/CosmosClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ static CosmosClient()
{
HttpConstants.Versions.CurrentVersion = HttpConstants.Versions.v2018_12_31;
HttpConstants.Versions.CurrentVersionUTF8 = Encoding.UTF8.GetBytes(HttpConstants.Versions.CurrentVersion);

// V3 always assumes assemblies exists
// Shall revisit on feedback
ServiceInteropWrapper.AssembliesExist = new Lazy<bool>(() => true);
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions Microsoft.Azure.Cosmos/src/Microsoft.Azure.Cosmos.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<NeutralLanguage>en-US</NeutralLanguage>
<ClientVersion>3.0.0.12-preview</ClientVersion>
<DirectVersion>3.0.0.27-preview</DirectVersion>
<DirectVersion>3.0.0.28-preview</DirectVersion>
<Version Condition=" '$(IsNightly)' == '1' ">$(ClientVersion)-nightly$(CurrentDate)</Version>
<Version Condition=" '$(IsNightly)' == '0' Or '$(IsNightly)' == '' ">$(ClientVersion)</Version>
<FileVersion>$(VersionPrefix)</FileVersion>
Expand Down Expand Up @@ -61,5 +61,5 @@
<PropertyGroup>
<DefineConstants>$(DefineConstants);DOCDBCLIENT;NETSTANDARD20</DefineConstants>
<DefineConstants Condition=" '$(SignAssembly)' == 'true' ">$(DefineConstants);SignAssembly</DefineConstants>
</PropertyGroup>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace Microsoft.Azure.Cosmos.Query
using Microsoft.Azure.Cosmos.Internal;
using Microsoft.Azure.Documents;
using Microsoft.Azure.Cosmos.CosmosElements;
using System.Net;

/// <summary>
/// CosmosOrderByItemQueryExecutionContext is a concrete implementation for CrossPartitionQueryExecutionContext.
Expand Down Expand Up @@ -385,15 +386,15 @@ private OrderByContinuationToken[] ValidateAndExtractContinuationToken(
if (suppliedOrderByContinuationTokens.Length == 0)
{
this.TraceWarning($"Order by continuation token can not be empty: {requestContinuation}.");
throw new BadRequestException(RMResources.InvalidContinuationToken);
throw new CosmosException(HttpStatusCode.BadRequest, RMResources.InvalidContinuationToken);
}

foreach (OrderByContinuationToken suppliedOrderByContinuationToken in suppliedOrderByContinuationTokens)
{
if (suppliedOrderByContinuationToken.OrderByItems.Count != sortOrders.Length)
{
this.TraceWarning($"Invalid order-by items in continuation token {requestContinuation} for OrderBy~Context.");
throw new BadRequestException(RMResources.InvalidContinuationToken);
throw new CosmosException(HttpStatusCode.BadRequest, RMResources.InvalidContinuationToken);
}
}

Expand All @@ -403,7 +404,7 @@ private OrderByContinuationToken[] ValidateAndExtractContinuationToken(
{
this.TraceWarning($"Invalid JSON in continuation token {requestContinuation} for OrderBy~Context, exception: {ex.Message}");

throw new BadRequestException(RMResources.InvalidContinuationToken, ex);
throw new CosmosException(HttpStatusCode.BadRequest, RMResources.InvalidContinuationToken);
}
}

Expand Down Expand Up @@ -478,7 +479,7 @@ private async Task FilterAsync(
CultureInfo.InvariantCulture,
"Invalid Rid in the continuation token {0} for OrderBy~Context.",
continuationToken.CompositeContinuationToken.Token));
throw new BadRequestException(RMResources.InvalidContinuationToken);
throw new CosmosException(HttpStatusCode.BadRequest, RMResources.InvalidContinuationToken);
}

resourceIds.Add(orderByResult.Rid, rid);
Expand All @@ -492,7 +493,7 @@ private async Task FilterAsync(
CultureInfo.InvariantCulture,
"Invalid Rid in the continuation token {0} for OrderBy~Context.",
continuationToken.CompositeContinuationToken.Token));
throw new BadRequestException(RMResources.InvalidContinuationToken);
throw new CosmosException(HttpStatusCode.BadRequest, RMResources.InvalidContinuationToken);
}

continuationRidVerified = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace Microsoft.Azure.Cosmos.Query
using Microsoft.Azure.Cosmos.Internal;
using Microsoft.Azure.Documents;
using Microsoft.Azure.Cosmos.CosmosElements;
using System.Net;

/// <summary>
/// CosmosParallelItemQueryExecutionContext is a concrete implementation for CrossPartitionQueryExecutionContext.
Expand Down Expand Up @@ -200,7 +201,7 @@ private async Task InitializeAsync(
CultureInfo.InvariantCulture,
"Invalid Range in the continuation token {0} for Parallel~Context.",
requestContinuation));
throw new BadRequestException(RMResources.InvalidContinuationToken);
throw new CosmosException(HttpStatusCode.BadRequest, RMResources.InvalidContinuationToken);
}
}

Expand All @@ -210,7 +211,7 @@ private async Task InitializeAsync(
CultureInfo.InvariantCulture,
"Invalid format for continuation token {0} for Parallel~Context.",
requestContinuation));
throw new BadRequestException(RMResources.InvalidContinuationToken);
throw new CosmosException(HttpStatusCode.BadRequest, RMResources.InvalidContinuationToken);
}
}
catch (JsonException ex)
Expand All @@ -221,7 +222,7 @@ private async Task InitializeAsync(
requestContinuation,
ex.Message));

throw new BadRequestException(RMResources.InvalidContinuationToken, ex);
throw new CosmosException(HttpStatusCode.BadRequest, RMResources.InvalidContinuationToken);
}

filteredPartitionKeyRanges = this.GetPartitionKeyRangesForContinuation(suppliedCompositeContinuationTokens, partitionKeyRanges, out targetIndicesForFullContinuation);
Expand Down
2 changes: 1 addition & 1 deletion Microsoft.Azure.Cosmos/src/Query/CosmosQueryContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class CosmosQueryContext
public virtual ResourceType ResourceTypeEnum { get; }
public virtual OperationType OperationTypeEnum { get; }
public virtual Type ResourceType { get; }
public virtual SqlQuerySpec SqlQuerySpec { get; }
public SqlQuerySpec SqlQuerySpec { get; internal set; }
public virtual QueryRequestOptions QueryRequestOptions { get; }
public virtual bool IsContinuationExpected { get; }
public virtual bool AllowNonValueAggregateQuery { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private async Task<CosmosContainerSettings> GetContainerSettingsAsync(Cancellati
{
cancellationToken.ThrowIfCancellationRequested();

CosmosContainerSettings containerSettings;
CosmosContainerSettings containerSettings = null;
if (this.cosmosQueryContext.ResourceTypeEnum.IsCollectionChild())
{
CollectionCache collectionCache = await this.cosmosQueryContext.QueryClient.GetCollectionCacheAsync();
Expand All @@ -145,11 +145,6 @@ private async Task<CosmosContainerSettings> GetContainerSettingsAsync(Cancellati
{
containerSettings = await collectionCache.ResolveCollectionAsync(request, cancellationToken);
}

}
else
{
containerSettings = null;
}

if (containerSettings == null)
Expand Down Expand Up @@ -263,6 +258,13 @@ public static async Task<CosmosQueryExecutionContext> CreateSpecializedDocumentQ
string collectionRid,
CancellationToken cancellationToken)
{
if (!string.IsNullOrEmpty(partitionedQueryExecutionInfo.QueryInfo?.RewrittenQuery))
{
cosmosQueryContext.SqlQuerySpec = new SqlQuerySpec(
partitionedQueryExecutionInfo.QueryInfo.RewrittenQuery,
cosmosQueryContext.SqlQuerySpec.Parameters);
}

// Figure out the optimal page size.
long initialPageSize = cosmosQueryContext.QueryRequestOptions.MaxItemCount.GetValueOrDefault(ParallelQueryConfig.GetConfig().ClientInternalPageSize);

Expand Down Expand Up @@ -346,6 +348,7 @@ internal static async Task<List<PartitionKeyRange>> GetTargetPartitionKeyRanges(
List<PartitionKeyRange> targetRanges;
if (queryRequestOptions.PartitionKey != null)
{
// Dis-ambiguate the NonePK if used
PartitionKeyInternal partitionKeyInternal = null;
if (Object.ReferenceEquals(queryRequestOptions.PartitionKey, CosmosContainerSettings.NonePartitionKeyValue))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Microsoft.Azure.Cosmos.Query.ExecutionComponent
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos;
Expand Down Expand Up @@ -49,7 +50,7 @@ public static async Task<TakeDocumentQueryExecutionComponent> CreateLimitDocumen

if (limitContinuationToken.Limit > limitCount)
{
throw new BadRequestException($"limit count in continuation token: {limitContinuationToken.Limit} can not be greater than the limit count in the query: {limitCount}.");
throw new CosmosException(HttpStatusCode.BadRequest, $"limit count in continuation token: {limitContinuationToken.Limit} can not be greater than the limit count in the query: {limitCount}.");
}

return new TakeDocumentQueryExecutionComponent(
Expand All @@ -75,7 +76,7 @@ public static async Task<TakeDocumentQueryExecutionComponent> CreateTopDocumentQ

if (topContinuationToken.Top > topCount)
{
throw new BadRequestException($"top count in continuation token: {topContinuationToken.Top} can not be greater than the top count in the query: {topCount}.");
throw new CosmosException(HttpStatusCode.BadRequest, $"top count in continuation token: {topContinuationToken.Top} can not be greater than the top count in the query: {topCount}.");
}

return new TakeDocumentQueryExecutionComponent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ private void PopulatePartitionKeyRangeInfo(CosmosRequestMessage request)
if (this.queryContext.ResourceTypeEnum.IsPartitioned())
{
// If the request already has the logical partition key,
// then we shouldn't add the physical partiton key range id.
// then we shouldn't add the physical partition key range id.

bool hasPartitionKey = request.Headers.Get(HttpConstants.HttpHeaders.PartitionKey) != null;
if (!hasPartitionKey)
Expand Down
7 changes: 4 additions & 3 deletions Microsoft.Azure.Cosmos/src/Query/QueryPartitionProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,10 @@ internal PartitionedQueryExecutionInfoInternal GetPartitionedQueryExecutionInfoI
if (exception != null)
{
DefaultTrace.TraceInformation("QueryEngineConfiguration: " + this.queryengineConfiguration);
throw new BadRequestException(
"Message: " + serializedQueryExecutionInfo,
exception);

throw new CosmosException(
HttpStatusCode.BadRequest,
"Message: " + serializedQueryExecutionInfo);
}

PartitionedQueryExecutionInfoInternal queryInfoInternal =
Expand Down
13 changes: 12 additions & 1 deletion Microsoft.Azure.Cosmos/src/Resource/CosmosException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ public class CosmosException : Exception
{
private readonly CosmosResponseMessageHeaders Headers = null;

internal CosmosException(
HttpStatusCode statusCode,
string message,
Error error = null) :
base(message)
{
this.StatusCode = statusCode;
this.Error = error;
}

internal CosmosException(
CosmosResponseMessage cosmosResponseMessage,
string message,
Expand All @@ -30,7 +40,6 @@ internal CosmosException(
this.ActivityId = this.Headers?.GetHeaderValue<string>(HttpConstants.HttpHeaders.ActivityId);
this.RequestCharge = this.Headers == null ? 0 : this.Headers.GetHeaderValue<double>(HttpConstants.HttpHeaders.RequestCharge);
this.SubStatusCode = (int)this.Headers.SubStatusCode;
this.Error = error;
if (cosmosResponseMessage.Headers.ContentLengthAsLong > 0)
{
using (StreamReader responseReader = new StreamReader(cosmosResponseMessage.Content))
Expand All @@ -39,6 +48,8 @@ internal CosmosException(
}
}
}

this.Error = error;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,12 @@ internal FeedIteratorCore(
/// </summary>
/// <param name="cancellationToken">(Optional) <see cref="CancellationToken"/> representing request cancellation.</param>
/// <returns>A query response from cosmos service</returns>
public override Task<CosmosResponseMessage> FetchNextSetAsync(CancellationToken cancellationToken = default(CancellationToken))
public override async Task<CosmosResponseMessage> FetchNextSetAsync(CancellationToken cancellationToken = default(CancellationToken))
{
return this.nextResultSetDelegate(this.MaxItemCount, this.continuationToken, this.queryOptions, this.state, cancellationToken)
.ContinueWith(task =>
{
CosmosResponseMessage response = task.Result;
this.continuationToken = response.Headers.Continuation;
this.HasMoreResults = GetHasMoreResults(this.continuationToken, response.StatusCode);
return response;
}, cancellationToken);
CosmosResponseMessage response = await this.nextResultSetDelegate(this.MaxItemCount, this.continuationToken, this.queryOptions, this.state, cancellationToken);
this.continuationToken = response.Headers.Continuation;
this.HasMoreResults = GetHasMoreResults(this.continuationToken, response.StatusCode);
return response;
}

internal static string GetContinuationToken(CosmosResponseMessage httpResponseMessage)
Expand Down Expand Up @@ -149,19 +145,15 @@ internal FeedIteratorCore(
/// </summary>
/// <param name="cancellationToken">(Optional) <see cref="CancellationToken"/> representing request cancellation.</param>
/// <returns>A query response from cosmos service</returns>
public override Task<FeedResponse<T>> FetchNextSetAsync(CancellationToken cancellationToken = default(CancellationToken))
public override async Task<FeedResponse<T>> FetchNextSetAsync(CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();

return this.nextResultSetDelegate(this.MaxItemCount, this.continuationToken, this.queryOptions, this.state, cancellationToken)
.ContinueWith(task =>
{
FeedResponse<T> response = task.Result;
this.HasMoreResults = response.HasMoreResults;
this.continuationToken = response.InternalContinuationToken;
return response;
}, cancellationToken);
FeedResponse<T> response = await this.nextResultSetDelegate(this.MaxItemCount, this.continuationToken, this.queryOptions, this.state, cancellationToken);
this.HasMoreResults = response.HasMoreResults;
this.continuationToken = response.InternalContinuationToken;
return response;

}

internal static ReadFeedResponse<T> CreateCosmosQueryResponse(
Expand Down
Loading

0 comments on commit 0e21285

Please sign in to comment.