Skip to content

Commit

Permalink
Merge branch 'master' into users/ezrahaleva/MakeListDistribution
Browse files Browse the repository at this point in the history
  • Loading branch information
ezrahaleva-msft committed Jun 20, 2024
2 parents 710fc76 + 272e844 commit be853ce
Show file tree
Hide file tree
Showing 26 changed files with 1,128 additions and 85 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<EncryptionOfficialVersion>2.0.4</EncryptionOfficialVersion>
<EncryptionPreviewVersion>2.1.0</EncryptionPreviewVersion>
<EncryptionPreviewSuffixVersion>preview4</EncryptionPreviewSuffixVersion>
<CustomEncryptionVersion>1.0.0-preview06</CustomEncryptionVersion>
<CustomEncryptionVersion>1.0.0-preview07</CustomEncryptionVersion>
<HybridRowVersion>1.1.0-preview3</HybridRowVersion>
<LangVersion>10.0</LangVersion>
<AboveDirBuildProps>$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))</AboveDirBuildProps>
Expand Down
5 changes: 5 additions & 0 deletions Microsoft.Azure.Cosmos.Encryption.Custom/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ Preview features are treated as a separate branch and will not be included in th
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

### <a name="1.0.0-preview07"/> [1.0.0-preview07](https://www.nuget.org/packages/Microsoft.Azure.Cosmos.Encryption.Custom/1.0.0-preview07) - 2024-06-12

#### Fixes
- [#4546](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/4546) Updates package reference Microsoft.Azure.Cosmos to version 3.41.0-preview and 3.40.0 for preview and stable version support.

### <a name="1.0.0-preview06"/> [1.0.0-preview06](https://www.nuget.org/packages/Microsoft.Azure.Cosmos.Encryption.Custom/1.0.0-preview06) - 2023-06-28

#### Fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1020,12 +1020,8 @@ public override Task<ResponseMessage> DeleteAllItemsByPartitionKeyStreamAsync(
requestOptions,
cancellationToken);
}
#endif

