Example #1
0
        public void ReloadReplica(BasicRSLTestMachine replica)
        {
            Console.WriteLine("{0} reloading  ------------------", replica.Self.MemberId);

            bool res = replica.Initialize(
                cfg,
                replica.Self,
                ManagedRSLProtocolVersion.ManagedRSLProtocolVersion_4,
                false);

            Debug.Assert(res);

            Console.WriteLine("{0} reloaded -----------------------", replica.Self.MemberId);
            this._allReplicaSet.Add(replica);
            this._replicaSet.Add(replica);
        }
Example #2
0
        /// <summary>
        /// Starts the configured number of replicas, this function will create
        /// the necessery files that are needed for the aplicaton to run
        /// </summary>
        /// <param name="numberOfReplicas">numberOfReplicas</param>
        /// <returns></returns>
        public int StartUp(int numberOfReplicas)
        {
            cfg = new ManagedRSLConfigParam();
            cfg.NewLeaderGracePeriodSec    = 10;
            cfg.HeartBeatIntervalSec       = 2;
            cfg.ElectionDelaySec           = 5;
            cfg.MaxElectionRandomizeSec    = 1;
            cfg.InitializeRetryIntervalSec = 1;
            cfg.PrepareRetryIntervalSec    = 1;
            cfg.VoteRetryIntervalSec       = 1;
            cfg.CPQueryRetryIntervalSec    = 5;
            cfg.MaxCheckpointIntervalSec   = 0;
            cfg.MaxLogLenMB              = 100;
            cfg.SendTimeoutSec           = 10;
            cfg.ReceiveTimeoutSec        = 10;
            cfg.MaxCacheLengthMB         = 50;
            cfg.MaxVotesInLog            = 1000;
            cfg.MaxOutstandingPerReplica = 10;
            cfg.MaxCheckpoints           = 2;
            cfg.MaxLogs                      = 5;
            cfg.LogLenRandomize              = 20;
            cfg.ElectionRandomize            = 10;
            cfg.FastReadSeqThreshold         = 5;
            cfg.InMemoryExecutionQueueSizeMB = 10;
            cfg.NumReaderThreads             = 5;
            cfg.MaxMessageSizeMB             = 1;
            cfg.WorkingDir                   = RSLWorkingDir;

            ManagedRSLNode[] nodes = new ManagedRSLNode[numberOfReplicas];
            for (int i = 0; i < nodes.Length; i++)
            {
                nodes[i]          = new ManagedRSLNode();
                nodes[i].MemberId = (i + 1).ToString();
                nodes[i].RslPort  = (ushort)(5000 + (100 * (i + 1)));
                nodes[i].HostName = "127.0.0.1";
                nodes[i].Ip       = new IPAddress(0x0100007F); // 127.0.0.1
            }

            int startedReplicas = 0;

            if (_replicaSet == null)
            {
                _replicaSet = new List <BasicRSLTestMachine>();

                ManagedRSLStateMachine.NotificationsCallback = OnNotification;

                ManagedRSLStateMachine.Init(".\\" + RSLDebugLogsDir);
                for (int i = 0; i < nodes.Length; i++)
                {
                    BasicRSLTestMachine replica = new BasicRSLTestMachine(nodes[i]);
                    try
                    {
                        bool res = replica.Initialize(
                            cfg,
                            nodes[i],
                            ManagedRSLProtocolVersion.ManagedRSLProtocolVersion_4,
                            false);
                        Debug.Assert(res);
                        startedReplicas++;
                        _replicaSet.Add(replica);
                        _allReplicaSet.Add(replica);
                    }
                    catch (Exception e)
                    {
                        if (e is NullReferenceException || e is System.Runtime.InteropServices.SEHException)
                        {
                            throw;
                        }
                    } //catch
                }     // for

                Console.WriteLine("Bootstrapping");
                byte[] buf = new byte[] { 1 };
                ManagedRSLMemberSet memberSet = new ManagedRSLMemberSet(nodes, buf, 0, 1);

                foreach (BasicRSLTestMachine replica in _allReplicaSet)
                {
                    RSLResponse resp = replica.Bootstrap(memberSet, 10);
                    Console.WriteLine(resp);
                }
            }
            else
            {
                startedReplicas = _replicaSet.Count;
            }

            return(startedReplicas);
        } //StartUp