Пример #1
0
 public bool InstallSnapshot(object snapshot, int lastIncludedIndex, int lastIncludedTerm)
 {
     if (_nodeStorage.GetTotalLogCount() < lastIncludedIndex)
     {
         _logger.LogInformation("Installing snapshot...");
         _nodeStorage.SetLastSnapshot(((JObject)snapshot).ToObject <State>(), lastIncludedIndex, lastIncludedTerm);
         _stateMachine.ApplySnapshotToStateMachine(((JObject)snapshot).ToObject <State>());
         _nodeStateService.CommitIndex = lastIncludedIndex;
         _nodeStorage.SetCurrentTerm(lastIncludedTerm);
     }
     return(true);
 }
Пример #2
0
        public Bootstrapper(ILogger <Bootstrapper <State> > logger,
                            ClusterOptions clusterOptions,
                            NodeOptions nodeOptions,
                            INodeStorage <State> nodeStorage,
                            IStateMachine <State> stateMachine,
                            NodeStateService nodeStateService)
        {
            _nodeStorage = nodeStorage;
            Logger       = logger;

            //Load the last snapshot
            if (_nodeStorage.LastSnapshot != null)
            {
                Logger.LogInformation("Detected snapshot, loading snapshot into state.");
                stateMachine.ApplySnapshotToStateMachine(_nodeStorage.LastSnapshot);
                nodeStateService.CommitIndex = _nodeStorage.LastSnapshotIncludedIndex;
                _nodeStorage.SetCurrentTerm(_nodeStorage.LastSnapshotIncludedTerm);
                nodeStateService.Id = _nodeStorage.Id;
            }
        }