From 5be6e2222f403eb0686614841614c9a757183a01 Mon Sep 17 00:00:00 2001 From: Matias Quaranta Date: Fri, 15 Dec 2023 08:08:04 -0800 Subject: [PATCH 1/3] Calling dispose --- .../FeedManagement/PartitionControllerCore.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Microsoft.Azure.Cosmos/src/ChangeFeedProcessor/FeedManagement/PartitionControllerCore.cs b/Microsoft.Azure.Cosmos/src/ChangeFeedProcessor/FeedManagement/PartitionControllerCore.cs index e181dadbec..fe3ed984c3 100644 --- a/Microsoft.Azure.Cosmos/src/ChangeFeedProcessor/FeedManagement/PartitionControllerCore.cs +++ b/Microsoft.Azure.Cosmos/src/ChangeFeedProcessor/FeedManagement/PartitionControllerCore.cs @@ -167,6 +167,8 @@ private async Task ProcessPartitionAsync(PartitionSupervisor partitionSupervisor } await this.RemoveLeaseAsync(lease: lease, wasAcquired: true).ConfigureAwait(false); + + partitionSupervisor.Dispose(); } private async Task HandlePartitionGoneAsync(DocumentServiceLease lease, string lastContinuationToken) From 63f1a18fba24cfaffe8d5d655d75da28d3143fdc Mon Sep 17 00:00:00 2001 From: Matias Quaranta Date: Fri, 15 Dec 2023 08:17:14 -0800 Subject: [PATCH 2/3] Tests --- .../PartitionControllerSplitTests.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/ChangeFeed/PartitionControllerSplitTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/ChangeFeed/PartitionControllerSplitTests.cs index 25704e05c8..ba56424ee0 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/ChangeFeed/PartitionControllerSplitTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/ChangeFeed/PartitionControllerSplitTests.cs @@ -48,6 +48,9 @@ public async Task Controller_ShouldSignalSynchronizerSplitPartition_IfPartitionS await sut.ShutdownAsync().ConfigureAwait(false); Mock.Get(synchronizer).VerifyAll(); + + Mock.Get(partitionSupervisor) + .Verify(s => s.Dispose(), Times.Once); } [TestMethod] @@ -76,6 +79,9 @@ public async Task Controller_ShouldPassLastKnownContinuationTokenToSynchronizer_ await sut.ShutdownAsync().ConfigureAwait(false); Mock.Get(synchronizer).VerifyAll(); + + Mock.Get(partitionSupervisor) + .Verify(s => s.Dispose(), Times.Once); } [TestMethod] @@ -108,6 +114,9 @@ public async Task Controller_ShouldCopyParentLeaseProperties_IfPartitionSplitHap .VerifySet(l => l.Properties = customProperties, Times.Once); Mock.Get(leaseChild2) .VerifySet(l => l.Properties = customProperties, Times.Once); + + Mock.Get(partitionSupervisor) + .Verify(s => s.Dispose(), Times.Once); } [TestMethod] @@ -132,6 +141,9 @@ public async Task Controller_ShouldKeepParentLease_IfSplitThrows() await sut.ShutdownAsync().ConfigureAwait(false); Mock.Get(leaseManager).Verify(manager => manager.DeleteAsync(lease), Times.Never); + + Mock.Get(partitionSupervisor) + .Verify(s => s.Dispose(), Times.Once); } [TestMethod] @@ -180,6 +192,13 @@ public async Task Controller_ShouldRunProcessingOnChildPartitions_IfHappyPath() monitor.Verify(m => m.NotifyLeaseAcquireAsync(leaseChild1.CurrentLeaseToken), Times.Once); monitor.Verify(m => m.NotifyLeaseReleaseAsync(leaseChild2.CurrentLeaseToken), Times.Once); + + Mock.Get(partitionSupervisor) + .Verify(s => s.Dispose(), Times.Once); + Mock.Get(partitionSupervisor1) + .Verify(s => s.Dispose(), Times.Once); + Mock.Get(partitionSupervisor2) + .Verify(s => s.Dispose(), Times.Once); } [TestMethod] From bddcd5f9ec2c1a9cc08821146fd209b018aa36bf Mon Sep 17 00:00:00 2001 From: Matias Quaranta Date: Tue, 19 Dec 2023 09:52:24 -0800 Subject: [PATCH 3/3] refactoring --- .../FeedManagement/PartitionControllerCore.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/ChangeFeedProcessor/FeedManagement/PartitionControllerCore.cs b/Microsoft.Azure.Cosmos/src/ChangeFeedProcessor/FeedManagement/PartitionControllerCore.cs index fe3ed984c3..7407477c21 100644 --- a/Microsoft.Azure.Cosmos/src/ChangeFeedProcessor/FeedManagement/PartitionControllerCore.cs +++ b/Microsoft.Azure.Cosmos/src/ChangeFeedProcessor/FeedManagement/PartitionControllerCore.cs @@ -89,8 +89,7 @@ public override async Task AddOrUpdateLeaseAsync(DocumentServiceLease lease) throw; } - PartitionSupervisor supervisor = this.partitionSupervisorFactory.Create(lease); - this.ProcessPartitionAsync(supervisor, lease).LogException(); + this.ProcessPartitionAsync(lease).LogException(); } public override async Task ShutdownAsync() @@ -146,8 +145,10 @@ private async Task RemoveLeaseAsync(DocumentServiceLease lease, bool wasAcquired } } - private async Task ProcessPartitionAsync(PartitionSupervisor partitionSupervisor, DocumentServiceLease lease) + private async Task ProcessPartitionAsync(DocumentServiceLease lease) { + using PartitionSupervisor partitionSupervisor = this.partitionSupervisorFactory.Create(lease); + try { await partitionSupervisor.RunAsync(this.shutdownCts.Token).ConfigureAwait(false); @@ -167,8 +168,6 @@ private async Task ProcessPartitionAsync(PartitionSupervisor partitionSupervisor } await this.RemoveLeaseAsync(lease: lease, wasAcquired: true).ConfigureAwait(false); - - partitionSupervisor.Dispose(); } private async Task HandlePartitionGoneAsync(DocumentServiceLease lease, string lastContinuationToken)