From 5d36ba727693ea5bcaf455d03e0dcf12a42dc8fc Mon Sep 17 00:00:00 2001 From: philipthomas Date: Mon, 25 Mar 2024 15:15:38 -0400 Subject: [PATCH 1/8] preview cfp ffcf --- .../src/Resource/Container/Container.cs | 78 ++++++++++++++++++- .../Resource/Container/ContainerInlineCore.cs | 10 --- .../Resource/Container/ContainerInternal.cs | 73 +---------------- 3 files changed, 77 insertions(+), 84 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Resource/Container/Container.cs b/Microsoft.Azure.Cosmos/src/Resource/Container/Container.cs index 5936f5e05d..2ee396cac6 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Container/Container.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Container/Container.cs @@ -10,7 +10,6 @@ namespace Microsoft.Azure.Cosmos using System.Linq; using System.Threading; using System.Threading.Tasks; - using Microsoft.Azure.Cosmos.Serializer; /// /// Operations for reading, replacing, or deleting a specific, existing container or item in a container by id. @@ -1681,6 +1680,81 @@ public abstract Task DeleteAllItemsByPartitionKeyStreamAsync( public abstract Task> GetPartitionKeyRangesAsync( FeedRange feedRange, CancellationToken cancellationToken = default); + + /// + /// Initializes a for change feed processing with all versions and deletes. + /// + /// Document type + /// A name that identifies the Processor and the particular work it will do. + /// Delegate to receive all changes and deletes + /// + /// + /// > documents, CancellationToken token) => + /// { + /// Console.WriteLine($"number of documents processed: {documents.Count}"); + /// + /// string id = default; + /// string pk = default; + /// string description = default; + /// + /// foreach (ChangeFeedItemChange changeFeedItem in documents) + /// { + /// if (changeFeedItem.Metadata.OperationType != ChangeFeedOperationType.Delete) + /// { + /// id = changeFeedItem.Current.id.ToString(); + /// pk = changeFeedItem.Current.pk.ToString(); + /// description = changeFeedItem.Current.description.ToString(); + /// } + /// else + /// { + /// id = changeFeedItem.Previous.id.ToString(); + /// pk = changeFeedItem.Previous.pk.ToString(); + /// description = changeFeedItem.Previous.description.ToString(); + /// } + /// + /// ChangeFeedOperationType operationType = changeFeedItem.Metadata.OperationType; + /// long previousLsn = changeFeedItem.Metadata.PreviousLsn; + /// DateTime conflictResolutionTimestamp = changeFeedItem.Metadata.ConflictResolutionTimestamp; + /// long lsn = changeFeedItem.Metadata.Lsn; + /// bool isTimeToLiveExpired = changeFeedItem.Metadata.IsTimeToLiveExpired; + /// } + /// + /// return Task.CompletedTask; + /// }) + /// .WithInstanceName(Guid.NewGuid().ToString()) + /// .WithLeaseContainer(leaseContainer) + /// .WithErrorNotification((leaseToken, error) => + /// { + /// Console.WriteLine(error.ToString()); + /// + /// return Task.CompletedTask; + /// }) + /// .Build(); + /// + /// await changeFeedProcessor.StartAsync(); + /// await Task.Delay(1000); + /// await this.Container.CreateItemAsync(new { id = "1", pk = "1", description = "original test" }, partitionKey: new PartitionKey("1")); + /// await this.Container.UpsertItemAsync(new { id = "1", pk = "1", description = "test after replace" }, partitionKey: new PartitionKey("1")); + /// await this.Container.DeleteItemAsync(id: "1", partitionKey: new PartitionKey("1")); + /// + /// allProcessedDocumentsEvent.WaitOne(10 * 1000); + /// + /// await changeFeedProcessor.StopAsync(); + /// ]]> + /// + /// + /// An instance of + public abstract ChangeFeedProcessorBuilder GetChangeFeedProcessorBuilderWithAllVersionsAndDeletes( + string processorName, + ChangeFeedHandler> onChangesDelegate); #endif } -} +} \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerInlineCore.cs b/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerInlineCore.cs index ede4aebc22..f3153a33cf 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerInlineCore.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerInlineCore.cs @@ -14,7 +14,6 @@ namespace Microsoft.Azure.Cosmos using Microsoft.Azure.Cosmos.Query.Core.Monads; using Microsoft.Azure.Cosmos.Query.Core.QueryClient; using Microsoft.Azure.Cosmos.ReadFeed; - using Microsoft.Azure.Cosmos.Serializer; using Microsoft.Azure.Cosmos.Tracing; // This class acts as a wrapper for environments that use SynchronizationContext. @@ -661,14 +660,5 @@ public override Task DeleteAllItemsByPartitionKeyStreamAsync( task: (trace) => base.DeleteAllItemsByPartitionKeyStreamAsync(partitionKey, trace, requestOptions, cancellationToken), openTelemetry: (response) => new OpenTelemetryResponse(response)); } - - public override ChangeFeedProcessorBuilder GetChangeFeedProcessorBuilderWithAllVersionsAndDeletes( - string processorName, - ChangeFeedHandler> onChangesDelegate) - { - return base.GetChangeFeedProcessorBuilderWithAllVersionsAndDeletes( - processorName, - onChangesDelegate); - } } } \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerInternal.cs b/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerInternal.cs index 27b007ed8e..7e980bac56 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerInternal.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerInternal.cs @@ -147,82 +147,11 @@ public abstract Task DeleteAllItemsByPartitionKeyStreamAsync( public abstract Task> GetPartitionKeyRangesAsync( FeedRange feedRange, CancellationToken cancellationToken = default); -#endif - /// - /// Initializes a for change feed processing with all versions and deletes. - /// - /// Document type - /// A name that identifies the Processor and the particular work it will do. - /// Delegate to receive all changes and deletes - /// - /// - /// > documents, CancellationToken token) => - /// { - /// Console.WriteLine($"number of documents processed: {documents.Count}"); - /// - /// string id = default; - /// string pk = default; - /// string description = default; - /// - /// foreach (ChangeFeedItemChange changeFeedItem in documents) - /// { - /// if (changeFeedItem.Metadata.OperationType != ChangeFeedOperationType.Delete) - /// { - /// id = changeFeedItem.Current.id.ToString(); - /// pk = changeFeedItem.Current.pk.ToString(); - /// description = changeFeedItem.Current.description.ToString(); - /// } - /// else - /// { - /// id = changeFeedItem.Previous.id.ToString(); - /// pk = changeFeedItem.Previous.pk.ToString(); - /// description = changeFeedItem.Previous.description.ToString(); - /// } - /// - /// ChangeFeedOperationType operationType = changeFeedItem.Metadata.OperationType; - /// long previousLsn = changeFeedItem.Metadata.PreviousLsn; - /// DateTime conflictResolutionTimestamp = changeFeedItem.Metadata.ConflictResolutionTimestamp; - /// long lsn = changeFeedItem.Metadata.Lsn; - /// bool isTimeToLiveExpired = changeFeedItem.Metadata.IsTimeToLiveExpired; - /// } - /// - /// return Task.CompletedTask; - /// }) - /// .WithInstanceName(Guid.NewGuid().ToString()) - /// .WithLeaseContainer(leaseContainer) - /// .WithErrorNotification((leaseToken, error) => - /// { - /// Console.WriteLine(error.ToString()); - /// - /// return Task.CompletedTask; - /// }) - /// .Build(); - /// - /// await changeFeedProcessor.StartAsync(); - /// await Task.Delay(1000); - /// await this.Container.CreateItemAsync(new { id = "1", pk = "1", description = "original test" }, partitionKey: new PartitionKey("1")); - /// await this.Container.UpsertItemAsync(new { id = "1", pk = "1", description = "test after replace" }, partitionKey: new PartitionKey("1")); - /// await this.Container.DeleteItemAsync(id: "1", partitionKey: new PartitionKey("1")); - /// - /// allProcessedDocumentsEvent.WaitOne(10 * 1000); - /// - /// await changeFeedProcessor.StopAsync(); - /// ]]> - /// - /// - /// An instance of public abstract ChangeFeedProcessorBuilder GetChangeFeedProcessorBuilderWithAllVersionsAndDeletes( string processorName, ChangeFeedHandler> onChangesDelegate); +#endif public abstract class TryExecuteQueryResult { From f357d610709d8ea583378184b1f17cada58b795e Mon Sep 17 00:00:00 2001 From: philipthomas Date: Mon, 25 Mar 2024 16:43:48 -0400 Subject: [PATCH 2/8] ran updatecontracts --- .../Contracts/DotNetPreviewSDKAPI.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetPreviewSDKAPI.json b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetPreviewSDKAPI.json index 66cdf8f4d5..d29800471a 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetPreviewSDKAPI.json +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetPreviewSDKAPI.json @@ -299,6 +299,11 @@ "Microsoft.Azure.Cosmos.Container;System.Object;IsAbstract:True;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { "Subclasses": {}, "Members": { + "Microsoft.Azure.Cosmos.ChangeFeedProcessorBuilder GetChangeFeedProcessorBuilderWithAllVersionsAndDeletes[T](System.String, ChangeFeedHandler`1)": { + "Type": "Method", + "Attributes": [], + "MethodInfo": "Microsoft.Azure.Cosmos.ChangeFeedProcessorBuilder GetChangeFeedProcessorBuilderWithAllVersionsAndDeletes[T](System.String, ChangeFeedHandler`1);IsAbstract:True;IsStatic:False;IsVirtual:True;IsGenericMethod:True;IsConstructor:False;IsFinal:False;" + }, "System.Threading.Tasks.Task`1[Microsoft.Azure.Cosmos.ResponseMessage] DeleteAllItemsByPartitionKeyStreamAsync(Microsoft.Azure.Cosmos.PartitionKey, Microsoft.Azure.Cosmos.RequestOptions, System.Threading.CancellationToken)": { "Type": "Method", "Attributes": [], From 9dc9c739494821ca29a0155bb77ed897884250b4 Mon Sep 17 00:00:00 2001 From: philipthomas Date: Tue, 26 Mar 2024 08:43:38 -0400 Subject: [PATCH 3/8] including this in Encryption --- .../src/EncryptionContainer.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Microsoft.Azure.Cosmos.Encryption.Custom/src/EncryptionContainer.cs b/Microsoft.Azure.Cosmos.Encryption.Custom/src/EncryptionContainer.cs index eebf5900cf..0706188ba4 100644 --- a/Microsoft.Azure.Cosmos.Encryption.Custom/src/EncryptionContainer.cs +++ b/Microsoft.Azure.Cosmos.Encryption.Custom/src/EncryptionContainer.cs @@ -1021,6 +1021,15 @@ public override Task DeleteAllItemsByPartitionKeyStreamAsync( requestOptions, cancellationToken); } + + public override ChangeFeedProcessorBuilder GetChangeFeedProcessorBuilderWithAllVersionsAndDeletes( + string processorName, + ChangeFeedHandler> onChangesDelegate) + { + return this.container.GetChangeFeedProcessorBuilderWithAllVersionsAndDeletes( + processorName, + onChangesDelegte); + } #endif private async Task ReadManyItemsHelperAsync( From 387248ca57ec84067555e721b2289541b272bd2f Mon Sep 17 00:00:00 2001 From: philipthomas Date: Tue, 26 Mar 2024 08:54:04 -0400 Subject: [PATCH 4/8] fixing name onChangesDelegate --- .../src/EncryptionContainer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Microsoft.Azure.Cosmos.Encryption.Custom/src/EncryptionContainer.cs b/Microsoft.Azure.Cosmos.Encryption.Custom/src/EncryptionContainer.cs index 0706188ba4..2214d8990a 100644 --- a/Microsoft.Azure.Cosmos.Encryption.Custom/src/EncryptionContainer.cs +++ b/Microsoft.Azure.Cosmos.Encryption.Custom/src/EncryptionContainer.cs @@ -1028,7 +1028,7 @@ public override ChangeFeedProcessorBuilder GetChangeFeedProcessorBuilderWithAllV { return this.container.GetChangeFeedProcessorBuilderWithAllVersionsAndDeletes( processorName, - onChangesDelegte); + onChangesDelegate); } #endif From cb4e76f4980d6cabac96bdc295b7eab82f1e9db4 Mon Sep 17 00:00:00 2001 From: philipthomas Date: Tue, 26 Mar 2024 12:29:41 -0400 Subject: [PATCH 5/8] sdkproject on encryptioncontainer --- .../src/EncryptionContainer.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Microsoft.Azure.Cosmos.Encryption.Custom/src/EncryptionContainer.cs b/Microsoft.Azure.Cosmos.Encryption.Custom/src/EncryptionContainer.cs index 2214d8990a..873bd1119a 100644 --- a/Microsoft.Azure.Cosmos.Encryption.Custom/src/EncryptionContainer.cs +++ b/Microsoft.Azure.Cosmos.Encryption.Custom/src/EncryptionContainer.cs @@ -1021,7 +1021,9 @@ public override Task DeleteAllItemsByPartitionKeyStreamAsync( requestOptions, cancellationToken); } +#endif +#if SDKPROJECTREF public override ChangeFeedProcessorBuilder GetChangeFeedProcessorBuilderWithAllVersionsAndDeletes( string processorName, ChangeFeedHandler> onChangesDelegate) From b58cf3363a835c5ec77ed46d622bdadf45c111f2 Mon Sep 17 00:00:00 2001 From: philipthomas Date: Tue, 26 Mar 2024 13:11:45 -0400 Subject: [PATCH 6/8] try this again --- .../src/EncryptionContainer.cs | 4 ---- .../src/EncryptionContainer.cs | 9 ++++++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Microsoft.Azure.Cosmos.Encryption.Custom/src/EncryptionContainer.cs b/Microsoft.Azure.Cosmos.Encryption.Custom/src/EncryptionContainer.cs index 873bd1119a..dc27fbd11d 100644 --- a/Microsoft.Azure.Cosmos.Encryption.Custom/src/EncryptionContainer.cs +++ b/Microsoft.Azure.Cosmos.Encryption.Custom/src/EncryptionContainer.cs @@ -10,7 +10,6 @@ namespace Microsoft.Azure.Cosmos.Encryption.Custom using System.Linq; using System.Threading; using System.Threading.Tasks; - using Microsoft.Azure.Cosmos; using Newtonsoft.Json.Linq; internal sealed class EncryptionContainer : Container @@ -1021,9 +1020,7 @@ public override Task DeleteAllItemsByPartitionKeyStreamAsync( requestOptions, cancellationToken); } -#endif -#if SDKPROJECTREF public override ChangeFeedProcessorBuilder GetChangeFeedProcessorBuilderWithAllVersionsAndDeletes( string processorName, ChangeFeedHandler> onChangesDelegate) @@ -1033,7 +1030,6 @@ public override ChangeFeedProcessorBuilder GetChangeFeedProcessorBuilderWithAllV onChangesDelegate); } #endif - private async Task ReadManyItemsHelperAsync( IReadOnlyList<(string id, PartitionKey partitionKey)> items, ReadManyRequestOptions readManyRequestOptions = null, diff --git a/Microsoft.Azure.Cosmos.Encryption/src/EncryptionContainer.cs b/Microsoft.Azure.Cosmos.Encryption/src/EncryptionContainer.cs index 0bd342f0ef..32df3587bb 100644 --- a/Microsoft.Azure.Cosmos.Encryption/src/EncryptionContainer.cs +++ b/Microsoft.Azure.Cosmos.Encryption/src/EncryptionContainer.cs @@ -11,7 +11,6 @@ namespace Microsoft.Azure.Cosmos.Encryption using System.Net; using System.Threading; using System.Threading.Tasks; - using Microsoft.Azure.Cosmos; using Newtonsoft.Json.Linq; internal sealed class EncryptionContainer : Container @@ -756,6 +755,14 @@ public override Task> GetPartitionKeyRangesAsync( } #endif +#if SDKPROJECTREF + public override ChangeFeedProcessorBuilder GetChangeFeedProcessorBuilderWithAllVersionsAndDeletes( + string processorName, + ChangeFeedHandler> onChangesDelegate) + { + throw new NotImplementedException(); + } +#endif /// /// This function handles the scenario where a container is deleted(say from different Client) and recreated with same Id but with different client encryption policy. /// The idea is to have the container Rid cached and sent out as part of RequestOptions with Container Rid set in "x-ms-cosmos-intended-collection-rid" header. From 92a735baefa30ea88a5af77a8159d3ea0ddaa4bb Mon Sep 17 00:00:00 2001 From: philipthomas Date: Tue, 26 Mar 2024 13:19:14 -0400 Subject: [PATCH 7/8] try, try, try again --- .../src/EncryptionContainer.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Microsoft.Azure.Cosmos.Encryption.Custom/src/EncryptionContainer.cs b/Microsoft.Azure.Cosmos.Encryption.Custom/src/EncryptionContainer.cs index dc27fbd11d..b2ffdd12c5 100644 --- a/Microsoft.Azure.Cosmos.Encryption.Custom/src/EncryptionContainer.cs +++ b/Microsoft.Azure.Cosmos.Encryption.Custom/src/EncryptionContainer.cs @@ -1020,14 +1020,14 @@ public override Task DeleteAllItemsByPartitionKeyStreamAsync( requestOptions, cancellationToken); } +#endif +#if SDKPROJECTREF public override ChangeFeedProcessorBuilder GetChangeFeedProcessorBuilderWithAllVersionsAndDeletes( string processorName, ChangeFeedHandler> onChangesDelegate) { - return this.container.GetChangeFeedProcessorBuilderWithAllVersionsAndDeletes( - processorName, - onChangesDelegate); + throw new NotImplementedException(); } #endif private async Task ReadManyItemsHelperAsync( From 545d31f9c3b94e93d4dd51dc72123ff16a58b6be Mon Sep 17 00:00:00 2001 From: philipthomas Date: Tue, 26 Mar 2024 13:22:45 -0400 Subject: [PATCH 8/8] with impl --- .../src/EncryptionContainer.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Microsoft.Azure.Cosmos.Encryption.Custom/src/EncryptionContainer.cs b/Microsoft.Azure.Cosmos.Encryption.Custom/src/EncryptionContainer.cs index b2ffdd12c5..bdba7677b6 100644 --- a/Microsoft.Azure.Cosmos.Encryption.Custom/src/EncryptionContainer.cs +++ b/Microsoft.Azure.Cosmos.Encryption.Custom/src/EncryptionContainer.cs @@ -1027,7 +1027,9 @@ public override ChangeFeedProcessorBuilder GetChangeFeedProcessorBuilderWithAllV string processorName, ChangeFeedHandler> onChangesDelegate) { - throw new NotImplementedException(); + return this.container.GetChangeFeedProcessorBuilderWithAllVersionsAndDeletes( + processorName, + onChangesDelegate); } #endif private async Task ReadManyItemsHelperAsync(