Пример #1
0
        public void CanProperlySnapshot()
        {
            using (var state = new PersistentState("self", StorageEnvironmentOptions.CreateMemoryOnly(), CancellationToken.None)
            {
                CommandSerializer = new JsonCommandSerializer()
            })
            {
                state.UpdateTermTo(null, 1);
                state.AppendToLeaderLog(new NopCommand());
                for (int i = 0; i < 5; i++)
                {
                    state.AppendToLeaderLog(new DictionaryCommand.Set
                    {
                        Key   = i.ToString(),
                        Value = i
                    });
                }

                state.MarkSnapshotFor(6, 1, 5);

                state.AppendToLeaderLog(new DictionaryCommand.Set
                {
                    Key   = "1",
                    Value = 4
                });

                var lastLogEntry = state.LastLogEntry();

                Assert.Equal(7, lastLogEntry.Index);
            }
        }
Пример #2
0
        internal bool LogIsUpToDate(long lastLogTerm, long lastLogIndex)
        {
            // Raft paper 5.4.1
            var lastLogEntry = PersistentState.LastLogEntry();

            if (lastLogEntry.Term < lastLogTerm)
            {
                return(true);
            }
            return(lastLogEntry.Index <= lastLogIndex);
        }