public ViewChangeMessageProcessor(
            MessageServiceClient messageServiceClient,
            ReplicaState replicaState,
            DoViewChangeXL doViewChange)
        {
            this.messageServiceClient = messageServiceClient;
            this.replicaState         = replicaState;

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

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

            this.bestDoViewChange = new DoViewChangeXL(
                this.replicaState.ServerId,
                this.viewNumber,
                this.replicaState.ViewNumber,
                this.configuration,
                this.replicaState.TupleSpace,
                this.replicaState.ClientTable,
                this.replicaState.CommitNumber);

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

            // Stay in this state for a timeout
            Task.Factory.StartNew(this.StartTimeout);
        }
        public ViewChangeMessageProcessor(
            MessageServiceClient messageServiceClient,
            ReplicaState replicaState,
            int viewNumber,
            SortedDictionary <string, Uri> configuration)
        {
            this.messageServiceClient = messageServiceClient;
            this.replicaState         = replicaState;

            this.viewNumber    = viewNumber;
            this.configuration = configuration;

            this.imTheManager         = this.configuration.Values.ToArray()[0].Equals(this.replicaState.MyUrl);
            this.numberToWait         = this.replicaState.Configuration.Count / 2;
            this.messagesDoViewChange = 0;

            this.bestDoViewChange = new DoViewChangeXL(
                this.replicaState.ServerId,
                this.viewNumber,
                this.replicaState.ViewNumber,
                this.configuration,
                this.replicaState.TupleSpace,
                this.replicaState.ClientTable,
                this.replicaState.CommitNumber);

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

            // Start the view change protocol
            Task.Factory.StartNew(this.MulticastStartViewChange);

            // Stay in this state for a timeout
            Task.Factory.StartNew(this.StartTimeout);
        }
        public IResponse VisitDoViewChangeXL(DoViewChangeXL doViewChange)
        {
            if (doViewChange.ViewNumber <= this.replicaState.ViewNumber)
            {
                return(null);
            }
            if (this.imTheManager &&
                doViewChange.ViewNumber == this.viewNumber &&
                ConfigurationUtils.CompareConfigurations(doViewChange.Configuration, this.configuration))
            {
                Interlocked.Increment(ref this.messagesDoViewChange);

                if (doViewChange.OldViewNumber == this.bestDoViewChange.OldViewNumber &&
                    doViewChange.CommitNumber > this.bestDoViewChange.CommitNumber)
                {
                    this.bestDoViewChange = doViewChange;
                }
                if (doViewChange.OldViewNumber > this.bestDoViewChange.OldViewNumber)
                {
                    this.bestDoViewChange = doViewChange;
                }

                this.CheckNumberAndSetNewConfiguration();
            }

            return(null);
        }
Exemplo n.º 4
0
 public void ChangeToViewChange(DoViewChangeXL doViewChange)
 {
     lock (this.State) {
         if (!(this.State is ViewChangeMessageProcessor))
         {
             this.State = new ViewChangeMessageProcessor(this.MessageServiceClient, this, doViewChange);
             this.HandlerStateChanged.Set();
             this.HandlerStateChanged.Reset();
         }
     }
 }
Exemplo n.º 5
0
 public IResponse VisitDoViewChangeXL(DoViewChangeXL doViewChange)
 {
     if (doViewChange.ViewNumber <= this.replicaState.ViewNumber)
     {
         return(null);
     }
     lock (this) {
         if (!(this.replicaState.State is ViewChangeMessageProcessor))
         {
             this.replicaState.ChangeToViewChange(doViewChange);
         }
     }
     return(doViewChange.Accept(this.replicaState.State));
 }
        private void MulticastStartViewChange()
        {
            IMessage message = new StartViewChangeXL(this.replicaState.ServerId, this.viewNumber, this.configuration);

            Uri[] currentConfiguration = this.replicaState.ReplicasUrl.ToArray();

            IResponses responses = this.messageServiceClient.RequestMulticast(
                message,
                currentConfiguration,
                this.replicaState.Configuration.Count / 2,
                Timeout.TIMEOUT_VIEW_CHANGE,
                true);

            IResponse[] responsesVector = responses.ToArray();

            // There was no quorum to accept the view change
            if (responsesVector.Length < this.numberToWait)
            {
                Log.Debug($"There was no quorum for view change. " +
                          $"Just received {responsesVector.Length} from at least {this.numberToWait}");
                this.replicaState.ChangeToNormalState();
                return;
            }

            // In case I'm the manager, wait for f DoViewChange
            if (this.imTheManager)
            {
                this.CheckNumberAndSetNewConfiguration();
            }
            else
            {
                // Else, send DoViewChange to leader
                Uri      leader        = this.configuration.Values.ToArray()[0];
                IMessage doViewMessage = new DoViewChangeXL(
                    this.replicaState.ServerId,
                    this.viewNumber,
                    this.replicaState.ViewNumber,
                    this.configuration,
                    this.replicaState.TupleSpace,
                    this.replicaState.ClientTable,
                    this.replicaState.CommitNumber);

                this.messageServiceClient.Request(doViewMessage, leader, -1);
            }
        }