public void StartEmulateNodes(int nodesQuantity)
        {
            RaftNode rn = null;

            RaftEntitySettings re_settings = new RaftEntitySettings()
            {
            };

            for (int i = 0; i < nodesQuantity; i++)
            {
                rn = new RaftNode(re_settings, new DBreeze.DBreezeEngine(@"D:\Temp\RaftDBreeze\node" + (4250 + i)),
                                  this,
                                  this,
                                  new DefaultHandler()
                                  );
                //rn.Verbose = true;
                rn.SetNodesQuantityInTheCluster((uint)nodesQuantity);
                rn.NodeAddress.NodeAddressId = i + 1;
                lock (sync_nodes)
                {
                    nodes.Add(rn.NodeAddress.NodeAddressId, rn);
                }
                System.Threading.Thread.Sleep((new Random()).Next(30, 150));
                // System.Threading.Thread.Sleep(500);
                rn.NodeStart();
            }
        }
        public async Task StartWorkNode(ClusterCommand command)
        {
            //create
            RaftEntitySettings re_settings = null;
            List <int>         ipAddress   = new List <int>();

            for (int i = 0; i < command.IpAddress.Count; i++)
            {
                ipAddress.Add(command.IpAddress[i].port);
            }
            re_settings = new RaftEntitySettings()
            {
                VerboseRaft                = true,
                VerboseTransport           = true,
                DelayedPersistenceIsActive = true,
            };
            List <LockSeriveControlNode> nodes = new List <LockSeriveControlNode>();
            List <PeerEndPoint>          eps   = new List <PeerEndPoint>();
            //every node have seperate configuration
            var order = command.Targets.IndexOf(this.nodeName);

            for (int index = 0; index < command.IpAddress.Count; index++)
            {
                eps.Add(new PeerEndPoint()
                {
                    Host = "127.0.0.1", Port = ipAddress[index]
                });
            }
            int Port     = eps[order].Port;
            var nodeName = this.nodeName + "_worker";

            this.wrk = new RaftServiceNode(
                new NodeSettings()
            {
                TcpClusterEndPoints  = eps,
                RaftEntitiesSettings = re_settings
            },
                LockClusterManager.PathRoot + nodeName,
                new WorkerHandler(this),
                Port,
                nodeName + "_Control",
                logger);
            wrk.Start();

            await Task.Delay(2000);

            await wrk.StartConnect();
        }
Ejemplo n.º 3
0
 public StateMachineTimerLoop(TimeMaster TM, RaftEntitySettings settings, RaftStateMachine stateMachine)
 {
     this.TM             = TM;
     this.entitySettings = settings;
     this.stateMachine   = stateMachine;
 }
Ejemplo n.º 4
0
        public void StartEmulateTcpNodes(int nodesQuantity)
        {
            TcpRaftNode trn = null;

            re_settings = new RaftEntitySettings()
            {
                VerboseRaft = true,
                //VerboseRaft = false,
                VerboseTransport = false,

                DelayedPersistenceIsActive = true,

                //InMemoryEntity = true,
                //InMemoryEntityStartSyncFromLatestEntity = true
            };

            for (int i = 0; i < nodesQuantity; i++)
            {
                eps.Add(new TcpClusterEndPoint()
                {
                    Host = "127.0.0.1", Port = 4250 + i
                });
            }

            for (int i = 0; i < nodesQuantity; i++)
            {
                lock (sync_nodes)
                {
                    //S:\temp\RaftDbr
                    trn = new TcpRaftNode(new NodeSettings()
                    {
                        TcpClusterEndPoints = eps, RaftEntitiesSettings = new List <RaftEntitySettings> {
                            re_settings
                        }
                    }, @"D:\Temp\RaftDBreeze\node" + (4250 + i),
                                          (entityName, index, data) => { Console.WriteLine($"wow committed {entityName}/{index}"); return(true); },
                                          4250 + i, this);

                    //rn = new TcpRaftNode(eps, @"S:\temp\RaftDbr\node" + (4250 + i), 4250 + i,
                    //       (data) => {
                    //           Console.WriteLine($"wow committed");
                    //       }, this, rn_settings);

                    nodes.Add(trn.GetNodeByEntityName("default").NodeAddress.NodeAddressId, trn);
                }

                trn.Start();

                //new Thread(() =>
                //{
                //    rn.Start();
                //    //Thread.CurrentThread.IsBackground = true;

                //    //lock (sync_nodes)
                //    //{
                //    //    rn = new TcpRaftNode(eps, 4250 + i, this, rn_settings);
                //    //    nodes.Add(rn.rn.NodeAddress.NodeAddressId, rn);
                //    //    rn.Start();
                //    //}

                //}).Start();

                //Task.Run(() =>
                //{
                //    rn = new TcpRaftNode(eps, 4250 + i, this, rn_settings);
                //    lock (sync_nodes)
                //    {
                //        nodes.Add(rn.rn.NodeAddress.NodeAddressId, rn);
                //    }
                //    rn.Start();
                //});


                //rn.Verbose = true;
                //rn.SetNodesQuantityInTheCluster((uint)nodesQuantity);
                //rn.NodeAddress.NodeAddressId = i + 1;
                //lock (sync_nodes)
                //{
                //    nodes.Add(4250 + i, rn);
                //}
                System.Threading.Thread.Sleep((new Random()).Next(30, 350));
                //// System.Threading.Thread.Sleep(500);
                //rn.NodeStart();
                //rn.Start();
            }
        }
