Exemplo n.º 1
0
        public void SetPeerAsDead(IReplica deadPeer)
        {
            Debug.Assert(deadPeer != LocalReplica);
            lock (AliveMembers)
            {
                NoOwner.UnionWith(deadPeer.PopOwnedTuples());
                AliveMembers.Remove(deadPeer);
            }

            if (AmILeader() && NoOwner.Count > 0)
            {
                foreach (var freeTuple in NoOwner)
                {
                    Queue <int> interestedPeers;
                    if (Shared.TryGetValue(freeTuple, out interestedPeers))
                    {
                        var interestedAlivePeer = interestedPeers
                                                  .Select(id => AllMembers[id])
                                                  .Intersect(AliveMembers)
                                                  .FirstOrDefault();

                        if (interestedAlivePeer != null)
                        {
                            RMSend(r => r.SetOwner(freeTuple, interestedAlivePeer.ReplicaId));
                        }
                        else
                        {
                            var chosenPeerIdx = LocalRoutingStrategy.Route(freeTuple.Content, AliveMembers.Count);
                            var chosenPeer    = AliveMembers[chosenPeerIdx];
                            RMSend(p => p.SetOwner(freeTuple, chosenPeer.ReplicaId));
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
 public void SetOwner(DadTuple tuple, int ownerId)
 {
     NoOwner.Remove(tuple);
     AllMembers[ownerId].AddOwnedTuple(tuple);
 }