public ViewChangeMessageProcessor(
            MessageServiceClient messageServiceClient,
            ReplicaState replicaState,
            StartChange startChange)
        {
            this.messageServiceClient = messageServiceClient;
            this.replicaState         = replicaState;

            this.viewNumber    = startChange.ViewNumber;
            this.configuration = startChange.Configuration;

            this.imTheLeader          = startChange.Configuration.Values.ToArray()[0].Equals(this.replicaState.MyUrl);
            this.numberToWait         = (startChange.Configuration.Count - 1) / 2;
            this.messagesDoViewChange = 0;

            this.bestDoViewChange = new DoViewChange(
                this.replicaState.ServerId,
                this.viewNumber,
                this.replicaState.ViewNumber,
                this.configuration,
                this.replicaState.Logger,
                this.replicaState.OpNumber,
                this.replicaState.CommitNumber);

            Log.Info("Changed to View Change State.");

            // Stay in this state for a timeout
            Task.Factory.StartNew(this.StartTimeout);
        }
        private void CheckNumberAndSetNewConfiguration()
        {
            if (this.messagesDoViewChange >= this.numberToWait)
            {
                // start change
                Uri[] replicasUrl = this.configuration.Values
                                    .Where(url => !url.Equals(this.replicaState.MyUrl))
                                    .ToArray();

                IMessage message = new StartChange(
                    this.replicaState.ServerId,
                    this.viewNumber,
                    this.configuration,
                    this.bestDoViewChange.Logger,
                    this.bestDoViewChange.OpNumber,
                    this.bestDoViewChange.CommitNumber);
                Task.Factory.StartNew(() =>
                                      this.messageServiceClient.RequestMulticast(message, replicasUrl, replicasUrl.Length, -1, false));

                // Set new configuration
                this.replicaState.SetNewConfiguration(
                    this.bestDoViewChange.Configuration,
                    replicasUrl,
                    this.bestDoViewChange.ViewNumber,
                    this.bestDoViewChange.Logger,
                    this.bestDoViewChange.OpNumber,
                    this.bestDoViewChange.CommitNumber);

                this.replicaState.ChangeToRecoveryState();
            }
        }
Пример #3
0
 public void ChangeToViewChange(StartChange startChange)
 {
     lock (this.State) {
         if (!(this.State is ViewChangeMessageProcessor))
         {
             this.State = new ViewChangeMessageProcessor(this.MessageServiceClient, this, startChange);
             this.HandlerStateChanged.Set();
             this.HandlerStateChanged.Reset();
         }
     }
 }
 public IResponse VisitStartChange(StartChange startChange)
 {
     if (startChange.ViewNumber <= this.replicaState.ViewNumber)
     {
         return(null);
     }
     lock (this.replicaState.State) {
         if (!(this.replicaState.State is ViewChangeMessageProcessor))
         {
             this.replicaState.ChangeToViewChange(startChange);
         }
     }
     return(startChange.Accept(this.replicaState.State));
 }
Пример #5
0
 public IResponse VisitStartChange(StartChange startChange)
 {
     Log.Info($"Start Change issued from server {startChange.ServerId}");
     if (startChange.ViewNumber <= this.replicaState.ViewNumber)
     {
         return(null);
     }
     lock (this) {
         if (!(this.replicaState.State is ViewChangeMessageProcessor))
         {
             this.replicaState.ChangeToViewChange(startChange);
         }
     }
     return(startChange.Accept(this.replicaState.State));
 }
 public IResponse VisitStartChange(StartChange startChange)
 {
     if (startChange.ViewNumber <= this.replicaState.ViewNumber)
     {
         return(null);
     }
     // Set new configuration
     Uri[] replicasUrl = this.configuration.Values
                         .Where(url => !url.Equals(this.replicaState.MyUrl))
                         .ToArray();
     this.replicaState.SetNewConfiguration(
         startChange.Configuration,
         replicasUrl,
         startChange.ViewNumber,
         startChange.Logger,
         startChange.OpNumber,
         startChange.CommitNumber);
     this.replicaState.ChangeToNormalState();
     return(null);
 }
 public IResponse VisitStartChange(StartChange startChange)
 {
     return(this.WaitNormalState(startChange));
 }