public override Task <SiloAddress> OnAddActivation( PlacementStrategy strategy, PlacementTarget target, IPlacementContext context) { throw new InvalidOperationException("Client Observers are not activated using the placement subsystem. Grain " + target.GrainIdentity); }
public override Task <SiloAddress> OnAddActivation( PlacementStrategy strategy, PlacementTarget target, IPlacementContext context) { throw new ClientNotAvailableException(target.GrainIdentity); }
public async Task <PlacementResult> SelectOrAddActivation( ActivationAddress sendingAddress, PlacementTarget targetGrain, IPlacementContext context, PlacementStrategy strategy) { if (targetGrain.IsClient) { var res = await clientObserversPlacementDirector.OnSelectActivation(strategy, targetGrain.GrainId, context); if (res == null) { throw new ClientNotAvailableException(targetGrain.GrainId); } return(res); } var actualStrategy = strategy ?? defaultPlacementStrategy; var result = await SelectActivation(targetGrain.GrainId, context, actualStrategy); if (result != null) { return(result); } return(await AddActivation(targetGrain, context, actualStrategy)); }
public async Task <PlacementResult> SelectOrAddActivation( PlacementTarget targetGrain, IPlacementRuntime context, PlacementStrategy strategy) { if (targetGrain.IsClient) { var res = await clientObserversPlacementDirector.OnSelectActivation(strategy, (GrainId)targetGrain.GrainIdentity, context); if (res == null) { throw new ClientNotAvailableException(targetGrain.GrainIdentity); } return(res); } var actualStrategy = strategy ?? defaultPlacementStrategy; var director = ResolveSelector(actualStrategy); var result = await director.OnSelectActivation(strategy, targetGrain.GrainIdentity, context); if (result != null) { return(result); } return(await AddActivation(targetGrain, context, actualStrategy)); }
private async Task <PlacementResult> AddActivation( PlacementTarget target, IPlacementRuntime context, PlacementStrategy strategy) { if (target.IsClient) { throw new InvalidOperationException("Client grains are not activated using the placement subsystem."); } var director = ResolveDirector(strategy); var siloAddress = await director.OnAddActivation(strategy, target, context); var grainTypeName = context.GetGrainTypeName(((LegacyGrainId)target.GrainIdentity).TypeCode); ActivationId activationId; if (strategy.IsDeterministicActivationId) { // Use the grain id as the activation id. activationId = ActivationId.GetDeterministic(target.GrainIdentity); } else { activationId = ActivationId.NewId(); } return(PlacementResult.SpecifyCreation( siloAddress, activationId, strategy, grainTypeName)); }
private async ValueTask <PlacementResult> GetOrPlaceActivationAsync( ValueTask <PlacementResult> selectActivationTask, PlacementTarget target, PlacementStrategy strategy, IPlacementRuntime placementRuntime, IPlacementDirector director) { var placementResult = await selectActivationTask; if (placementResult is object) { return(placementResult); } var siloAddress = await director.OnAddActivation(strategy, target, placementRuntime); ActivationId activationId; if (strategy.IsDeterministicActivationId) { // Use the grain id as the activation id. activationId = ActivationId.GetDeterministic(target.GrainIdentity); } else { activationId = ActivationId.NewId(); } return(PlacementResult.SpecifyCreation( siloAddress, activationId, strategy)); }
public virtual Task <SiloAddress> OnAddActivation( PlacementStrategy strategy, PlacementTarget target, IPlacementContext context) { var allSilos = context.GetCompatibleSilos(target); return(Task.FromResult(allSilos[random.Next(allSilos.Count)])); }
public Task <PlacementResult> OnAddActivation(PlacementStrategy strategy, PlacementTarget target, IPlacementContext context) { var grainType = context.GetGrainTypeName(target.GrainId); return(Task.FromResult( PlacementResult.SpecifyCreation(context.LocalSilo, strategy, grainType))); }
public virtual Task <SiloAddress> OnAddActivation( PlacementStrategy strategy, PlacementTarget target, IPlacementContext context) { var allSilos = context.GetCompatibleSilos(target).OrderBy(s => s).ToArray(); // need to sort the list, so that the outcome is deterministic int hash = (int)(target.GrainIdentity.GetUniformHashCode() & 0x7fffffff); // reset highest order bit to avoid negative ints return(Task.FromResult(allSilos[hash % allSilos.Length])); }
public virtual Task <PlacementResult> OnAddActivation( PlacementStrategy strategy, PlacementTarget target, IPlacementContext context) { var grainType = context.GetGrainTypeName(target.GrainId); var allSilos = context.GetCompatibleSiloList(target); return(Task.FromResult( PlacementResult.SpecifyCreation(allSilos[random.Next(allSilos.Count)], strategy, grainType))); }
public virtual Task <SiloAddress> OnAddActivation( PlacementStrategy strategy, PlacementTarget target, IPlacementContext context) { var allSilos = context.GetCompatibleSilos(target); int hash = (int)(target.GrainIdentity.GetUniformHashCode() & 0x7fffffff); // reset highest order bit to avoid negative ints return(Task.FromResult(allSilos[hash % allSilos.Count])); }
OnAddActivation(PlacementStrategy strategy, PlacementTarget target, IPlacementContext context) { // if local silo is not active or does not support this type of grain, revert to random placement if (context.LocalSiloStatus != SiloStatus.Active || !context.GetCompatibleSilos(target).Contains(context.LocalSilo)) { return(base.OnAddActivation(strategy, target, context)); } cachedLocalSilo = cachedLocalSilo ?? Task.FromResult(context.LocalSilo); return(cachedLocalSilo); }
public override Task <SiloAddress> OnAddActivation( PlacementStrategy strategy, PlacementTarget target, IPlacementContext context) { // If the cache was not populated, just place locally if (this.localCache.IsEmpty) { return(Task.FromResult(this.localAddress)); } return(SelectSilo(strategy, target, context)); }
public Task <SiloAddress> SelectSiloPowerOfK(PlacementStrategy strategy, PlacementTarget target, IPlacementContext context) { var compatibleSilos = context.GetCompatibleSilos(target); // Exclude overloaded and non-compatible silos var relevantSilos = new List <CachedLocalStat>(); foreach (CachedLocalStat current in localCache.Values) { if (IsSiloOverloaded(current.SiloStats)) { continue; } if (!compatibleSilos.Contains(current.Address)) { continue; } relevantSilos.Add(current); } if (relevantSilos.Count > 0) { int chooseFrom = Math.Min(relevantSilos.Count, chooseHowMany); var chooseFromThoseSilos = new List <CachedLocalStat>(); while (chooseFromThoseSilos.Count < chooseFrom) { int index = ThreadSafeRandom.Next(relevantSilos.Count); var pickedSilo = relevantSilos[index]; relevantSilos.RemoveAt(index); chooseFromThoseSilos.Add(pickedSilo); } CachedLocalStat minLoadedSilo = chooseFromThoseSilos.First(); foreach (CachedLocalStat s in chooseFromThoseSilos) { if (SiloLoad_ByRecentActivations(s) < SiloLoad_ByRecentActivations(minLoadedSilo)) { minLoadedSilo = s; } } return(MakePlacement(minLoadedSilo)); } var debugLog = string.Format("Unable to select a candidate from {0} silos: {1}", localCache.Count, Utils.EnumerableToString( localCache, kvp => String.Format("SiloAddress = {0} -> {1}", kvp.Key.ToString(), kvp.Value.ToString()))); logger.Warn(ErrorCode.Placement_ActivationCountBasedDirector_NoSilos, debugLog); throw new OrleansException(debugLog); }
/// <summary> /// Gets or places an activation. /// </summary> public ValueTask <PlacementResult> GetOrPlaceActivation(PlacementTarget target, IPlacementRuntime placementRuntime) { var strategy = _strategyResolver.GetPlacementStrategy(target.GrainIdentity.Type); var director = _directorResolver.GetPlacementDirector(strategy); var selector = director as IActivationSelector ?? _defaultActivationSelector; if (selector.TrySelectActivationSynchronously(strategy, target.GrainIdentity, placementRuntime, out var placementResult)) { return(new ValueTask <PlacementResult>(placementResult)); } return(GetOrPlaceActivationAsync(target, strategy, placementRuntime, selector, director)); }
public Task <SiloAddress> OnAddActivation(PlacementStrategy strategy, PlacementTarget target, IPlacementContext context) { // If the current silo is not shutting down, place locally if (!context.LocalSiloStatus.IsTerminating()) { return(Task.FromResult(context.LocalSilo)); } // otherwise, place somewhere else var compatibleSilos = context.GetCompatibleSilos(target); return(Task.FromResult(compatibleSilos[random.Next(compatibleSilos.Count)])); }
OnAddActivation(PlacementStrategy strategy, PlacementTarget target, IPlacementContext context) { // if local silo is not active or does not support this type of grain, revert to random placement if (context.LocalSiloStatus != SiloStatus.Active || !context.GetCompatibleSiloList(target).Contains(context.LocalSilo)) { return(base.OnAddActivation(strategy, target, context)); } var grainType = context.GetGrainTypeName(target.GrainId); return(Task.FromResult( PlacementResult.SpecifyCreation(context.LocalSilo, strategy, grainType))); }
private Task <PlacementResult> AddActivation( PlacementTarget target, IPlacementContext context, PlacementStrategy strategy) { if (target.IsClient) { throw new InvalidOperationException("Client grains are not activated using the placement subsystem."); } var director = ResolveDirector(strategy); return(director.OnAddActivation(strategy, target, context)); }
/// <summary> /// Gets or places an activation. /// </summary> public ValueTask <PlacementResult> GetOrPlaceActivation(PlacementTarget target, IPlacementRuntime placementRuntime) { var strategy = _strategyResolver.GetPlacementStrategy(target.GrainIdentity.Type); var director = _directorResolver.GetPlacementDirector(strategy); var selector = director as IActivationSelector ?? _defaultActivationSelector; var selectActivationTask = selector.OnSelectActivation(strategy, target.GrainIdentity, placementRuntime); if (selectActivationTask.IsCompletedSuccessfully && selectActivationTask.Result is object) { return(selectActivationTask); } return(GetOrPlaceActivationAsync(selectActivationTask, target, strategy, placementRuntime, director)); }
private async Task <PlacementResult> AddActivation( PlacementTarget target, IPlacementRuntime context, PlacementStrategy strategy) { if (target.IsClient) { throw new InvalidOperationException("Client grains are not activated using the placement subsystem."); } var director = ResolveDirector(strategy); return(PlacementResult.SpecifyCreation( await director.OnAddActivation(strategy, target, context), strategy, context.GetGrainTypeName(target.GrainIdentity.TypeCode))); }
private async ValueTask <PlacementResult> GetOrPlaceActivationAsync( PlacementTarget target, PlacementStrategy strategy, IPlacementRuntime placementRuntime, IActivationSelector selector, IPlacementDirector director) { var placementResult = await selector.OnSelectActivation(strategy, target.GrainIdentity, placementRuntime); if (placementResult is object) { return(placementResult); } var siloAddress = await director.OnAddActivation(strategy, target, placementRuntime); string grainTypeName; if (LegacyGrainId.TryConvertFromGrainId(target.GrainIdentity, out var legacyId)) { grainTypeName = placementRuntime.GetGrainTypeName(legacyId.TypeCode); } else { grainTypeName = null; } ActivationId activationId; if (strategy.IsDeterministicActivationId) { // Use the grain id as the activation id. activationId = ActivationId.GetDeterministic(target.GrainIdentity); } else { activationId = ActivationId.NewId(); } return(PlacementResult.SpecifyCreation( siloAddress, activationId, strategy, grainTypeName)); }
public virtual Task <SiloAddress> OnAddActivation( PlacementStrategy strategy, PlacementTarget target, IPlacementContext context) { string siloRole = target.GrainIdentity.Key.ToString(); List <SiloAddress> siloAddressesSameRole = membershipTableManager.MembershipTableSnapshot.Entries .Where(s => s.Value.Status == SiloStatus.Active && s.Value.RoleName == siloRole) .Select(s => s.Key) .Intersect(context.GetCompatibleSilos(target)) .ToList(); if (siloAddressesSameRole == null || siloAddressesSameRole.Count == 0) { throw new OrleansException($"Cannot place grain with RoleName {siloRole}. Either Role name is invalid or there are no active silos with type {siloRole} in MembershipTableSnapshot registered yet."); } return(Task.FromResult(siloAddressesSameRole[ThreadSafeRandom.Next(siloAddressesSameRole.Count)])); }
public Task <SiloAddress> OnAddActivation(PlacementStrategy strategy, PlacementTarget target, IPlacementContext context) { var compatibleSilos = context.GetCompatibleSilos(target); // If the current silo is not shutting down, place locally if we are compatible if (!context.LocalSiloStatus.IsTerminating()) { foreach (var silo in compatibleSilos) { if (silo.Equals(context.LocalSilo)) { return(Task.FromResult(context.LocalSilo)); } } } // otherwise, place somewhere else return(Task.FromResult(compatibleSilos[ThreadSafeRandom.Next(compatibleSilos.Length)])); }
public bool TrySelectActivationSynchronously( ActivationAddress sendingAddress, PlacementTarget targetGrain, IPlacementRuntime context, PlacementStrategy strategy, out PlacementResult placementResult) { if (targetGrain.IsClient) { return(clientObserversPlacementDirector.TrySelectActivationSynchronously( strategy, (GrainId)targetGrain.GrainIdentity, context, out placementResult)); } var actualStrategy = strategy ?? defaultPlacementStrategy; var director = ResolveSelector(actualStrategy); return(director.TrySelectActivationSynchronously(strategy, (GrainId)targetGrain.GrainIdentity, context, out placementResult)); }
OnAddActivation(PlacementStrategy strategy, PlacementTarget target, IPlacementContext context) { throw new InvalidOperationException("Client Observers are not activated using the placement subsystem. Grain " + target.GrainId); }
public override Task <SiloAddress> OnAddActivation( PlacementStrategy strategy, PlacementTarget target, IPlacementContext context) { return(SelectSilo(strategy, target, context)); }
public Task <SiloAddress> OnAddActivation(PlacementStrategy strategy, PlacementTarget target, IPlacementContext context) { return(Task.FromResult(context.LocalSilo)); }