public void Process(int iteration, RandTestQueueItem item) { var electionsMsg = item.Message as ElectionMessage.ElectionsDone; if (electionsMsg != null) { _electionsResults[item.EndPoint] = electionsMsg.Master.ExternalHttpEndPoint; Done = _electionsResults.Count == _instancesCount; } }
public virtual void Process(int iteration, RandTestQueueItem item) { var msg = item.Message as ElectionMessage.ElectionsDone; if (msg != null) { var master = msg.Master.ExternalHttpEndPoint; ElectionsResults[item.EndPoint] = Tuple.Create(msg.InstalledView, master); Done = ElectionsResults.Values.Count(x => x.Item1 == msg.InstalledView) >= _majorityCount; } }
private MemberInfo[] CreateUpdatedGossip(int iteration, RandTestQueueItem item, ElectionsInstance[] instances, MemberInfo[] initialGossip, Dictionary<IPEndPoint, MemberInfo[]> previousGossip) { if (previousGossip[item.EndPoint].Length < 5) { Console.WriteLine("Update item: {0} : {1}", iteration, item.EndPoint.Port); return instances.Select((x, i) => MemberInfo.ForVNode(x.InstanceId, DateTime.UtcNow, VNodeState.Unknown, true, x.EndPoint, null, x.EndPoint, null, x.EndPoint, x.EndPoint, -1, 0, 0, -1, -1, Guid.Empty, 0)).ToArray(); } return null; }
public void Process(int iteration, RandTestQueueItem item) { var electionsDone = item.Message as ElectionMessage.ElectionsDone; if (electionsDone != null) { MemberInfo[] previousMembers; if (_previousGossip.TryGetValue(item.EndPoint, out previousMembers)) { var masterMemberIndex = Array.FindIndex(previousMembers, x => x.Is(electionsDone.Master.InternalHttpEndPoint)); if (masterMemberIndex != -1) { var previousMasterInfo = previousMembers[masterMemberIndex]; var masterEndPoint = previousMasterInfo.InternalHttpEndPoint; previousMembers[masterMemberIndex] = MemberInfo.ForVNode(previousMasterInfo.InstanceId, DateTime.UtcNow, VNodeState.Master, previousMasterInfo.IsAlive, masterEndPoint, null, masterEndPoint, null, masterEndPoint, masterEndPoint, -1, 0, 0, -1, -1, Guid.Empty, 0); } } } var updatedGossip = _createUpdatedGossip(iteration, item, _instances, _initialGossip, _previousGossip); if (updatedGossip != null) { if (updatedGossip.Length > _instances.Length) throw new InvalidDataException("Gossip should not contain more items than there are servers in the cluster."); _processedItems.Add(item); foreach (var memberInfo in updatedGossip) { _sendOverHttpProcessor.RegisterEndpointToSkip(memberInfo.ExternalTcpEndPoint, !memberInfo.IsAlive); } var updateGossipMessage = new GossipMessage.GossipUpdated(new ClusterInfo(updatedGossip)); _enqueue(item, updateGossipMessage); _previousGossip[item.EndPoint] = updatedGossip; var master = updateGossipMessage.ClusterInfo.Members.FirstOrDefault(x => x.IsAlive && x.State == VNodeState.Master); if (master == null) _enqueue(item, new ElectionMessage.StartElections()); } }
private MemberInfo[] CreateUpdatedGossip(int iteration, RandTestQueueItem item, ElectionsInstance[] instances, MemberInfo[] initialGossip, Dictionary<IPEndPoint, MemberInfo[]> previousGossip) { if (iteration == 1 || (iteration % 100 != (item.EndPoint.Port % 1000) && _randomCase.Next(100) < 30 )) return null; if (previousGossip[item.EndPoint].Length < 5) { return instances.Select((x, i) => MemberInfo.ForVNode(x.InstanceId, DateTime.UtcNow, VNodeState.Unknown, true, x.EndPoint, null, x.EndPoint, null, x.EndPoint, x.EndPoint, -1, 0, 0, -1, -1, Guid.Empty, 0)) .ToArray(); } return null; }
public void Process(int iteration, RandTestQueueItem item) { _items.Add(item); }
private void Enqueue(RandTestQueueItem item, Message message) { Runner.Enqueue(item.EndPoint, message, item.Bus, 10); }