private void MemberLeft(MemberLeftEvent msg, IContext context) { _logger.LogInformation($"Kind {_kind} Member Left {msg.Address}"); foreach (var(actorId, pid) in _partition.ToArray()) { if (pid.Address == msg.Address) { _partition.Remove(actorId); _reversePartition.Remove(pid); } } //If the left member is self, transfer remaining pids to others if (msg.Address == ProcessRegistry.Instance.Address) { //TODO: right now we transfer ownership on a per actor basis. //this could be done in a batch //ownership is also racy, new nodes should maybe forward requests to neighbours (?) foreach (var(actorId, _) in _partition.ToArray()) { var address = MemberList.GetPartition(actorId, _kind); if (!string.IsNullOrEmpty(address)) { TransferOwnership(actorId, address, context); } } } }
private void MemberLeft(MemberLeftEvent msg) { _logger.LogInformation("Member Left {0}", msg.Address); foreach (var(actorId, pid) in _partition.ToArray()) { if (pid.Address == msg.Address) { _partition.Remove(actorId); } } }
private void Notify(MemberStatus @new, MemberStatus old) { if (@new == null && old == null) { return; //ignore } if (@new == null) { //notify left var left = new MemberLeftEvent(old.Host, old.Port, old.Kinds); Actor.EventStream.Publish(left); _members.Remove(old.Address); var endpointTerminated = new EndpointTerminatedEvent { Address = old.Address }; Actor.EventStream.Publish(endpointTerminated); return; } if (old == null) { //notify joined var joined = new MemberJoinedEvent(@new.Host, @new.Port, @new.Kinds); Actor.EventStream.Publish(joined); return; } if (@new.MemberId != old.MemberId) { var rejoined = new MemberRejoinedEvent(@new.Host, @new.Port, @new.Kinds); Actor.EventStream.Publish(rejoined); return; } if (old.Alive && [email protected]) { var unavailable = new MemberUnavailableEvent(@new.Host, @new.Port, @new.Kinds); Actor.EventStream.Publish(unavailable); return; } if (@new.Alive && !old.Alive) { var available = new MemberAvailableEvent(@new.Host, @new.Port, @new.Kinds); Actor.EventStream.Publish(available); } }
private static void UpdateAndNotify(MemberStatus @new, MemberStatus old) { if (@new == null && old == null) { return; //ignore } if (@new == null) { //update MemberStrategy foreach (var k in old.Kinds) { if (MemberStrategyByKind.TryGetValue(k, out var ms)) { ms.RemoveMember(old); if (ms.GetAllMembers().Count == 0) { MemberStrategyByKind.Remove(k); } } } //notify left var left = new MemberLeftEvent(old.Host, old.Port, old.Kinds); Actor.EventStream.Publish(left); Members.Remove(old.Address); var endpointTerminated = new EndpointTerminatedEvent { Address = old.Address }; Actor.EventStream.Publish(endpointTerminated); return; } if (old == null) { //update MemberStrategy foreach (var k in @new.Kinds) { if (!MemberStrategyByKind.ContainsKey(k)) { MemberStrategyByKind[k] = Cluster.Config.MemberStrategyBuilder(k); } MemberStrategyByKind[k].AddMember(@new); } //notify joined var joined = new MemberJoinedEvent(@new.Host, @new.Port, @new.Kinds); Actor.EventStream.Publish(joined); return; } //update MemberStrategy if (@new.Alive != old.Alive || @new.MemberId != old.MemberId || @new.StatusValue != null && [email protected](old.StatusValue)) { foreach (var k in @new.Kinds) { if (MemberStrategyByKind.TryGetValue(k, out var ms)) { ms.UpdateMember(@new); } } } //notify changes if (@new.MemberId != old.MemberId) { var rejoined = new MemberRejoinedEvent(@new.Host, @new.Port, @new.Kinds); Actor.EventStream.Publish(rejoined); } }