Ejemplo n.º 5
0
        public async Task StartControlNodes(int num)
        {
            //create
            HttpRaftServiceNode trn         = null;
            RaftEntitySettings  re_settings = null;
            List <int>          ipAddress   = new List <int>();

            for (int i = 0; i < num; i++)
            {
                ipAddress.Add(GetPort());
            }
            re_settings = new RaftEntitySettings()
            {
                VerboseRaft                = true,
                VerboseTransport           = true,
                DelayedPersistenceIsActive = true,
            };
            List <HttpRaftServiceNode> nodes = new List <HttpRaftServiceNode>();

            for (int i = 0; i < num; i++)
            {
                List <PeerEndPoint> eps = new List <PeerEndPoint>();
                //every node have seperate configuration
                for (int index = 0; index < num; index++)
                {
                    eps.Add(new PeerEndPoint()
                    {
                        Host = "127.0.0.1", Port = ipAddress[index]
                    });
                }
                lock (sync_nodes)
                {
                    int Port     = eps[i].Port;
                    var nodeName = "entity" + (i + 1);
                    trn = new HttpRaftServiceNode(
                        new NodeSettings()
                    {
                        TcpClusterEndPoints  = eps,
                        RaftEntitiesSettings = re_settings
                    },
                        PathRoot + nodeName,
                        new LockClusterManagerHandler(),
                        Port,
                        nodeName,
                        10000 + i,
                        new HelloServerHandler(),
                        log
                        );
                    this.Nodes.Add(trn);
                }
                nodes.Add(trn);
                trn.Start();
                await trn.StartHttp();

                System.Threading.Thread.Sleep((new Random()).Next(30, 350));
            }
            for (int i = 0; i < num; i++)
            {
                await nodes[i].StartConnect();
            }
        }
Ejemplo n.º 6
0
        public static TcpRaftNode GetFromConfig(int configVersion, string configuration, string dbreezePath, int port, IWarningLog log, Func <string, ulong, byte[], bool> OnCommit)
        {
            //Setip for configVersion=1
            try
            {
                TcpRaftNode rn = null;


                var re_settings = new RaftEntitySettings()
                {
                    EntityName       = "default",
                    VerboseRaft      = false,
                    VerboseTransport = false
                };

                string[] sev;
                List <TcpClusterEndPoint> eps = new List <TcpClusterEndPoint>();

                List <RaftEntitySettings> reSettings = new List <RaftEntitySettings>();
                string entityName = "";

                StringReader strReader = new StringReader(configuration);

                while (true)
                {
                    var el = strReader.ReadLine();
                    if (el == null)
                    {
                        break;
                    }

                    var se = el.Split(new char[] { ':' });
                    if (se.Length < 2)
                    {
                        continue;
                    }
                    switch (se[0].Trim().ToLower())
                    {
                    case "endpoint":
                        sev = se[1].Split(new char[] { ',' });
                        eps.Add(new TcpClusterEndPoint()
                        {
                            Host = sev[0].Trim(), Port = Convert.ToInt32(sev[1].Trim())
                        });
                        break;

                    //case "dbreeze":
                    //    dbreeze = String.Join(":",se.Skip(1));
                    //    break;
                    case "entity":
                        entityName = se[1].Trim();
                        if (entityName.ToLower().Equals("default"))
                        {
                            continue;
                        }
                        //flushing default entity and starting new one
                        if (String.IsNullOrEmpty(entityName))
                        {
                            throw new Exception("Raft.Net: configuration entity name must not be empty and must be unique among other entities");
                        }
                        reSettings.Add(re_settings);
                        re_settings = new RaftEntitySettings {
                            EntityName = entityName
                        };
                        break;

                    case "verboseraft":
                        if (se[1].Trim().ToLower().Equals("true"))
                        {
                            re_settings.VerboseRaft = true;
                        }
                        break;

                    case "verbosetransport":
                        if (se[1].Trim().ToLower().Equals("true"))
                        {
                            re_settings.VerboseTransport = true;
                        }
                        break;

                    case "delayedpersistenceisactive":
                        if (se[1].Trim().ToLower().Equals("true"))
                        {
                            re_settings.DelayedPersistenceIsActive = true;
                        }
                        break;

                    case "delayedpersistencems":
                        re_settings.DelayedPersistenceMs = Convert.ToUInt32(se[1].Trim());
                        break;

                    case "inmemoryentity":
                        if (se[1].Trim().ToLower().Equals("true"))
                        {
                            re_settings.InMemoryEntity = true;
                        }
                        break;

                    case "inmemoryentitystartsyncfromlatestentity":
                        if (se[1].Trim().ToLower().Equals("true"))
                        {
                            re_settings.InMemoryEntityStartSyncFromLatestEntity = true;
                        }
                        break;
                    }//DelayedPersistenceMs
                }

                reSettings.Add(re_settings);


                rn = new TcpRaftNode(new NodeSettings()
                {
                    TcpClusterEndPoints = eps, RaftEntitiesSettings = reSettings
                }, dbreezePath,
                                     OnCommit,
                                     port, log);

                return(rn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }