Пример #1
0
        /// <summary>
        /// Start all instances of Paxos Roles
        /// You might want to run them on separate nodes/hosts
        /// </summary>
        static void startPaxos()
        {
            ThreadPool.SetMaxThreads(20, 20);

            foreach (Acceptor acceptor in acceptors)
            {
                ThreadPool.QueueUserWorkItem(state => { acceptor.Start(); });
            }
            foreach (Leader leader in leaders)
            {
                ThreadPool.QueueUserWorkItem(state => { leader.Start(); });
            }
            ReplicaFactory replicaFactory = new ReplicaFactory();

            foreach (Replica replica in replicas)
            {
                ThreadPool.QueueUserWorkItem(state => { replicaFactory.StartInstance(replica, leaders); });
            }
        }
Пример #2
0
        /// <summary>
        /// The goal is to create/instantiate all required roles for Paxos
        /// If N is an even number greater or equal to 2
        /// # of replicas = N + 1
        /// # of leaders = N + 1
        /// # of acceptors = 2 * N + 1
        /// </summary>
        static void initializePaxos()
        {
            AcceptorFactory acceptorFactory = new AcceptorFactory();

            acceptors.Add(acceptorFactory.BuildInstance(messageBroker));
            acceptors.Add(acceptorFactory.BuildInstance(messageBroker));
            acceptors.Add(acceptorFactory.BuildInstance(messageBroker));
            acceptors.Add(acceptorFactory.BuildInstance(messageBroker));
            acceptors.Add(acceptorFactory.BuildInstance(messageBroker));

            ReplicaFactory replicaFactory = new ReplicaFactory();

            replicas.Add(replicaFactory.BuildInstance(messageBroker, stateMachine));
            replicas.Add(replicaFactory.BuildInstance(messageBroker, stateMachine));
            replicas.Add(replicaFactory.BuildInstance(messageBroker, stateMachine));

            LeaderFactory leaderFactory = new LeaderFactory();

            leaders.Add(leaderFactory.BuildInstance(messageBroker, acceptors, replicas));
            leaders.Add(leaderFactory.BuildInstance(messageBroker, acceptors, replicas));
            leaders.Add(leaderFactory.BuildInstance(messageBroker, acceptors, replicas));
        }