public void Start(int nodeId)
        {
            IEmulatedNode node = null;

            lock (sync_nodes)
            {
                nodes.TryGetValue(nodeId, out node);
            }
            //var node = nodes.Where(r => r.NodeAddress.NodeAddressId == nodeId).FirstOrDefault();
            if (node != null)
            {
                if (node is TcpRaftNode)
                {
                    if (!((TcpRaftNode)node).Disposed)
                    {
                        return;
                    }
                    node = null;

                    TcpRaftNode trn = null;

                    lock (sync_nodes)
                    {
                        trn = new TcpRaftNode(new NodeSettings()
                        {
                            TcpClusterEndPoints = eps, RaftEntitiesSettings = new List <RaftEntitySettings> {
                                re_settings
                            }
                        },
                                              @"D:\Temp\RaftDBreeze\node" + nodeId,
                                              new DefaultHandler(),
                                              nodeId,
                                              null,
                                              this);
                        nodes[trn.GetNodeByEntityName("default").NodeAddress.NodeAddressId] = trn;
                    }
                    trn.Start();
                }
                else
                {
                    node.EmulationStart();
                }
            }
        }
Ejemplo n.º 2
0
        ///// <summary>
        ///// Test method
        ///// </summary>
        ///// <param name="nodeId"></param>
        ///// <param name="stateLogId"></param>
        ///// <returns></returns>
        //public bool ContainsStateLogIdData(int nodeId, ulong stateLogId)
        //{
        //    IEmulatedNode node = null;
        //    lock (sync_nodes)
        //    {
        //        nodes.TryGetValue(nodeId, out node);
        //    }
        //    //var node = nodes.Where(r => r.NodeAddress.NodeAddressId == nodeId).FirstOrDefault();
        //    if (node == null)
        //        return false;

        //    return ((RaftNode)node).ContainsStateLogEntryId(stateLogId);
        //}


        public void Start(int nodeId)
        {
            IEmulatedNode node = null;

            lock (sync_nodes)
            {
                nodes.TryGetValue(nodeId, out node);
            }
            //var node = nodes.Where(r => r.NodeAddress.NodeAddressId == nodeId).FirstOrDefault();
            if (node != null)
            {
                if (node is TcpRaftNode)
                {
                    if (!((TcpRaftNode)node).Disposed)
                    {
                        return;
                    }
                    node = null;

                    TcpRaftNode trn = null;

                    lock (sync_nodes)
                    {
                        trn = new TcpRaftNode(new NodeSettings()
                        {
                            TcpClusterEndPoints = eps, RaftEntitiesSettings = new List <RaftEntitySettings> {
                                re_settings
                            }
                        }, @"D:\Temp\RaftDBreeze\node" + nodeId,
                                              (entityName, index, data) => { Console.WriteLine($"wow committed {entityName}/{index}"); return(true); },
                                              nodeId, this);
                        nodes[trn.GetNodeByEntityName("default").NodeAddress.NodeAddressId] = trn;
                    }
                    trn.Start();
                }
                else
                {
                    node.EmulationStart();
                }
            }
        }
Ejemplo n.º 3
0
        public void StartEmulateTcpNodes(int nodesQuantity)
        {
            TcpRaftNode trn = null;

            rn_settings = new RaftNodeSettings()
            {
                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(eps, new List <RaftNodeSettings> {
                        rn_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();
            }
        }