#if SDKPROJECTREF
public override ChangeFeedProcessorBuilder GetChangeFeedProcessorBuilderWithAllVersionsAndDeletes<T>(
string processorName,
ChangeFeedHandler<ChangeFeedItem<T>> onChangesDelegate)
public override ChangeFeedProcessorBuilder GetChangeFeedProcessorBuilderWithAllVersionsAndDeletes<T>(string processorName, ChangeFeedHandler<ChangeFeedItem<T>> onChangesDelegate)
{
return this.container.GetChangeFeedProcessorBuilderWithAllVersionsAndDeletes(
processorName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
</ItemGroup>

<ItemGroup Condition=" '$(SdkProjectRef)' != 'True' AND '$(IsPreview)' != 'True' ">
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.32.3" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.40.0" />
</ItemGroup>

<ItemGroup Condition=" '$(SdkProjectRef)' != 'True' AND '$(IsPreview)' == 'True' ">
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.35.1-preview" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.41.0-preview.0" />
</ItemGroup>

<ItemGroup Condition=" '$(SdkProjectRef)' == 'True' ">
Expand All @@ -36,7 +36,7 @@

<ItemGroup>
<PackageReference Include="Azure.Core" Version="1.38.0" />
<PackageReference Include="Azure.Identity" Version="1.11.0" />
<PackageReference Include="Azure.Identity" Version="1.11.4" />
<PackageReference Include="Microsoft.Data.Encryption.Cryptography" Version="0.2.0-pre" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,14 @@ public async Task EncryptionCreateItem()

TestDoc expectedDoc = new TestDoc(testDoc);

#if SDKPROJECTREF
// FIXME Remove the above once the binary encoding issue is fixed.
// Read feed (null query)
await LegacyEncryptionTests.ValidateQueryResultsAsync(
LegacyEncryptionTests.encryptionContainer,
query: null,
expectedDoc);
#endif

await LegacyEncryptionTests.ValidateQueryResultsAsync(
LegacyEncryptionTests.encryptionContainer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,11 +441,14 @@ public async Task EncryptionCreateItem()

TestDoc expectedDoc = new TestDoc(testDoc);

#if SDKPROJECTREF
// FIXME Remove the above once the binary encoding issue is fixed.
// Read feed (null query)
await MdeCustomEncryptionTests.ValidateQueryResultsAsync(
MdeCustomEncryptionTests.encryptionContainer,
query: null,
expectedDoc);
#endif

await MdeCustomEncryptionTests.ValidateQueryResultsAsync(
MdeCustomEncryptionTests.encryptionContainer,
Expand Down Expand Up @@ -1043,7 +1046,7 @@ public async Task VerifyDekOperationWithSystemTextSerializer()
DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull
};

CosmosSystemTextJsonSerializer cosmosSystemTextJsonSerializer = new CosmosSystemTextJsonSerializer(jsonSerializerOptions);
LegacyEncryptionTests.CosmosSystemTextJsonSerializer cosmosSystemTextJsonSerializer = new (jsonSerializerOptions);

CosmosClient clientWithCosmosSystemTextJsonSerializer = TestCommon.CreateCosmosClient(builder => builder
.WithCustomSerializer(cosmosSystemTextJsonSerializer)
Expand Down Expand Up @@ -2263,7 +2266,7 @@ public override async Task<byte[]> EncryptAsync(


#region Legacy
#pragma warning disable CS0618 // Type or member is obsolete
#pragma warning disable CS0618 // Type or member is obsolete
[TestMethod]
public async Task EncryptionCreateDekWithDualDekProvider()
{
Expand Down Expand Up @@ -2477,12 +2480,15 @@ public async Task ReadLegacyEncryptedDataWithMdeProcessor()

TestDoc expectedDoc = new TestDoc(testDoc);

#if SDKPROJECTREF
// FIXME Remove the above once the binary encoding issue is fixed.
// Read feed (null query)
await MdeCustomEncryptionTests.ValidateQueryResultsAsync(
MdeCustomEncryptionTests.encryptionContainer,
query: null,
expectedDoc,
legacyAlgo: true);
#endif

await MdeCustomEncryptionTests.ValidateQueryResultsAsync(
MdeCustomEncryptionTests.encryptionContainer,
Expand Down Expand Up @@ -2651,7 +2657,7 @@ public override Task<EncryptionKeyWrapResult> WrapKeyAsync(byte[] key, Encryptio
}
}

#pragma warning restore CS0618 // Type or member is obsolete
#endregion
#pragma warning restore CS0618 // Type or member is obsolete
#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ await CosmosEncryptorTests.cosmosEncryptor.EncryptAsync(
}
catch (InvalidOperationException ex)
{
Assert.AreEqual("Null DataEncryptionKey returned from FetchDataEncryptionKeyAsync.", ex.Message);
Assert.AreEqual("Null DataEncryptionKey returned from FetchDataEncryptionKeyWithoutRawKeyAsync.", ex.Message);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,5 +237,20 @@ internal FaultInjectionDynamicChannelStore GetChannelStore()
{
return this.channelStore;
}

public Task<(bool, StoreResponse)> OnHttpRequestCallAsync(DocumentServiceRequest request)
{
throw new NotImplementedException();
}

public Task OnBeforeHttpSendAsync(DocumentServiceRequest request)
{
throw new NotImplementedException();
}

public Task OnAfterHttpSendAsync(DocumentServiceRequest request)
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.11.0" />
<PackageReference Include="Azure.Identity" Version="1.11.4" />
<PackageReference Include="Azure.Security.KeyVault.Keys" Version="4.2.0" />
<PackageReference Include="Microsoft.Azure.Cosmos.Encryption" Version="1.0.0-previewV20" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,24 @@ public async ValueTask<bool> MoveNextAsync(ITrace trace, CancellationToken cance
else
{
// left most and any non null continuations
IOrderedEnumerable<FeedRangeState<QueryState>> feedRangeStates = crossPartitionState
.Value
.ToArray()
.OrderBy(tuple => ((FeedRangeEpk)tuple.FeedRange).Range.Min);
FeedRangeState<QueryState>[] feedRangeStates = crossPartitionState.Value.ToArray();
Array.Sort<FeedRangeState<QueryState>>(feedRangeStates, (x, y) => string.CompareOrdinal(((FeedRangeEpk)x.FeedRange).Range.Min, ((FeedRangeEpk)y.FeedRange).Range.Min));

List<ParallelContinuationToken> activeParallelContinuationTokens = new List<ParallelContinuationToken>();
{
FeedRangeState<QueryState> firstState = feedRangeStates.First();
FeedRangeState<QueryState> firstState = feedRangeStates[0];
ParallelContinuationToken firstParallelContinuationToken = new ParallelContinuationToken(
token: firstState.State != null ? ((CosmosString)firstState.State.Value).Value : null,
range: ((FeedRangeEpk)firstState.FeedRange).Range);

activeParallelContinuationTokens.Add(firstParallelContinuationToken);
}

foreach (FeedRangeState<QueryState> feedRangeState in feedRangeStates.Skip(1))
for (int i = 1; i < feedRangeStates.Length; i++)
{
cancellationToken.ThrowIfCancellationRequested();

FeedRangeState<QueryState> feedRangeState = feedRangeStates[i];
if (feedRangeState.State != null)
{
ParallelContinuationToken parallelContinuationToken = new ParallelContinuationToken(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,15 @@ internal TryCatch<PartitionedQueryExecutionInfoInternal> TryGetPartitionedQueryE

fixed (byte* bytePtr2 = buffer)
{
errorCode = ServiceInteropWrapper.GetPartitionKeyRangesFromQuery3(
errorCode = ServiceInteropWrapper.GetPartitionKeyRangesFromQuery4(
this.serviceProvider,
querySpecJsonString,
partitionKeyRangesApiOptions,
allParts,
partsLengths,
(uint)partitionKeyDefinition.Paths.Count,
vectorEmbeddingPolicyString,
vectorEmbeddingPolicyString?.Length ?? 0,
new IntPtr(bytePtr2),
(uint)buffer.Length,
out serializedQueryExecutionInfoResultLength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,55 +19,36 @@ namespace Microsoft.Azure.Cosmos
#endif
class ChangeFeedMetadata
{
/// <summary>
/// New instance of meta data for <see cref="ChangeFeedItem{T}"/> created.
/// </summary>
/// <param name="conflictResolutionTimestamp"></param>
/// <param name="lsn"></param>
/// <param name="operationType"></param>
/// <param name="previousLsn"></param>
public ChangeFeedMetadata(
DateTime conflictResolutionTimestamp,
long lsn,
ChangeFeedOperationType operationType,
long previousLsn)
{
this.ConflictResolutionTimestamp = conflictResolutionTimestamp;
this.Lsn = lsn;
this.OperationType = operationType;
this.PreviousLsn = previousLsn;
}

/// <summary>
/// The conflict resolution timestamp.
/// </summary>
[JsonProperty(PropertyName = "crts", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(UnixDateTimeConverter))]
public DateTime ConflictResolutionTimestamp { get; }
public DateTime ConflictResolutionTimestamp { get; internal set; }

/// <summary>
/// The current logical sequence number.
/// </summary>
[JsonProperty(PropertyName = "lsn", NullValueHandling = NullValueHandling.Ignore)]
public long Lsn { get; }
public long Lsn { get; internal set; }

/// <summary>
/// The change feed operation type.
/// </summary>
[JsonProperty(PropertyName = "operationType")]
[JsonConverter(typeof(StringEnumConverter))]
public ChangeFeedOperationType OperationType { get; }
public ChangeFeedOperationType OperationType { get; internal set; }

/// <summary>
/// The previous logical sequence number.
/// </summary>
[JsonProperty(PropertyName = "previousImageLSN", NullValueHandling = NullValueHandling.Ignore)]
public long PreviousLsn { get; }
public long PreviousLsn { get; internal set; }

/// <summary>
/// Used to distinquish explicit deletes (e.g. via DeleteItem) from deletes caused by TTL expiration (a collection may define time-to-live policy for documents).
/// </summary>
[JsonProperty(PropertyName = "timeToLiveExpired", NullValueHandling= NullValueHandling.Ignore)]
public bool IsTimeToLiveExpired { get; }
public bool IsTimeToLiveExpired { get; internal set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// ------------------------------------------------------------

namespace Microsoft.Azure.Cosmos
{
using System;
using System.IO;
using System.Reflection;
using System.Text.Json;
using System.Text.Json.Serialization;

/// <summary>
/// This class provides a default implementation of System.Text.Json Cosmos Linq Serializer.
/// </summary>
internal class CosmosSystemTextJsonSerializer : CosmosLinqSerializer
{
/// <summary>
/// A read-only instance of <see cref="JsonSerializerOptions"/>.
/// </summary>
private readonly JsonSerializerOptions jsonSerializerOptions;

/// <summary>
/// Creates an instance of <see cref="CosmosSystemTextJsonSerializer"/>
/// with the default values for the Cosmos SDK
/// </summary>
/// <param name="jsonSerializerOptions">An instance of <see cref="JsonSerializerOptions"/> containing the json serialization options.</param>
internal CosmosSystemTextJsonSerializer(
JsonSerializerOptions jsonSerializerOptions)
{
this.jsonSerializerOptions = jsonSerializerOptions;
}

/// <inheritdoc/>
public override T FromStream<T>(Stream stream)
{
if (stream == null)
throw new ArgumentNullException(nameof(stream));

if (typeof(Stream).IsAssignableFrom(typeof(T)))
{
return (T)(object)stream;
}

if (stream.CanSeek && stream.Length == 0)
{
return default;
}

using (stream)
{
using StreamReader reader = new (stream);
return JsonSerializer.Deserialize<T>(reader.ReadToEnd(), this.jsonSerializerOptions);
}
}

/// <inheritdoc/>
public override Stream ToStream<T>(T input)
{
MemoryStream streamPayload = new ();
using Utf8JsonWriter writer = new (streamPayload);

JsonSerializer.Serialize(writer, input, this.jsonSerializerOptions);

streamPayload.Position = 0;
return streamPayload;
}

/// <summary>
/// Convert a MemberInfo to a string for use in LINQ query translation.
/// </summary>
/// <param name="memberInfo">Any MemberInfo used in the query.</param>
/// <returns>A serialized representation of the member.</returns>
/// <remarks>
/// Note that this is just a default implementation which handles the basic scenarios.To handle any special cases,
/// please create a custom serializer which inherits from the <see cref="CosmosSystemTextJsonSerializer"/> and overrides the
/// SerializeMemberName() method.
/// </remarks>
public override string SerializeMemberName(MemberInfo memberInfo)
{
JsonExtensionDataAttribute jsonExtensionDataAttribute =
memberInfo.GetCustomAttribute<JsonExtensionDataAttribute>(true);

if (jsonExtensionDataAttribute != null)
{
return null;
}

JsonPropertyNameAttribute jsonPropertyNameAttribute = memberInfo.GetCustomAttribute<JsonPropertyNameAttribute>(true);

if (!string.IsNullOrEmpty(jsonPropertyNameAttribute?.Name))
{
return jsonPropertyNameAttribute.Name;
}

if (this.jsonSerializerOptions.PropertyNamingPolicy != null)
{
return this.jsonSerializerOptions.PropertyNamingPolicy.ConvertName(memberInfo.Name);
}

return memberInfo.Name;
}
}
}
Loading

0 comments on commit be853ce

Please sign in to comment.