Example #1
0
        public override void Handle(CanInstallSnapshotResponse resp)
        {
            if (FromOurTopology(resp) == false)
            {
                _log.Info("Got an append entries response message outside my cluster topology (id: {0}), ignoring", resp.ClusterTopologyId);
                return;
            }

            Task snapshotInstallationTask;
            if (resp.Success == false)
            {
                _log.Debug("Received CanInstallSnapshotResponse(Success=false) from {0}, Term = {1}, Index = {2}, updating and will try again",
                    resp.From,
                    resp.Term,
                    resp.Index);
                _matchIndexes[resp.From] = resp.Index;
                _nextIndexes[resp.From] = resp.Index + 1;
                _lastContact[resp.From] = DateTime.UtcNow;
                _snapshotsPendingInstallation.TryRemove(resp.From, out snapshotInstallationTask);
                return;
            }
            if (resp.IsCurrentlyInstalling)
            {
                _log.Debug("Received CanInstallSnapshotResponse(IsCurrentlyInstalling=false) from {0}, Term = {1}, Index = {2}, will retry when it is done",
                    resp.From,
                    resp.Term,
                    resp.Index);

                _snapshotsPendingInstallation.TryRemove(resp.From, out snapshotInstallationTask);
                return;
            }
            _log.Debug("Received CanInstallSnapshotResponse from {0}, starting snapshot streaming task", resp.From);

            // problem, we can't just send the log entries, we have to send
            // the full snapshot to this destination, this can take a very long
            // time for large data sets. Because of that, we are doing that in a
            // background thread, and while we are doing that, we aren't going to be
            // doing any communication with this peer. Note that while the peer
            // is accepting the snapshot, it isn't counting the heartbeat timer, or
            // can move to become a candidate.
            // During normal operations, we will never be using this, since we leave a buffer
            // in place (by default roughly 4K entries) to make sure that small disconnects will
            // not cause us to be forced to send a snapshot over the wire.

            if (_snapshotsPendingInstallation.ContainsKey(resp.From))
                return; // already sending

            var nodeConnectionInfo = Engine.CurrentTopology.GetNodeByName(resp.From);
            if (nodeConnectionInfo == null)
            {
                _log.Info("Got CanInstallSnapshotResponse for {0}, but it isn't in our topology, ignoring", resp.From);
                return;
            }

            var task = new Task(() => SendSnapshotToPeer(nodeConnectionInfo));
            task.ContinueWith(_ => _snapshotsPendingInstallation.TryRemove(resp.From, out _));

            if (_snapshotsPendingInstallation.TryAdd(resp.From, task))
                task.Start();
        }
Example #2
0
 public abstract void Reply(CanInstallSnapshotResponse resp);
Example #3
0
			public override void Reply(CanInstallSnapshotResponse resp)
			{
				Reply(resp.Success, resp);	
			}
		public virtual void Handle(CanInstallSnapshotResponse resp)
		{
			//irrelevant here, so doing nothing (used only in LeaderStateBehavior)
		}