Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="raftNodeSettings"></param>
        /// <param name="udpPort">e.g. 47777 </param>
        /// <param name="verboseNode">Will call VerbosePrint on true</param>
        public RaftNodeUdp(RaftNodeSettings raftNodeSettings, int udpPort, bool verboseNode)
        {
            try
            {
                TM = new TimeMaster(this);

                udpSocket = new UdpSocketListener(TM, this);
                UdpPort   = udpPort;

                rn = new RaftNode(raftNodeSettings, this, this);

                rn.Verbose          = verboseNode;
                rn.NodeAddress.IsMe = true;

                //Can be increased on the hot system later.
                rn.SetNodesQuantityInTheCluster(raftNodeSettings.InitialQuantityOfRaftNodesInTheCluster);

                //Supplied by emulator for VerbosePrints
                rn.NodeAddress.NodeAddressId = raftNodeSettings.RaftNodeIdExternalForEmulator;
            }
            catch (Exception ex)
            {
                this.LogError(new WarningLogEntry()
                {
                    Exception = ex, Method = "Raft.RaftNodeUdp.RaftNodeUdp"
                });
            }
        }
Exemplo n.º 2
0
        public StateLog(RaftNode rn)
        {
            this.rn = rn;

            //if (rn.nodeSettings.InMemoryEntity)

            //    if (String.IsNullOrEmpty(dbreezePath) || rn.nodeSettings.InMemoryEntity)
            //    db = new DBreezeEngine(new DBreezeConfiguration { Storage = DBreezeConfiguration.eStorage.MEMORY });
            //else
            //    db = new DBreezeEngine(dbreezePath);

            if (rn.entitySettings.EntityName != "default")
            {
                tblStateLogEntry += "_" + rn.entitySettings.EntityName;
            }

            if (rn.entitySettings.InMemoryEntity)
            {
                tblStateLogEntry = "mem_" + tblStateLogEntry;
            }

            using (var t = this.rn.db.GetTransaction())
            {
                var row = t.SelectBackwardFromTo <byte[], byte[]>(tblStateLogEntry,
                                                                  new byte[] { 1 }.ToBytes(ulong.MaxValue, ulong.MaxValue), true,
                                                                  new byte[] { 1 }.ToBytes(ulong.MinValue, ulong.MinValue), true)
                          .FirstOrDefault();

                StateLogEntry sle = null;
                if (row != null && row.Exists)
                {
                    sle                  = StateLogEntry.BiserDecode(row.Value);
                    StateLogId           = sle.Index;
                    StateLogTerm         = sle.Term;
                    PreviousStateLogId   = sle.PreviousStateLogId;
                    PreviousStateLogTerm = sle.PreviousStateLogTerm;

                    tempPrevStateLogId   = PreviousStateLogId;
                    tempPrevStateLogTerm = PreviousStateLogTerm;
                    tempStateLogId       = StateLogId;
                    tempStateLogTerm     = StateLogTerm;

                    rn.NodeTerm = sle.Term;
                }
                var rowTerm = t.Select <byte[], byte[]>(tblStateLogEntry, new byte[] { 2 });
                if (rowTerm.Exists)
                {
                    LastCommittedIndex     = rowTerm.Value.Substring(0, 8).To_UInt64_BigEndian();
                    LastCommittedIndexTerm = rowTerm.Value.Substring(8, 8).To_UInt64_BigEndian();
                }

                var rowBL = t.Select <byte[], ulong>(tblStateLogEntry, new byte[] { 3 });
                if (rowBL.Exists)
                {
                    LastBusinessLogicCommittedIndex = rowBL.Value;
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        public void Dispose()
        {
            try
            {
                this.TM.Dispose();

                if (udpSocket != null)
                {
                    udpSocket.Stop();
                    udpSocket.Dispose();
                    udpSocket = null;
                }

                if (rn != null)
                {
                    rn.NodeStop();
                    rn.Dispose();
                    rn = null;
                }
            }
            catch
            {}
        }
Exemplo n.º 4
0
 public RedirectHandler(RaftNode rn)
 {
     this.rn = rn;
 }