Skip to content

Commit

Permalink
Ignore remote vertex instance if it appears in the local set.
Browse files Browse the repository at this point in the history
  • Loading branch information
ReubenBond committed May 23, 2024
1 parent 557a66a commit 5592a98
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/Orleans.Runtime/Placement/Rebalancing/ActivationRebalancer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Orleans.Runtime.Utilities;
using System.Runtime.InteropServices;
using System.Diagnostics.CodeAnalysis;
using Microsoft.CodeAnalysis;

namespace Orleans.Runtime.Placement.Rebalancing;

Expand Down Expand Up @@ -369,19 +370,25 @@ private static (MaxHeap<CandidateVertexHeapElement> Local, MaxHeap<CandidateVert
sourceIndex[element.Id] = element;
}

Dictionary<GrainId, CandidateVertexHeapElement> index = [];
Dictionary<GrainId, CandidateVertexHeapElement> heapIndex = [];
List<CandidateVertexHeapElement> localVertexList = new(local.Count);
foreach (var element in local)
{
var vertex = CreateVertex(sourceIndex, index, element);
var vertex = CreateVertex(sourceIndex, heapIndex, element);
vertex.Location = VertexLocation.Local;
localVertexList.Add(vertex);
}

List<CandidateVertexHeapElement> remoteVertexList = new(remote.Length);
foreach (var element in remote)
{
var vertex = CreateVertex(sourceIndex, index, element);
var vertex = CreateVertex(sourceIndex, heapIndex, element);
if (vertex.Location is not VertexLocation.Unknown)
{
// This vertex is already part of the local set, so assume that the vertex is local and ignore the remote vertex.
continue;
}

vertex.Location = VertexLocation.Remote;
remoteVertexList.Add(vertex);
}
Expand Down Expand Up @@ -439,7 +446,7 @@ private async Task FinalizeProtocol(ImmutableArray<GrainId> giving, ImmutableArr
{
await Task.WhenAll(migrationTasks);
}
catch (Exception)
catch
{
// This should happen rarely, but at this point we cant really do much, as its out of our control.
// Even if some fail, the algorithm will eventually run again, so activations will have more chances to migrate.
Expand Down Expand Up @@ -694,4 +701,4 @@ private enum Direction : byte
/// <param name="Direction">The edge's direction</param>
/// <param name="Weight">The number of estimated messages exchanged between <paramref name="SourceId"/> and <paramref name="TargetId"/>.</param>
private readonly record struct VertexEdge(GrainId SourceId, GrainId TargetId, bool IsMigratable, SiloAddress PartnerSilo, Direction Direction, long Weight);
}
}

0 comments on commit 5592a98

Please sign in to comment.