Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Downgrade to Microsoft.Azure.Cosmos 3.12.0 #22197

Merged
1 commit merged into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ updates:
- dependency-name: Castle.Core
- dependency-name: Humanizer.Core
- dependency-name: IdentityServer4.EntityFramework
- dependency-name: Azure.Cosmos
- dependency-name: Microsoft.Azure.Cosmos
- dependency-name: Microsoft.CSharp
- dependency-name: Microsoft.Data.SqlClient
- dependency-name: Microsoft.DotNet.PlatformAbstractions
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Cosmos/EFCore.Cosmos.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All" />
<PackageReference Include="Azure.Cosmos" Version="4.0.0-preview3" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.12.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using Azure.Cosmos;
using JetBrains.Annotations;
using Microsoft.Azure.Cosmos;
using Microsoft.EntityFrameworkCore.Cosmos.Infrastructure.Internal;
using Microsoft.EntityFrameworkCore.Cosmos.Internal;
using Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
using System;
using System.ComponentModel;
using System.Net;
using Azure.Cosmos;
using JetBrains.Annotations;
using Microsoft.Azure.Cosmos;
using Microsoft.EntityFrameworkCore.Cosmos.Infrastructure.Internal;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
using System.Globalization;
using System.Net;
using System.Text;
using Azure.Cosmos;
using JetBrains.Annotations;
using Microsoft.Azure.Cosmos;
using Microsoft.EntityFrameworkCore.Cosmos.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System;
using System.Net;
using Azure.Cosmos;
using Microsoft.Azure.Cosmos;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.Extensions.DependencyInjection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System;
using System.Net;
using Azure.Cosmos;
using Microsoft.Azure.Cosmos;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.Extensions.DependencyInjection;

Expand Down
92 changes: 40 additions & 52 deletions src/EFCore.Cosmos/Storage/Internal/CosmosClientWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Azure;
using Azure.Cosmos;
using JetBrains.Annotations;
using Microsoft.Azure.Cosmos;
using Microsoft.EntityFrameworkCore.Cosmos.Diagnostics.Internal;
using Microsoft.EntityFrameworkCore.Cosmos.Infrastructure.Internal;
using Microsoft.EntityFrameworkCore.Diagnostics;
Expand Down Expand Up @@ -141,7 +140,7 @@ public virtual async Task<bool> CreateDatabaseIfNotExistsOnceAsync(
var response = await Client.CreateDatabaseIfNotExistsAsync(_databaseId, cancellationToken: cancellationToken)
.ConfigureAwait(false);

return response.GetRawResponse().Status == (int)HttpStatusCode.Created;
return response.StatusCode == HttpStatusCode.Created;
}

/// <summary>
Expand Down Expand Up @@ -188,13 +187,13 @@ public virtual async Task<bool> DeleteDatabaseOnceAsync(
{
using var response = await Client.GetDatabase(_databaseId).DeleteStreamAsync(cancellationToken: cancellationToken)
.ConfigureAwait(false);
if (response.Status == (int)HttpStatusCode.NotFound)
if (response.StatusCode == HttpStatusCode.NotFound)
{
return false;
}

EnsureSuccessStatusCode(response);
return response.Status == (int)HttpStatusCode.NoContent;
response.EnsureSuccessStatusCode();
return response.StatusCode == HttpStatusCode.NoContent;
}

/// <summary>
Expand Down Expand Up @@ -239,13 +238,13 @@ private async Task<bool> CreateContainerIfNotExistsOnceAsync(
},
cancellationToken: cancellationToken)
.ConfigureAwait(false);
if (response.Status == (int)HttpStatusCode.Conflict)
if (response.StatusCode == HttpStatusCode.Conflict)
{
return false;
}

EnsureSuccessStatusCode(response);
return response.Status == (int)HttpStatusCode.Created;
response.EnsureSuccessStatusCode();
return response.StatusCode == HttpStatusCode.Created;
}

