public bool OkToRemove(UnregistrationCause cause, GlobalConfiguration config) { switch (cause) { case UnregistrationCause.Force: return(true); case UnregistrationCause.CacheInvalidation: return(RegistrationStatus == GrainDirectoryEntryStatus.Cached); case UnregistrationCause.NonexistentActivation: { if (RegistrationStatus == GrainDirectoryEntryStatus.Cached) { return(true); // cache entries are always removed } var delayparameter = config.DirectoryLazyDeregistrationDelay; if (delayparameter <= TimeSpan.Zero) { return(false); // no lazy deregistration } else { return(TimeCreated <= DateTime.UtcNow - delayparameter); } } default: throw new OrleansException("unhandled case"); } }
public async Task UnregisterAsync(GrainAddress address, UnregistrationCause cause, int hopCount) { (hopCount > 0 ? UnregistrationsRemoteReceived : unregistrationsIssued).Increment(); if (hopCount == 0) { InvalidateCacheEntry(address); } // see if the owner is somewhere else (returns null if we are owner) var forwardaddress = this.CheckIfShouldForward(address.GrainId, hopCount, "UnregisterAsync"); // on all silos other than first, we insert a retry delay and recheck owner before forwarding if (hopCount > 0 && forwardaddress != null) { await Task.Delay(RETRY_DELAY); forwardaddress = this.CheckIfShouldForward(address.GrainId, hopCount, "UnregisterAsync"); this.log.LogWarning($"UnregisterAsync - It seems we are not the owner of activation {address}, trying to forward it to {forwardaddress} (hopCount={hopCount})"); } if (forwardaddress == null) { // we are the owner UnregistrationsLocal.Increment(); DirectoryPartition.RemoveActivation(address.GrainId, address.ActivationId, cause); } else { UnregistrationsRemoteSent.Increment(); // otherwise, notify the owner await GetDirectoryReference(forwardaddress).UnregisterAsync(address, cause, hopCount + 1); } }
public bool OkToRemove(UnregistrationCause cause) { switch (cause) { case UnregistrationCause.Force: return true; case UnregistrationCause.CacheInvalidation: return RegistrationStatus == GrainDirectoryEntryStatus.Cached; case UnregistrationCause.NonexistentActivation: { if (RegistrationStatus == GrainDirectoryEntryStatus.Cached) return true; // cache entries are always removed var delayparameter = Silo.CurrentSilo.OrleansConfig.Globals.DirectoryLazyDeregistrationDelay; if (delayparameter <= TimeSpan.Zero) return false; // no lazy deregistration else return (TimeCreated <= DateTime.UtcNow - delayparameter); } default: throw new OrleansException("unhandled case"); } }
/// <summary> /// Removes an activation of the given grain from the partition /// </summary> /// <param name="grain">the identity of the grain</param> /// <param name="activation">the id of the activation</param> /// <param name="cause">reason for removing the activation</param> internal void RemoveActivation(GrainId grain, ActivationId activation, UnregistrationCause cause = UnregistrationCause.Force) { IActivationInfo ignore1; bool ignore2; RemoveActivation(grain, activation, cause, out ignore1, out ignore2); }
public async Task Unregister(ActivationAddress address, UnregistrationCause cause) { try { await this.grainDirectory.Unregister(address.ToGrainAddress()); } finally { this.cache.Remove(address.Grain); } }
public async Task Unregister(GrainAddress address, UnregistrationCause cause) { try { await GetGrainDirectory(address.GrainId.Type).Unregister(address); } finally { this.cache.Remove(address); } }
public bool RemoveActivation(ActivationId act, UnregistrationCause cause, TimeSpan lazyDeregistrationDelay, out IActivationInfo info, out bool wasRemoved) { wasRemoved = false; if (Instances.TryGetValue(act, out info) && info.OkToRemove(cause, lazyDeregistrationDelay)) { Instances.Remove(act); wasRemoved = true; VersionTag = rand.Next(); } return(Instances.Count == 0); }
public bool RemoveActivation(ActivationId act, UnregistrationCause cause, GlobalConfiguration config, out IActivationInfo info, out bool wasRemoved) { info = null; wasRemoved = false; if (Instances.TryGetValue(act, out info) && info.OkToRemove(cause, config)) { Instances.Remove(act); wasRemoved = true; VersionTag = rand.Next(); } return(Instances.Count == 0); }
public async Task Unregister(ActivationAddress address, UnregistrationCause cause) { if (address.Grain.IsClient) { await this.inClusterGrainLocator.Unregister(address, cause); } else { await this.grainDirectory.Unregister(ConvertToGrainAddress(address)); this.cache.Remove(address.Grain); } }
public async Task UnregisterMany(List <ActivationAddress> addresses, UnregistrationCause cause) { try { var grainAddresses = addresses.Select(addr => addr.ToGrainAddress()).ToList(); await this.grainDirectory.UnregisterMany(grainAddresses); } finally { foreach (var address in addresses) { this.cache.Remove(address.Grain); } } }
/// <summary> /// Removes an activation of the given grain from the partition /// </summary> /// <param name="grain">the identity of the grain</param> /// <param name="activation">the id of the activation</param> /// <param name="cause">reason for removing the activation</param> /// <param name="entry">returns the entry, if found </param> /// <param name="wasRemoved">returns whether the entry was actually removed</param> internal void RemoveActivation(GrainId grain, ActivationId activation, UnregistrationCause cause, out IActivationInfo entry, out bool wasRemoved) { wasRemoved = false; entry = null; lock (lockable) { if (partitionData.ContainsKey(grain) && partitionData[grain].RemoveActivation(activation, cause, globalConfig, out entry, out wasRemoved)) { // if the last activation for the grain was removed, we remove the entire grain info partitionData.Remove(grain); } } if (log.IsEnabled(LogLevel.Trace)) { log.Trace("Removing activation for grain {0} cause={1} was_removed={2}", grain.ToString(), cause, wasRemoved); } }
public async Task UnregisterManyAsync(List <GrainAddress> addresses, UnregistrationCause cause, int hopCount) { (hopCount > 0 ? UnregistrationsManyRemoteReceived : unregistrationsManyIssued).Increment(); Dictionary <SiloAddress, List <GrainAddress> > forwardlist = null; var tasks = new List <Task>(); UnregisterOrPutInForwardList(addresses, cause, hopCount, ref forwardlist, tasks, "UnregisterManyAsync"); // before forwarding to other silos, we insert a retry delay and re-check destination if (hopCount > 0 && forwardlist != null) { await Task.Delay(RETRY_DELAY); Dictionary <SiloAddress, List <GrainAddress> > forwardlist2 = null; UnregisterOrPutInForwardList(addresses, cause, hopCount, ref forwardlist2, tasks, "UnregisterManyAsync"); forwardlist = forwardlist2; if (forwardlist != null) { this.log.LogWarning($"RegisterAsync - It seems we are not the owner of some activations, trying to forward it to {forwardlist.Count} silos (hopCount={hopCount})"); } } // forward the requests if (forwardlist != null) { foreach (var kvp in forwardlist) { UnregistrationsManyRemoteSent.Increment(); tasks.Add(GetDirectoryReference(kvp.Key).UnregisterManyAsync(kvp.Value, cause, hopCount + 1)); } } // wait for all the requests to finish await Task.WhenAll(tasks); }
public bool OkToRemove(UnregistrationCause cause, TimeSpan lazyDeregistrationDelay) { switch (cause) { case UnregistrationCause.Force: return(true); case UnregistrationCause.NonexistentActivation: { var delayparameter = lazyDeregistrationDelay; if (delayparameter <= TimeSpan.Zero) { return(false); // no lazy deregistration } else { return(TimeCreated <= DateTime.UtcNow - delayparameter); } } default: throw new OrleansException("unhandled case"); } }
public Task UnregisterManyAsync(List<ActivationAddress> addresses, UnregistrationCause cause, int hopCount) { return router.UnregisterManyAsync(addresses, cause, hopCount); }
public Task Unregister(ActivationAddress address, UnregistrationCause cause) => this.localGrainDirectory.UnregisterAsync(address, cause);
/// <summary> /// Removes an activation of the given grain from the partition /// </summary> /// <param name="grain">the identity of the grain</param> /// <param name="activation">the id of the activation</param> /// <param name="cause">reason for removing the activation</param> /// <param name="entry">returns the entry, if found </param> /// <param name="wasRemoved">returns whether the entry was actually removed</param> internal void RemoveActivation(GrainId grain, ActivationId activation, UnregistrationCause cause, out IActivationInfo entry, out bool wasRemoved) { wasRemoved = false; entry = null; lock (lockable) { if (partitionData.ContainsKey(grain) && partitionData[grain].RemoveActivation(activation, cause, out entry, out wasRemoved)) // if the last activation for the grain was removed, we remove the entire grain info partitionData.Remove(grain); } if (log.IsVerbose3) log.Verbose3("Removing activation for grain {0} cause={1} was_removed={2}", grain.ToString(), cause, wasRemoved); }
public Task UnregisterMany(List <ActivationAddress> addresses, UnregistrationCause cause) => this.localGrainDirectory.UnregisterManyAsync(addresses, cause);
public bool RemoveActivation(ActivationId act, UnregistrationCause cause, out IActivationInfo info, out bool wasRemoved) { info = null; wasRemoved = false; if (Instances.TryGetValue(act, out info) && info.OkToRemove(cause)) { Instances.Remove(act); wasRemoved = true; VersionTag = rand.Next(); } return Instances.Count == 0; }
/// <summary> /// Removes an activation of the given grain from the partition /// </summary> /// <param name="grain">the identity of the grain</param> /// <param name="activation">the id of the activation</param> /// <param name="cause">reason for removing the activation</param> internal void RemoveActivation(GrainId grain, ActivationId activation, UnregistrationCause cause = UnregistrationCause.Force) { RemoveActivation(grain, activation, cause, out _, out _); }
public async Task UnregisterMany(List <ActivationAddress> addresses, UnregistrationCause cause) { var tasks = addresses.Select(addr => Unregister(addr, cause)).ToList(); await Task.WhenAll(tasks); }
public void Unregister(ActivationAddress address, UnregistrationCause cause) { directoryPartition.RemoveActivation(address.Grain, address.Activation, cause); }
public Task UnregisterAsync(ActivationAddress address, UnregistrationCause cause, int hopCount) { return(router.UnregisterAsync(address, cause, hopCount)); }
public Task UnregisterAsync(List <ActivationAddress> addresses, UnregistrationCause cause) { List <ActivationAddress> formerActivationsInThisCluster = null; foreach (var address in addresses) { IActivationInfo existingAct; bool wasRemoved; directoryPartition.RemoveActivation(address.Grain, address.Activation, cause, out existingAct, out wasRemoved); if (existingAct == null) { logger.Verbose2("GSIP:Unr {0} {1} ignored", cause, address); } else if (!wasRemoved) { logger.Verbose2("GSIP:Unr {0} {1} too fresh", cause, address); } else if (existingAct.RegistrationStatus == GrainDirectoryEntryStatus.Owned || existingAct.RegistrationStatus == GrainDirectoryEntryStatus.Doubtful) { logger.Verbose2("GSIP:Unr {0} {1} broadcast ({2})", cause, address, existingAct.RegistrationStatus); if (formerActivationsInThisCluster == null) { formerActivationsInThisCluster = new List <ActivationAddress>(); } formerActivationsInThisCluster.Add(address); } else { logger.Verbose2("GSIP:Unr {0} {1} removed ({2})", cause, address, existingAct.RegistrationStatus); } } if (formerActivationsInThisCluster == null) { return(TaskDone.Done); } // we must also remove cached references to former activations in this cluster // from remote clusters; thus, we broadcast the unregistration var myClusterId = Silo.CurrentSilo.ClusterId; if (myClusterId == null) { return(TaskDone.Done); // single cluster - no broadcast required } // target clusters in current configuration, other than this one var remoteClusters = Silo.CurrentSilo.LocalMultiClusterOracle.GetMultiClusterConfiguration().Clusters .Where(id => id != myClusterId).ToList(); var tasks = new List <Task>(); foreach (var remoteCluster in remoteClusters) { // find gateway var gossipOracle = Silo.CurrentSilo.LocalMultiClusterOracle; var clusterGatewayAddress = gossipOracle.GetRandomClusterGateway(remoteCluster); if (clusterGatewayAddress != null) { var clusterGrainDir = InsideRuntimeClient.Current.InternalGrainFactory.GetSystemTarget <IClusterGrainDirectory>(Constants.ClusterDirectoryServiceId, clusterGatewayAddress); // try to send request tasks.Add(clusterGrainDir.ProcessDeactivations(formerActivationsInThisCluster)); } } return(Task.WhenAll(tasks)); }
public Task UnregisterAsync(List <ActivationAddress> addresses, UnregistrationCause cause) { throw new InvalidOperationException(); }
public Task UnregisterAsync(ActivationAddress address, UnregistrationCause cause, int hopCount) { return router.UnregisterAsync(address, cause, hopCount); }
public Task UnregisterAsync(List<ActivationAddress> addresses, UnregistrationCause cause) { List<ActivationAddress> formerActivationsInThisCluster = null; foreach (var address in addresses) { IActivationInfo existingAct; bool wasRemoved; directoryPartition.RemoveActivation(address.Grain, address.Activation, cause, out existingAct, out wasRemoved); if (existingAct == null) { logger.Verbose2("GSIP:Unr {0} {1} ignored", cause, address); } else if (!wasRemoved) { logger.Verbose2("GSIP:Unr {0} {1} too fresh", cause, address); } else if (existingAct.RegistrationStatus == GrainDirectoryEntryStatus.Owned || existingAct.RegistrationStatus == GrainDirectoryEntryStatus.Doubtful) { logger.Verbose2("GSIP:Unr {0} {1} broadcast ({2})", cause, address, existingAct.RegistrationStatus); if (formerActivationsInThisCluster == null) formerActivationsInThisCluster = new List<ActivationAddress>(); formerActivationsInThisCluster.Add(address); } else { logger.Verbose2("GSIP:Unr {0} {1} removed ({2})", cause, address, existingAct.RegistrationStatus); } } if (formerActivationsInThisCluster == null) return TaskDone.Done; // we must also remove cached references to former activations in this cluster // from remote clusters; thus, we broadcast the unregistration var myClusterId = Silo.CurrentSilo.ClusterId; if (myClusterId == null) return TaskDone.Done; // single cluster - no broadcast required // target clusters in current configuration, other than this one var remoteClusters = Silo.CurrentSilo.LocalMultiClusterOracle.GetMultiClusterConfiguration().Clusters .Where(id => id != myClusterId).ToList(); var tasks = new List<Task>(); foreach (var remoteCluster in remoteClusters) { // find gateway var gossipOracle = Silo.CurrentSilo.LocalMultiClusterOracle; var clusterGatewayAddress = gossipOracle.GetRandomClusterGateway(remoteCluster); if (clusterGatewayAddress != null) { var clusterGrainDir = InsideRuntimeClient.Current.InternalGrainFactory.GetSystemTarget<IClusterGrainDirectory>(Constants.ClusterDirectoryServiceId, clusterGatewayAddress); // try to send request tasks.Add(clusterGrainDir.ProcessDeactivations(formerActivationsInThisCluster)); } } return Task.WhenAll(tasks); }
// helper method to avoid code duplication inside UnregisterManyAsync private void UnregisterOrPutInForwardList(IEnumerable <GrainAddress> addresses, UnregistrationCause cause, int hopCount, ref Dictionary <SiloAddress, List <GrainAddress> > forward, List <Task> tasks, string context) { foreach (var address in addresses) { // see if the owner is somewhere else (returns null if we are owner) var forwardAddress = this.CheckIfShouldForward(address.GrainId, hopCount, context); if (forwardAddress != null) { AddToDictionary(ref forward, forwardAddress, address); } else { // we are the owner UnregistrationsLocal.Increment(); DirectoryPartition.RemoveActivation(address.GrainId, address.ActivationId, cause); } } }
public void Unregister(ActivationAddress address, UnregistrationCause cause) { throw new InvalidOperationException(); }
public Task UnregisterManyAsync(List <ActivationAddress> addresses, UnregistrationCause cause, int hopCount) { return(router.UnregisterManyAsync(addresses, cause, hopCount)); }
public Task Unregister(ActivationAddress address, UnregistrationCause cause) => throw new InvalidOperationException($"Cannot unregister client grain explicitly");
public Task UnregisterAsync(List<ActivationAddress> addresses, UnregistrationCause cause) { throw new InvalidOperationException(); }
public Task Unregister(ActivationAddress address, UnregistrationCause cause) => GetGrainLocator(address.Grain.Type).Unregister(address, cause);
public Task UnregisterManyAsync(List <ActivationAddress> addresses, UnregistrationCause cause, int hopCount) { return(localGrainDirectory.UnregisterManyAsync(addresses, cause, hopCount)); }