diff --git a/src/core/Akka.Persistence/Snapshot/SnapshotStore.cs b/src/core/Akka.Persistence/Snapshot/SnapshotStore.cs index fbd0693e652..242e6b073e1 100644 --- a/src/core/Akka.Persistence/Snapshot/SnapshotStore.cs +++ b/src/core/Akka.Persistence/Snapshot/SnapshotStore.cs @@ -8,6 +8,7 @@ using System; using System.Threading.Tasks; using Akka.Actor; +using Akka.Event; using Akka.Pattern; namespace Akka.Persistence.Snapshot @@ -20,6 +21,8 @@ public abstract class SnapshotStore : ActorBase private readonly TaskContinuationOptions _continuationOptions = TaskContinuationOptions.ExecuteSynchronously; private readonly bool _publish; private readonly CircuitBreaker _breaker; + private readonly ILoggingAdapter _log; + private readonly bool _debugEnabled; /// /// Initializes a new instance of the class. @@ -43,6 +46,9 @@ protected SnapshotStore() config.GetInt("circuit-breaker.max-failures", 10), config.GetTimeSpan("circuit-breaker.call-timeout", TimeSpan.FromSeconds(10)), config.GetTimeSpan("circuit-breaker.reset-timeout", TimeSpan.FromSeconds(30))); + + _debugEnabled = config.GetBoolean("debug"); + _log = Context.GetLogger(); } /// @@ -59,6 +65,8 @@ private bool ReceiveSnapshotStore(object message) switch (message) { case LoadSnapshot loadSnapshot: + if(_debugEnabled) + _log.Info($"{nameof(LoadSnapshot)} message received."); LoadSnapshotAsync(loadSnapshot, self, senderPersistentActor); break; @@ -214,9 +222,20 @@ private async Task LoadSnapshotAsync(LoadSnapshot loadSnapshot, IActorRef self, { try { + if(_debugEnabled) + _log.Info($"Starting {nameof(LoadSnapshotAsync)} circuit breaker."); + var result = await _breaker.WithCircuitBreaker((msg: loadSnapshot, ss: this), - state => state.ss.LoadAsync(state.msg.PersistenceId, - state.msg.Criteria.Limit(state.msg.ToSequenceNr))); + state => + { + if(_debugEnabled) + _log.Info($"Invoking {nameof(LoadAsync)} inside circuit breaker."); + + return state.ss.LoadAsync(state.msg.PersistenceId, state.msg.Criteria.Limit(state.msg.ToSequenceNr)); + }); + + if(_debugEnabled) + _log.Info($"{nameof(LoadSnapshotAsync)} circuit breaker completed."); senderPersistentActor.Tell(new LoadSnapshotResult(result, loadSnapshot.ToSequenceNr), self); }