Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Akka.Cluster.Sharding: LeastShardAllocationStrategy ArgumentException during rebalance #7365

Closed
Aaronontheweb opened this issue Oct 28, 2024 · 2 comments · Fixed by #7367
Closed

Comments

@Aaronontheweb
Copy link
Member

Version Information
Version of Akka.NET? not sure yet - waiting on reply in Discord
Which Akka.NET Modules? Akka.Cluster.Sharding

Describe the bug

System.ArgumentException: An element with the same key but a different value already exists. Key: 'akka.tcp://NuBreedSys@prod-nubreed-quote-process-managers-0.prod-nubreed-quote-process-managers-service:9233'
   at System.Collections.Immutable.ImmutableDictionary2.HashBucket.Add(TKey key, TValue value, IEqualityComparer1 keyOnlyComparer, IEqualityComparer1 valueComparer, KeyCollisionBehavior behavior, OperationResult& result)
   at System.Collections.Immutable.ImmutableDictionary2.AddRange(IEnumerable1 items, MutationInput origin, KeyCollisionBehavior collisionBehavior)
   at Akka.Cluster.Sharding.Internal.AbstractLeastShardAllocationStrategy.RegionEntriesFor(IImmutableDictionary2 currentShardAllocations)
   at Akka.Cluster.Sharding.LeastShardAllocationStrategy.Rebalance(IImmutableDictionary2 currentShardAllocations, IImmutableSet1 rebalanceInProgress)
   at Akka.Cluster.Sharding.ShardCoordinator.Active(Object message)
   at Akka.Cluster.Sharding.DDataShardCoordinator.<Activate>b__45_0(Object msg)
   at Akka.Actor.ActorBase.AroundReceive(Receive receive, Object message)
   at Phobos.Actor.PhobosActorCell.ReceiveMessage(Object message)
   at Akka.Actor.ActorCell.Invoke(Envelope envelope)

Expected behavior

Actual behavior
What actually happened and how did it differ from your expectations?

Screenshots
If applicable, add screenshots to help explain your problem.

Environment

Using state-store-mode = ddata

Additional context

Not sure yet, still working on getting thoughts organized here

@Aaronontheweb
Copy link
Member Author

This is the line that throws:

var sortedRegionEntries = RegionEntriesFor(currentShardAllocations).OrderBy(i => i, ShardSuitabilityOrdering.Instance).ToImmutableList();

When it's invoking this function:

protected ImmutableList<RegionEntry> RegionEntriesFor(IImmutableDictionary<IActorRef, IImmutableList<string>> currentShardAllocations)
{
var addressToMember = ClusterState.Members.ToImmutableDictionary(m => m.Address, m => m);
return currentShardAllocations.Select(i =>
{
var regionAddress = i.Key.Path.Address.HasLocalScope ? SelfMember.Address : i.Key.Path.Address;
var memberForRegion = addressToMember.GetValueOrDefault(regionAddress);
// if the member is unknown (very unlikely but not impossible) because of view not updated yet
// that node is ignored for this invocation
if (memberForRegion != null)
return new RegionEntry(i.Key, memberForRegion, i.Value);
return null;
}).Where(i => i != null).ToImmutableList();
}

I'm guessing it's the ToImmutableDictionary call that is the problem here based on the stack trace provided by the user

@Aaronontheweb
Copy link
Member Author

Also need to investigate why Akka.Cluster.Sharding never automatically healed from this issue either - that seems like a separate bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant