-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose available versions information in placement context (#3136)
- Loading branch information
1 parent
da78acb
commit 5604368
Showing
23 changed files
with
315 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Orleans.Placement; | ||
using Orleans.Runtime; | ||
using Orleans.Runtime.Placement; | ||
|
||
namespace UnitTests.GrainInterfaces | ||
{ | ||
[AttributeUsage(AttributeTargets.Class)] | ||
public sealed class VersionAwareStrategyAttribute : PlacementAttribute | ||
{ | ||
public VersionAwareStrategyAttribute() | ||
: base(VersionAwarePlacementStrategy.Singleton) | ||
{ | ||
} | ||
} | ||
|
||
[Serializable] | ||
public class VersionAwarePlacementStrategy : PlacementStrategy | ||
{ | ||
internal static VersionAwarePlacementStrategy Singleton { get; } = new VersionAwarePlacementStrategy(); | ||
|
||
private VersionAwarePlacementStrategy() | ||
{ } | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
return obj is VersionAwarePlacementStrategy; | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return GetType().GetHashCode(); | ||
} | ||
} | ||
|
||
public class VersionAwarePlacementDirector : IPlacementDirector<VersionAwarePlacementStrategy> | ||
{ | ||
private readonly Random random = new Random(); | ||
|
||
public Task<SiloAddress> OnAddActivation(PlacementStrategy strategy, PlacementTarget target, IPlacementContext context) | ||
{ | ||
IReadOnlyList<SiloAddress> silos; | ||
if (target.InterfaceVersion == 0) | ||
{ | ||
silos = (IReadOnlyList<SiloAddress>)context.GetCompatibleSilos(target); | ||
} | ||
else | ||
{ | ||
var silosByVersion = context.GetCompatibleSilosWithVersions(target); | ||
var maxSiloCount = 0; | ||
ushort version = 0; | ||
foreach (var kvp in silosByVersion) | ||
{ | ||
if (kvp.Value.Count > maxSiloCount) | ||
{ | ||
version = kvp.Key; | ||
maxSiloCount = kvp.Value.Count; | ||
} | ||
} | ||
silos = silosByVersion[version]; | ||
} | ||
|
||
return Task.FromResult(silos[random.Next(silos.Count)]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.