Exemplo n.º 1
0
        public void Read(BinaryReader msg)
        {
            From = msg.ReadIPEndPoint();

            if (msg.ReadBoolean())
            {
                var entry = new LogEntry();
                var index = new LogIndex();

                index.Term = msg.ReadUInt32();
                index.Type = (LogIndexType)msg.ReadUInt32();
                index.ChunkOffset = msg.ReadUInt32();
                index.ChunkSize = msg.ReadUInt32();
                index.Flag1 = msg.ReadUInt32();
                index.Flag2 = msg.ReadUInt32();
                index.Flag3 = msg.ReadUInt32();
                index.Flag4 = msg.ReadUInt32();

                entry.Index = index;

                var dataLength = msg.ReadInt32();
                entry.Data = msg.ReadBytes(dataLength);

                Entry = entry;
            }
            else
            {
                Entry = null;
            }
        }
Exemplo n.º 2
0
        public void Read(BinaryReader msg)
        {
            From = msg.ReadIPEndPoint();
            AgentIP = msg.ReadIPEndPoint();
            Term = msg.ReadUInt32();
            PrevTerm = msg.ReadUInt32();
            PrevIndex = msg.ReadUInt32();
            CommitIndex = msg.ReadUInt32();

            var length = msg.ReadInt32();
            if (length > 0)
            {
                Entries = new LogEntry[length];
                for (var i = 0; i < length; i++)
                {
                    var entry = new LogEntry();
                    var index = new LogIndex();

                    index.Term = msg.ReadUInt32();
                    index.Type = (LogIndexType)msg.ReadUInt32();
                    index.ChunkOffset = msg.ReadUInt32();
                    index.ChunkSize = msg.ReadUInt32();
                    index.Flag1 = msg.ReadUInt32();
                    index.Flag2 = msg.ReadUInt32();
                    index.Flag3 = msg.ReadUInt32();
                    index.Flag4 = msg.ReadUInt32();

                    entry.Index = index;

                    var dataLength = msg.ReadInt32();
                    entry.Data = msg.ReadBytes(dataLength);

                    Entries[i] = entry;
                }
            }
        }
Exemplo n.º 3
0
        public byte[] GetData(LogIndex index)
        {
            var data = new byte[index.ChunkSize];

            using (var fr = OpenDataFileReader())
            {
                fr.Seek(index.ChunkOffset, SeekOrigin.Begin);
                fr.Read(data, 0, data.Length);
            }
            return data;
        }
Exemplo n.º 4
0
        public uint GetLastIndex(out LogIndex index)
        {
            if (_logLength == 0)
            {
                index = new LogIndex() { Type = 0, ChunkOffset = 0, ChunkSize = 0, Term = 0 };
                return 0;
            }

            index = _logIndices[_logLength - 1];
            return _logLength;
        }
Exemplo n.º 5
0
        public bool GetIndex(uint key, out LogIndex index)
        {
            if (key < 1 || key > _logLength)
            {
                index = new LogIndex() { Type = 0, ChunkOffset = 0, ChunkSize = 0, Term = 0 };
                return false;
            }

            index = _logIndices[key - 1];
            return true;
        }
Exemplo n.º 6
0
 public static bool AreEqual(LogIndex left, LogIndex right)
 {
     return left.Term == right.Term &&
         left.Type == right.Type &&
         left.ChunkOffset == right.ChunkOffset &&
         left.ChunkSize == right.ChunkSize &&
         left.Flag1 == right.Flag1 &&
         left.Flag2 == right.Flag2 &&
         left.Flag3 == right.Flag3 &&
         left.Flag4 == right.Flag4;
 }