/// <summary>
Expand Down Expand Up @@ -300,7 +299,7 @@ private async Task<bool> CreateItemOnceAsync(
.ConfigureAwait(false);
ProcessResponse(response, entry);

return response.Status == (int)HttpStatusCode.Created;
return response.StatusCode == HttpStatusCode.Created;
}

/// <summary>
Expand Down Expand Up @@ -363,7 +362,7 @@ private async Task<bool> ReplaceItemOnceAsync(
.ConfigureAwait(false);
ProcessResponse(response, entry);

return response.Status == (int)HttpStatusCode.OK;
return response.StatusCode == HttpStatusCode.OK;
}

/// <summary>
Expand Down Expand Up @@ -425,7 +424,7 @@ public virtual async Task<bool> DeleteItemOnceAsync(
.ConfigureAwait(false);
ProcessResponse(response, entry);

return response.Status == (int)HttpStatusCode.NoContent;
return response.StatusCode == HttpStatusCode.NoContent;
}

private static ItemRequestOptions CreateItemRequestOptions(IUpdateEntry entry)
Expand All @@ -443,7 +442,7 @@ private static ItemRequestOptions CreateItemRequestOptions(IUpdateEntry entry)
etag = converter.ConvertToProvider(etag);
}

return new ItemRequestOptions { IfMatch = new ETag((string)etag) };
return new ItemRequestOptions { IfMatchEtag = (string)etag };
}

private static PartitionKey CreatePartitionKey(IUpdateEntry entry)
Expand All @@ -465,21 +464,21 @@ private static PartitionKey CreatePartitionKey(IUpdateEntry entry)
return partitionKey == null ? PartitionKey.None : new PartitionKey((string)partitionKey);
}

