Skip to content

Commit

Permalink
use MinBy and MaxBy (#6742)
Browse files Browse the repository at this point in the history
Co-authored-by: Aaron Stannard <[email protected]>
  • Loading branch information
SimonCropp and Aaronontheweb authored May 17, 2023
1 parent c11e5c6 commit 455d05b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public override Task<IImmutableSet<ShardId>> Rebalance(IImmutableDictionary<IAct
{
var (_, Shards) = MostSuitableRegion(sortedRegionEntries);
// even if it is to another new node.
var mostShards = sortedRegionEntries.Select(r => r.ShardIds.Where(s => !rebalanceInProgress.Contains(s))).OrderByDescending(i => i.Count()).FirstOrDefault()?.ToArray() ?? Array.Empty<string>();
var mostShards = sortedRegionEntries.Select(r => r.ShardIds.Where(s => !rebalanceInProgress.Contains(s))).MaxBy(i => i.Count())?.ToArray() ?? Array.Empty<string>();

var difference = mostShards.Length - Shards.Count;
if (difference >= _rebalanceThreshold)
Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka.Cluster.Tests.MultiNode/TransitionSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private RoleName Leader(params RoleName[] roles)
{
// sorts the addresses and provides the address of the node with the lowest port number
// as that node will be the leader
return roles.Select(x => (x, GetAddress(x).Port)).OrderBy(x => x.Item2).First().Item1;
return roles.Select(x => (x, GetAddress(x).Port)).MinBy(x => x.Item2).Item1;
}

private RoleName[] NonLeader(params RoleName[] roles)
Expand Down

0 comments on commit 455d05b

Please sign in to comment.