From 0d6325a8f25027fbf8819517d575d3ae3401e842 Mon Sep 17 00:00:00 2001 From: Aaron Stannard Date: Tue, 31 May 2022 14:54:50 -0500 Subject: [PATCH] de-duplicate only identical `ShardHomeAllocated` messages close https://github.com/akkadotnet/akka.net/issues/5604 --- .../PersistentShardCoordinator.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/contrib/cluster/Akka.Cluster.Sharding/PersistentShardCoordinator.cs b/src/contrib/cluster/Akka.Cluster.Sharding/PersistentShardCoordinator.cs index 645e0a6c360..ff567449a40 100644 --- a/src/contrib/cluster/Akka.Cluster.Sharding/PersistentShardCoordinator.cs +++ b/src/contrib/cluster/Akka.Cluster.Sharding/PersistentShardCoordinator.cs @@ -109,11 +109,11 @@ public IImmutableSet AllShards } /// - /// TBD + /// Feed an event into the ShardCoordinator state. /// - /// TBD - /// TBD - /// TBD + /// The event to process. + /// Thrown if an event is illegal in the current state. + /// An update copy of this state. public State Updated(IDomainEvent e) { switch (e) @@ -1361,8 +1361,12 @@ protected override bool ReceiveRecover(object message) if (CurrentState.RegionProxies.Contains(proxyTerminated.RegionProxy)) CurrentState = CurrentState.Updated(evt); return true; - case ShardHomeAllocated _: - CurrentState = CurrentState.Updated(evt); + case ShardHomeAllocated homeAllocated: + // if we already have identical ShardHomeAllocated data, skip processing it + // addresses https://github.com/akkadotnet/akka.net/issues/5604 + if(!(CurrentState.Shards.TryGetValue(homeAllocated.Shard, out var currentShardRegion) + && Equals(homeAllocated.Region, currentShardRegion))) + CurrentState = CurrentState.Updated(evt); return true; case ShardHomeDeallocated _: CurrentState = CurrentState.Updated(evt);