Ejemplo n.º 1
0
        public async Task Start()
        {
            ActorEventSource.Current.ActorMessage(this, "[Driver] is starting");

            if (this.Nodes == null)
            {
                this.NumberOfNodes = 2;

                this.Nodes   = new Dictionary <int, INode>();
                this.NodeMap = new Dictionary <INode, bool>();

                this.SafetyMonitor   = ActorProxy.Create <ISafetyMonitor>(new ActorId(1), "fabric:/FabricFailureDetector");
                this.FailureDetector = ActorProxy.Create <IFailureDetector>(new ActorId(2), "fabric:/FabricFailureDetector");

                await this.Initialize();

                await this.FailureDetector.Configure(this.Nodes.Keys.ToList());

                await this.FailureDetector.RegisterClient(0);

                await this.FailureDetector.Start();

                //this.Fail();
            }
        }
Ejemplo n.º 2
0
        public async Task Configure(int id)
        {
            await Task.Run(() =>
            {
                if (this.ProcessedRequests == null)
                {
                    this.NodeId            = id;
                    this.IsHalted          = false;
                    this.ProcessedRequests = new HashSet <ulong>();

                    this.SafetyMonitor = ActorProxy.Create <ISafetyMonitor>(
                        new ActorId(1), "fabric:/FabricFailureDetector");
                }
            });
        }
Ejemplo n.º 3
0
        protected override async Task OnActivateAsync()
        {
            if (this.Nodes == null)
            {
                this.FailureDetectorId = 2;
                this.Nodes             = new Dictionary <int, INode>();
                this.Clients           = new Dictionary <IDriver, bool>();
                this.Alive             = new Dictionary <INode, bool>();
                this.Responses         = new Dictionary <INode, bool>();
                this.ProcessedRequests = new HashSet <ulong>();
                this.PingCounter       = 0;
                this.HasStarted        = false;

                this.SafetyMonitor = ActorProxy.Create <ISafetyMonitor>(new ActorId(1), "fabric:/FabricFailureDetector");
            }

            await base.OnActivateAsync();
        }
Ejemplo n.º 4
0
        private async void BecomeLeader()
        {
            Console.WriteLine($"<RaftLog> Server {this.ServerId} became LEADER.");
            Console.WriteLine($"<RaftLog> Leader {this.ServerId} | term {this.CurrentTerm} " +
                              $"| election votes {this.VotesReceived} | log {this.Logs.Count}.");

            this.Role          = Role.Leader;
            this.VotesReceived = 0;

            this.SafetyMonitor = this.GrainFactory.GetGrain <ISafetyMonitor>(100);
            await this.SafetyMonitor.NotifyLeaderElected(this.CurrentTerm);

            await this.ClusterManager.NotifyLeaderUpdate(this.ServerId, this.CurrentTerm);

            var logIndex = this.Logs.Count;
            var logTerm  = this.GetLogTermForIndex(logIndex);

            this.NextIndex.Clear();
            this.MatchIndex.Clear();
            foreach (var server in this.Servers)
            {
                if (server.Key == this.ServerId)
                {
                    continue;
                }
                this.NextIndex.Add(server.Value, logIndex + 1);
                this.MatchIndex.Add(server.Value, 0);
            }

            foreach (var server in this.Servers)
            {
                if (server.Key == this.ServerId)
                {
                    continue;
                }

                await server.Value.AppendEntriesRequest(this.CurrentTerm, this.ServerId,
                                                        logIndex, logTerm, new List <Log>(), this.CommitIndex, -1);
            }
        }