private static void ProcessResponse(Response response, IUpdateEntry entry)
private static void ProcessResponse(ResponseMessage response, IUpdateEntry entry)
{
EnsureSuccessStatusCode(response);
response.EnsureSuccessStatusCode();
var etagProperty = entry.EntityType.GetETagProperty();
if (etagProperty != null && entry.EntityState != EntityState.Deleted)
{
entry.SetStoreGeneratedValue(etagProperty, response.Headers.ETag?.ToString());
entry.SetStoreGeneratedValue(etagProperty, response.Headers.ETag);
}

var jObjectProperty = entry.EntityType.FindProperty(StoreKeyConvention.JObjectPropertyName);
if (jObjectProperty != null
&& jObjectProperty.ValueGenerated == ValueGenerated.OnAddOrUpdate
&& response.ContentStream != null)
&& response.Content != null)
{
using var responseStream = response.ContentStream;
using var responseStream = response.Content;
using var reader = new StreamReader(responseStream);
using var jsonReader = new JsonTextReader(reader);

Expand Down Expand Up @@ -561,11 +560,11 @@ internal virtual async Task<JObject> ExecuteReadItemAsync(
return JObjectFromReadItemResponseMessage(responseMessage);
}

private static JObject JObjectFromReadItemResponseMessage(Response response)
private static JObject JObjectFromReadItemResponseMessage(ResponseMessage responseMessage)
{
EnsureSuccessStatusCode(response);
responseMessage.EnsureSuccessStatusCode();

var responseStream = response.ContentStream;
var responseStream = responseMessage.Content;
var reader = new StreamReader(responseStream);
var jsonReader = new JsonTextReader(reader);

Expand All @@ -574,7 +573,7 @@ private static JObject JObjectFromReadItemResponseMessage(Response response)
return new JObject(new JProperty("c", jObject));
}

private IAsyncEnumerable<Response> CreateQuery(
private FeedIterator CreateQuery(
string containerId,
string partitionKey,
CosmosSqlQuery query)
Expand All @@ -597,7 +596,7 @@ private IAsyncEnumerable<Response> CreateQuery(
return container.GetItemQueryStreamIterator(queryDefinition, requestOptions: queryRequestOptions);
}

private async Task<Response> CreateSingleItemQuery(
private async Task<ResponseMessage> CreateSingleItemQuery(
string containerId,
string partitionKey,
string resourceId,
Expand Down Expand Up @@ -647,19 +646,9 @@ private static bool TryReadJObject(JsonTextReader jsonReader, out JObject jObjec
return true;
}
}

return false;
}

private static void EnsureSuccessStatusCode(Response response)
{
var httpStatusCode = response.Status;
if (httpStatusCode < 200 || httpStatusCode > 299)
{
throw new HttpException(response);
}
}

private sealed class DocumentEnumerable : IEnumerable<JObject>
{
private readonly CosmosClientWrapper _cosmosClient;
Expand Down Expand Up @@ -692,12 +681,12 @@ private sealed class Enumerator : IEnumerator<JObject>
private readonly string _partitionKey;
private readonly CosmosSqlQuery _cosmosSqlQuery;

private Response _response;
private ResponseMessage _responseMessage;
private Stream _responseStream;
private StreamReader _reader;
private JsonTextReader _jsonReader;

private IAsyncEnumerator<Response> _query;
private FeedIterator _query;

public Enumerator(DocumentEnumerable documentEnumerable)
{
Expand All @@ -717,18 +706,18 @@ public bool MoveNext()
{
if (_jsonReader == null)
{
_query ??= _cosmosClientWrapper.CreateQuery(_containerId, _partitionKey, _cosmosSqlQuery).GetAsyncEnumerator();
_query ??= _cosmosClientWrapper.CreateQuery(_containerId, _partitionKey, _cosmosSqlQuery);

if (!_query.MoveNextAsync().AsTask().GetAwaiter().GetResult())
if (!_query.HasMoreResults)
{
Current = default;
return false;
}

_response = _query.Current;
EnsureSuccessStatusCode(_response);
_responseMessage = _query.ReadNextAsync().GetAwaiter().GetResult();
_responseMessage.EnsureSuccessStatusCode();

_responseStream = _response.ContentStream;
_responseStream = _responseMessage.Content;
_reader = new StreamReader(_responseStream);
_jsonReader = CreateJsonReader(_reader);
}
Expand Down Expand Up @@ -758,8 +747,8 @@ public void Dispose()
{
ResetRead();

_response?.Dispose();
_response = null;
_responseMessage?.Dispose();
_responseMessage = null;
}

public void Reset()
Expand Down Expand Up @@ -797,12 +786,12 @@ private sealed class AsyncEnumerator : IAsyncEnumerator<JObject>
private readonly CosmosSqlQuery _cosmosSqlQuery;
private readonly CancellationToken _cancellationToken;

private Response _response;
private ResponseMessage _responseMessage;
private Stream _responseStream;
private StreamReader _reader;
private JsonTextReader _jsonReader;

private IAsyncEnumerator<Response> _query;
private FeedIterator _query;

public JObject Current { get; private set; }

Expand All @@ -822,19 +811,18 @@ public async ValueTask<bool> MoveNextAsync()

if (_jsonReader == null)
{
_query ??= _cosmosClientWrapper.CreateQuery(_containerId, _partitionKey, _cosmosSqlQuery)
.GetAsyncEnumerator(_cancellationToken);
_query ??= _cosmosClientWrapper.CreateQuery(_containerId, _partitionKey, _cosmosSqlQuery);

if (!await _query.MoveNextAsync().ConfigureAwait(false))
if (!_query.HasMoreResults)
{
Current = default;
return false;
}

_response = _query.Current;
EnsureSuccessStatusCode(_response);
_responseMessage = await _query.ReadNextAsync(_cancellationToken).ConfigureAwait(false);
_responseMessage.EnsureSuccessStatusCode();

_responseStream = _response.ContentStream;
_responseStream = _responseMessage.Content;
_reader = new StreamReader(_responseStream);
_jsonReader = CreateJsonReader(_reader);
}
Expand Down Expand Up @@ -864,8 +852,8 @@ public async ValueTask DisposeAsync()
{
await ResetReadAsync().ConfigureAwait(false);

await _response.DisposeAsyncIfAvailable().ConfigureAwait(false);
_response = null;
await _responseMessage.DisposeAsyncIfAvailable().ConfigureAwait(false);
_responseMessage = null;
}
}
}
Expand Down
Loading