From 73c9e08d2796c64e016fdf80007c0f8c72f8e47b Mon Sep 17 00:00:00 2001 From: Philip Thomas <86612891+philipthomas-MSFT@users.noreply.github.com> Date: Wed, 4 Jan 2023 15:37:36 -0500 Subject: [PATCH] add new LatestVersion changefeed mode that has same behavior as Incremental; renamed FullFidelity to AllVersionsAndDeletes (#3596) --- .../src/ChangeFeed/ChangeFeedMode.cs | 16 +++++++++++++++- .../FullFidelity/ChangeFeedItemChange{T}.cs | 4 ++-- .../FullFidelity/ChangeFeedMetadata.cs | 2 +- .../FullFidelity/ChangeFeedOperationType.cs | 2 +- .../src/Resource/Settings/ChangeFeedPolicy.cs | 2 +- .../FeedToken/ChangeFeedIteratorCoreTests.cs | 14 +++++++------- .../NetworkAttachedDocumentContainerTests.cs | 2 +- .../Contracts/DotNetPreviewSDKAPI.json | 18 ++++++++++++++---- 8 files changed, 42 insertions(+), 18 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/ChangeFeed/ChangeFeedMode.cs b/Microsoft.Azure.Cosmos/src/ChangeFeed/ChangeFeedMode.cs index d64a9942d5..7df0871d74 100644 --- a/Microsoft.Azure.Cosmos/src/ChangeFeed/ChangeFeedMode.cs +++ b/Microsoft.Azure.Cosmos/src/ChangeFeed/ChangeFeedMode.cs @@ -31,6 +31,20 @@ internal ChangeFeedMode() /// A to receive incremental item changes. public static ChangeFeedMode Incremental => ChangeFeedModeIncremental.Instance; + /// + /// Creates a to receive latest version item changes. + /// + /// + /// Latest version mode includes item creations and updates, not deletions. + /// + /// A to receive latest version item changes. +#if PREVIEW + public +#else + internal +#endif + static ChangeFeedMode LatestVersion => ChangeFeedModeIncremental.Instance; + /// /// Creates a to receive notifications for creations, deletes, as well as all intermediary snapshots for updates. /// @@ -49,6 +63,6 @@ internal ChangeFeedMode() #else internal #endif - static ChangeFeedMode FullFidelity => ChangeFeedModeFullFidelity.Instance; + static ChangeFeedMode AllVersionsAndDeletes => ChangeFeedModeFullFidelity.Instance; } } diff --git a/Microsoft.Azure.Cosmos/src/Resource/FullFidelity/ChangeFeedItemChange{T}.cs b/Microsoft.Azure.Cosmos/src/Resource/FullFidelity/ChangeFeedItemChange{T}.cs index 1a564443bd..deb9c7db87 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/FullFidelity/ChangeFeedItemChange{T}.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/FullFidelity/ChangeFeedItemChange{T}.cs @@ -7,7 +7,7 @@ namespace Microsoft.Azure.Cosmos using Newtonsoft.Json; /// - /// The typed response that contains the current, previous, and metadata change feed resource when is initialized to . + /// The typed response that contains the current, previous, and metadata change feed resource when is initialized to . /// /// /// @@ -19,7 +19,7 @@ namespace Microsoft.Azure.Cosmos /// public string status { get; set; } /// } /// - /// ChangeFeedMode changeFeedMode = ChangeFeedMode.FullFidelity; + /// ChangeFeedMode changeFeedMode = ChangeFeedMode.AllVersionsAndDeletes; /// PartitionKey partitionKey = new PartitionKey(@"learning"); /// ChangeFeedStartFrom changeFeedStartFrom = ChangeFeedStartFrom.Now(FeedRange.FromPartitionKey(partitionKey)); /// diff --git a/Microsoft.Azure.Cosmos/src/Resource/FullFidelity/ChangeFeedMetadata.cs b/Microsoft.Azure.Cosmos/src/Resource/FullFidelity/ChangeFeedMetadata.cs index 75abc2ef1e..81b10461f9 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/FullFidelity/ChangeFeedMetadata.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/FullFidelity/ChangeFeedMetadata.cs @@ -10,7 +10,7 @@ namespace Microsoft.Azure.Cosmos using Newtonsoft.Json.Converters; /// - /// The metadata of a change feed resource with is initialized to . + /// The metadata of a change feed resource with is initialized to . /// #if PREVIEW public diff --git a/Microsoft.Azure.Cosmos/src/Resource/FullFidelity/ChangeFeedOperationType.cs b/Microsoft.Azure.Cosmos/src/Resource/FullFidelity/ChangeFeedOperationType.cs index 48e70b2260..9144556e91 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/FullFidelity/ChangeFeedOperationType.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/FullFidelity/ChangeFeedOperationType.cs @@ -7,7 +7,7 @@ namespace Microsoft.Azure.Cosmos using System.Runtime.Serialization; /// - /// The operation type of a change feed resource with is initialized to . Upsert operations will yield or . + /// The operation type of a change feed resource with is initialized to . Upsert operations will yield or . /// #if PREVIEW public diff --git a/Microsoft.Azure.Cosmos/src/Resource/Settings/ChangeFeedPolicy.cs b/Microsoft.Azure.Cosmos/src/Resource/Settings/ChangeFeedPolicy.cs index e0b6d3ad16..e411d8ea2e 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Settings/ChangeFeedPolicy.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Settings/ChangeFeedPolicy.cs @@ -16,7 +16,7 @@ namespace Microsoft.Azure.Cosmos /// /// The example below creates a new container with a custom change feed policy for full fidelity change feed with a retention window of 5 minutes - so intermediary snapshots of changes as well as deleted documents would be /// available for processing for 5 minutes before they vanish. - /// Processing the change feed with will only be able within this retention window - if you attempt to process a change feed after more + /// Processing the change feed with will only be able within this retention window - if you attempt to process a change feed after more /// than the retention window (5 minutes in this sample) an error (Status Code 400) will be returned. /// It would still be possible to process changes using mode even when configuring a full fidelity change /// feed policy with retention window on the container and when using Incremental mode it doesn't matter whether your are out of the retention window or not. diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/FeedToken/ChangeFeedIteratorCoreTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/FeedToken/ChangeFeedIteratorCoreTests.cs index e34bf128fc..b9d179c0c1 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/FeedToken/ChangeFeedIteratorCoreTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/FeedToken/ChangeFeedIteratorCoreTests.cs @@ -788,7 +788,7 @@ public async Task ChangeFeedIteratorCore_WithFullFidelityReadFromBeginning() // FF does not work with StartFromBeginning currently, capture error FeedIterator fullFidelityIterator = container.GetChangeFeedIterator( ChangeFeedStartFrom.Beginning(), - ChangeFeedMode.FullFidelity); + ChangeFeedMode.AllVersionsAndDeletes); CosmosException cosmosException = await Assert.ThrowsExceptionAsync(() => fullFidelityIterator.ReadNextAsync()); Assert.AreEqual(HttpStatusCode.BadRequest, cosmosException.StatusCode, "Full Fidelity Change Feed does not work with StartFromBeginning currently."); @@ -829,7 +829,7 @@ private async Task ValidateChangeFeedIteratorCore_WithQuery( // FF does not work with StartFromBeginning currently, so we capture an initial continuation. FeedIterator> fullFidelityIterator = container.GetChangeFeedIteratorWithQuery>( ChangeFeedStartFrom.Now(), - ChangeFeedMode.FullFidelity, + ChangeFeedMode.AllVersionsAndDeletes, querySpec, null); @@ -862,7 +862,7 @@ private async Task ValidateChangeFeedIteratorCore_WithQuery( // Resume Change Feed and verify we pickup the events where documents matches the query fullFidelityIterator = container.GetChangeFeedIteratorWithQuery>( ChangeFeedStartFrom.ContinuationToken(initialContinuation), - ChangeFeedMode.FullFidelity, + ChangeFeedMode.AllVersionsAndDeletes, querySpec, null); int detectedEvents = 0; @@ -891,7 +891,7 @@ private async Task ValidateChangeFeedIteratorCore_WithQuery( fullFidelityIterator = container.GetChangeFeedIteratorWithQuery>( ChangeFeedStartFrom.ContinuationToken(initialContinuation), - ChangeFeedMode.FullFidelity, + ChangeFeedMode.AllVersionsAndDeletes, querySpec, null); detectedEvents = 0; @@ -927,7 +927,7 @@ public async Task ChangeFeedIteratorCore_FeedRange_FromPartitionKey_VerifyingWir string otherId = Guid.NewGuid().ToString(); PartitionKey partitionKey = new PartitionKey(id); - ChangeFeedMode changeFeedMode = ChangeFeedMode.FullFidelity; + ChangeFeedMode changeFeedMode = ChangeFeedMode.AllVersionsAndDeletes; ChangeFeedStartFrom changeFeedStartFrom = ChangeFeedStartFrom.Now(FeedRange.FromPartitionKey(partitionKey)); using (FeedIterator> feedIterator = container.GetChangeFeedIterator>( @@ -1017,7 +1017,7 @@ public async Task ChangeFeedIteratorCore_FeedRange_VerifyingWireFormatTests() using (FeedIterator> feedIterator = container.GetChangeFeedIterator>( changeFeedStartFrom: ChangeFeedStartFrom.Now(), - changeFeedMode: ChangeFeedMode.FullFidelity)) + changeFeedMode: ChangeFeedMode.AllVersionsAndDeletes)) { string continuation = null; while (feedIterator.HasMoreResults) @@ -1124,7 +1124,7 @@ public async Task ChangeFeedIteratorCore_FeedRange_FromPartitionKey_Dynamic_Veri string otherId = Guid.NewGuid().ToString(); using (FeedIterator feedIterator = container.GetChangeFeedIterator( changeFeedStartFrom: ChangeFeedStartFrom.Now(FeedRange.FromPartitionKey(new PartitionKey(id))), - changeFeedMode: ChangeFeedMode.FullFidelity)) + changeFeedMode: ChangeFeedMode.AllVersionsAndDeletes)) { string continuation = null; while (feedIterator.HasMoreResults) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/ChangeFeed/NetworkAttachedDocumentContainerTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/ChangeFeed/NetworkAttachedDocumentContainerTests.cs index 5e62114c1e..a8f5c4810c 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/ChangeFeed/NetworkAttachedDocumentContainerTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/ChangeFeed/NetworkAttachedDocumentContainerTests.cs @@ -144,7 +144,7 @@ public async Task MonadicChangeFeedAsync_ChangeFeedMode_FullFidelity() await networkAttachedDocumentContainer.MonadicChangeFeedAsync( feedRangeState: new FeedRangeState(new FeedRangePartitionKeyRange("0"), ChangeFeedState.Beginning()), - changeFeedPaginationOptions: new ChangeFeedPaginationOptions(ChangeFeedMode.FullFidelity, pageSizeHint: 10), + changeFeedPaginationOptions: new ChangeFeedPaginationOptions(ChangeFeedMode.AllVersionsAndDeletes, pageSizeHint: 10), trace: NoOpTrace.Singleton, cancellationToken: default); 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 07d725e2c5..add1fce30e 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 @@ -160,15 +160,25 @@ "Microsoft.Azure.Cosmos.ChangeFeedMode;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.ChangeFeedMode FullFidelity": { + "Microsoft.Azure.Cosmos.ChangeFeedMode AllVersionsAndDeletes": { "Type": "Property", "Attributes": [], - "MethodInfo": "Microsoft.Azure.Cosmos.ChangeFeedMode FullFidelity;CanRead:True;CanWrite:False;Microsoft.Azure.Cosmos.ChangeFeedMode get_FullFidelity();IsAbstract:False;IsStatic:True;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "Microsoft.Azure.Cosmos.ChangeFeedMode AllVersionsAndDeletes;CanRead:True;CanWrite:False;Microsoft.Azure.Cosmos.ChangeFeedMode get_AllVersionsAndDeletes();IsAbstract:False;IsStatic:True;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" }, - "Microsoft.Azure.Cosmos.ChangeFeedMode get_FullFidelity()": { + "Microsoft.Azure.Cosmos.ChangeFeedMode LatestVersion": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "Microsoft.Azure.Cosmos.ChangeFeedMode LatestVersion;CanRead:True;CanWrite:False;Microsoft.Azure.Cosmos.ChangeFeedMode get_LatestVersion();IsAbstract:False;IsStatic:True;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Microsoft.Azure.Cosmos.ChangeFeedMode get_AllVersionsAndDeletes()": { + "Type": "Method", + "Attributes": [], + "MethodInfo": "Microsoft.Azure.Cosmos.ChangeFeedMode get_AllVersionsAndDeletes();IsAbstract:False;IsStatic:True;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Microsoft.Azure.Cosmos.ChangeFeedMode get_LatestVersion()": { "Type": "Method", "Attributes": [], - "MethodInfo": "Microsoft.Azure.Cosmos.ChangeFeedMode get_FullFidelity();IsAbstract:False;IsStatic:True;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + "MethodInfo": "Microsoft.Azure.Cosmos.ChangeFeedMode get_LatestVersion();IsAbstract:False;IsStatic:True;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" } }, "NestedTypes": {}