Exemplo n.º 1
0
        public void Send(JsonOperationContext context, InstallSnapshot installSnapshot)
        {
            if (_log.IsInfoEnabled)
            {
                _log.Info($"Install snapshot on: ({installSnapshot.LastIncludedIndex:#,#;;0} / {installSnapshot.LastIncludedTerm:#,#;;0})");
            }

            Send(context, new DynamicJsonValue
            {
                ["Type"] = nameof(InstallSnapshot),
                [nameof(InstallSnapshot.LastIncludedIndex)] = installSnapshot.LastIncludedIndex,
                [nameof(InstallSnapshot.LastIncludedTerm)]  = installSnapshot.LastIncludedTerm,
                [nameof(InstallSnapshot.Topology)]          = installSnapshot.Topology
            });
        }
Exemplo n.º 2
0
        public InstallSnapshotResponse InstallSnapshotHandler(InstallSnapshot request)
        {
            if (request.Term < _nodeStorage.CurrentTerm)
            {
                return(new InstallSnapshotResponse()
                {
                    IsSuccessful = false,
                    Term = request.Term
                });
            }
            lock (commitLock)
            {
                var snapshotInstallResult = _snapshotService.InstallSnapshot(request.Snapshot, request.LastIncludedIndex, request.LastIncludedTerm);

                return(new InstallSnapshotResponse()
                {
                    IsSuccessful = snapshotInstallResult,
                    Term = request.Term
                });
            }
        }