Ejemplo n.º 1
0
        private void HandleReplayMessages(ReplayMessages message)
        {
            var context = Context;

            // Send replayed messages and replay result to persistentActor directly. No need
            // to resequence replayed messages relative to written and looped messages.
            ReplayMessagesAsync(message.PersistenceId, message.FromSequenceNr, message.ToSequenceNr, message.Max, p =>
            {
                if (!p.IsDeleted || message.ReplayDeleted)
                {
                    foreach (var adaptedRepresentation in AdaptFromJournal(p))
                    {
                        message.PersistentActor.Tell(new ReplayedMessage(adaptedRepresentation), p.Sender);
                    }
                }
            })
            .NotifyAboutReplayCompletion(message.PersistentActor)
            .ContinueWith(t =>
            {
                if (!t.IsFaulted && CanPublish)
                {
                    context.System.EventStream.Publish(message);
                }
            }, _continuationOptions);
        }
Ejemplo n.º 2
0
 private void HandleReplayMessages(ReplayMessages msg)
 {
     ReplayMessagesAsync(msg.PersistenceId, msg.FromSequenceNr, msg.ToSequenceNr, msg.Max, persistent =>
     {
         if (!persistent.IsDeleted || msg.ReplayDeleted) msg.PersistentActor.Tell(new ReplayedMessage(persistent), persistent.Sender);
     })
     .NotifyAboutReplayCompletion(msg.PersistentActor)
     .ContinueWith(t =>
     {
         if (!t.IsFaulted && CanPublish) Context.System.EventStream.Publish(msg);
     });
 }
Ejemplo n.º 3
0
 private void HandleReplayMessages(ReplayMessages message)
 {
     // Send replayed messages and replay result to persistentActor directly. No need
     // to resequence replayed messages relative to written and looped messages.
     ReplayMessagesAsync(message.PersistenceId, message.FromSequenceNr, message.ToSequenceNr, message.Max, p =>
     {
         if (!p.IsDeleted || message.ReplayDeleted) message.PersistentActor.Tell(new ReplayedMessage(p), p.Sender);
     })
     .NotifyAboutReplayCompletion(message.PersistentActor)
     .ContinueWith(t =>
     {
         if(!t.IsFaulted && CanPublish) Context.System.EventStream.Publish(message);
     }, _continuationOptions);
 }
        protected override async Task HandleReplayMessages(ReplayMessages req, OracleCommand command, IActorContext context)
        {
            var replaySettings = Setup.ReplayFilterSettings;
            var replyTo        = replaySettings.IsEnabled
                ? context.ActorOf(ReplayFilter.Props(req.PersistentActor, replaySettings.Mode, replaySettings.WindowSize, replaySettings.MaxOldWriters, replaySettings.IsDebug))
                : req.PersistentActor;
            var persistenceId = req.PersistenceId;

            NotifyNewPersistenceIdAdded(persistenceId);

            try
            {
                var highestSequenceNr = await ReadHighestSequenceNr(persistenceId, command);

                var toSequenceNr = Math.Min(req.ToSequenceNr, highestSequenceNr);

                command.CommandText = ByPersistenceIdSql;
                command.Parameters.Clear();

                AddParameter(command, ":PersistenceId", OracleDbType.NVarchar2, persistenceId);
                AddParameter(command, ":FromSequenceNr", OracleDbType.Int64, req.FromSequenceNr);
                AddParameter(command, ":ToSequenceNr", OracleDbType.Int64, toSequenceNr);

                using (var reader = await command.ExecuteReaderAsync())
                {
                    var i = 0L;
                    while (i++ < req.Max && await reader.ReadAsync())
                    {
                        var persistent = ReadEvent(reader);
                        if (persistent.IsDeleted)
                        {
                            continue;
                        }

                        foreach (var adaptedRepresentation in AdaptFromJournal(persistent))
                        {
                            replyTo.Tell(new ReplayedMessage(adaptedRepresentation), ActorRefs.NoSender);
                        }
                    }
                }

                var response = new RecoverySuccess(highestSequenceNr);
                replyTo.Tell(response, ActorRefs.NoSender);
            }
            catch (Exception cause)
            {
                var response = new ReplayMessagesFailure(cause);
                replyTo.Tell(response, ActorRefs.NoSender);
            }
        }
Ejemplo n.º 5
0
        protected IEnumerable <object> LoadFromJournal(string persistenceId, int expectedCount)
        {
            var persistenceExtension = Akka.Persistence.Persistence.Instance.Get(GridNode.System) ?? Akka.Persistence.Persistence.Instance.Apply(GridNode.System);
            var settings             = persistenceExtension.Settings;
            var journal = persistenceExtension.JournalFor(null);

            var loadMsg = new ReplayMessages(0, long.MaxValue, long.MaxValue, persistenceId, TestActor);

            journal.Tell(loadMsg);

            for (int i = 0; i < expectedCount; i++)
            {
                yield return(FishForMessage <ReplayedMessage>(m => m.Persistent.PersistenceId == persistenceId).Persistent.Payload);
            }
        }
Ejemplo n.º 6
0
 private void HandleReplayMessages(ReplayMessages msg)
 {
     ReplayMessagesAsync(msg.PersistenceId, msg.FromSequenceNr, msg.ToSequenceNr, msg.Max, persistent =>
     {
         if (!persistent.IsDeleted || msg.ReplayDeleted)
         {
             msg.PersistentActor.Tell(new ReplayedMessage(persistent), persistent.Sender);
         }
     })
     .NotifyAboutReplayCompletion(msg.PersistentActor)
     .ContinueWith(t =>
     {
         if (!t.IsFaulted && CanPublish)
         {
             Context.System.EventStream.Publish(msg);
         }
     });
 }
Ejemplo n.º 7
0
 private void HandleReplayMessages(ReplayMessages msg)
 {
     var context = Context;
     var sender = Sender;
     ReplayMessagesAsync(msg.PersistenceId, msg.FromSequenceNr, msg.ToSequenceNr, msg.Max, persistent =>
     {
         if (!persistent.IsDeleted || msg.ReplayDeleted)
         {
             foreach (var adapterRepresentation in AdaptFromJournal(persistent))
             {
                 msg.PersistentActor.Tell(new ReplayedMessage(adapterRepresentation), sender);
             }
         }
     })
     .NotifyAboutReplayCompletion(msg.PersistentActor)
     .ContinueWith(t =>
     {
         if (!t.IsFaulted && CanPublish) context.System.EventStream.Publish(msg);
     });
 }
Ejemplo n.º 8
0
        private void HandleReplayMessages(ReplayMessages msg)
        {
            var context = Context;
            var sender  = Sender;

            ReplayMessagesAsync(msg.PersistenceId, msg.FromSequenceNr, msg.ToSequenceNr, msg.Max, persistent =>
            {
                if (!persistent.IsDeleted || msg.ReplayDeleted)
                {
                    foreach (var adapterRepresentation in AdaptFromJournal(persistent))
                    {
                        msg.PersistentActor.Tell(new ReplayedMessage(adapterRepresentation), sender);
                    }
                }
            })
            .NotifyAboutReplayCompletion(msg.PersistentActor)
            .ContinueWith(t =>
            {
                if (!t.IsFaulted && CanPublish)
                {
                    context.System.EventStream.Publish(msg);
                }
            });
        }
Ejemplo n.º 9
0
 private void HandleReplayMessages(ReplayMessages message)
 {
     var replyTo = _isReplayFilterEnabled
         ? Context.ActorOf(ReplayFilter.Props(message.PersistentActor, _replayFilterMode, _replayFilterWindowSize,
             _replayFilterMaxOldWriters, _replayDebugEnabled))
         : message.PersistentActor;
     var context = Context;
     var readHighestSequenceNrFrom = Math.Max(0, message.FromSequenceNr - 1);
     var promise = new TaskCompletionSource<long>();
     _breaker
         .WithCircuitBreaker(() => ReadHighestSequenceNrAsync(message.PersistenceId, readHighestSequenceNrFrom))
         .ContinueWith(t =>
         {
             if (!t.IsFaulted && !t.IsCanceled)
             {
                 var highSequenceNr = t.Result;
                 var toSequenceNr = Math.Min(message.ToSequenceNr, highSequenceNr);
                 if (highSequenceNr == 0 || message.FromSequenceNr > toSequenceNr)
                 {
                     promise.SetResult(highSequenceNr);
                 }
                 else
                 {
                     // Send replayed messages and replay result to persistentActor directly. No need
                     // to resequence replayed messages relative to written and looped messages.
                     // not possible to use circuit breaker here
                     ReplayMessagesAsync(context, message.PersistenceId, message.FromSequenceNr, toSequenceNr,
                         message.Max, p =>
                         {
                             if (!p.IsDeleted) // old records from pre 1.5 may still have the IsDeleted flag
                             {
                                 foreach (var adaptedRepresentation in AdaptFromJournal(p))
                                 {
                                     replyTo.Tell(new ReplayedMessage(adaptedRepresentation), ActorRefs.NoSender);
                                 }
                             }
                         })
                         .ContinueWith(replayTask =>
                         {
                             if (!replayTask.IsFaulted && !replayTask.IsCanceled)
                                 promise.SetResult(highSequenceNr);
                             else
                                 promise.SetException(replayTask.IsFaulted
                                     ? TryUnwrapException(replayTask.Exception)
                                     : new OperationCanceledException(
                                         "ReplayMessagesAsync canceled, possibly due to timing out."));
                         }, _continuationOptions);
                 }
             }
             else
             {
                 promise.SetException(t.IsFaulted
                     ? TryUnwrapException(t.Exception)
                     : new OperationCanceledException(
                         "ReadHighestSequenceNrAsync canceled, possibly due to timing out."));
             }
         }, _continuationOptions);
     promise.Task
         .ContinueWith(t => !t.IsFaulted ? (object) new RecoverySuccess(t.Result) : new ReplayMessagesFailure(TryUnwrapException(t.Exception)), _continuationOptions)
         .PipeTo(replyTo)
         .ContinueWith(t =>
         {
             if (!t.IsFaulted && CanPublish) context.System.EventStream.Publish(message);
         }, _continuationOptions);
 }
Ejemplo n.º 10
0
        private void HandleReplayMessages(ReplayMessages message)
        {
            var replyTo = _isReplayFilterEnabled
                ? Context.ActorOf(ReplayFilter.Props(message.PersistentActor, _replayFilterMode, _replayFilterWindowSize,
                                                     _replayFilterMaxOldWriters, _replayDebugEnabled))
                : message.PersistentActor;
            var context = Context;
            var readHighestSequenceNrFrom = Math.Max(0, message.FromSequenceNr - 1);
            var promise = new TaskCompletionSource <long>();

            _breaker
            .WithCircuitBreaker(() => ReadHighestSequenceNrAsync(message.PersistenceId, readHighestSequenceNrFrom))
            .ContinueWith(t =>
            {
                if (!t.IsFaulted && !t.IsCanceled)
                {
                    var highSequenceNr = t.Result;
                    var toSequenceNr   = Math.Min(message.ToSequenceNr, highSequenceNr);
                    if (highSequenceNr == 0 || message.FromSequenceNr > toSequenceNr)
                    {
                        promise.SetResult(highSequenceNr);
                    }
                    else
                    {
                        // Send replayed messages and replay result to persistentActor directly. No need
                        // to resequence replayed messages relative to written and looped messages.
                        // not possible to use circuit breaker here
                        ReplayMessagesAsync(context, message.PersistenceId, message.FromSequenceNr, toSequenceNr,
                                            message.Max, p =>
                        {
                            if (!p.IsDeleted)         // old records from pre 1.5 may still have the IsDeleted flag
                            {
                                foreach (var adaptedRepresentation in AdaptFromJournal(p))
                                {
                                    replyTo.Tell(new ReplayedMessage(adaptedRepresentation), ActorRefs.NoSender);
                                }
                            }
                        })
                        .ContinueWith(replayTask =>
                        {
                            if (!replayTask.IsFaulted && !replayTask.IsCanceled)
                            {
                                promise.SetResult(highSequenceNr);
                            }
                            else
                            {
                                promise.SetException(replayTask.IsFaulted
                                            ? TryUnwrapException(replayTask.Exception)
                                            : new OperationCanceledException(
                                                         "ReplayMessagesAsync canceled, possibly due to timing out."));
                            }
                        }, _continuationOptions);
                    }
                }
                else
                {
                    promise.SetException(t.IsFaulted
                            ? TryUnwrapException(t.Exception)
                            : new OperationCanceledException(
                                             "ReadHighestSequenceNrAsync canceled, possibly due to timing out."));
                }
            }, _continuationOptions);
            promise.Task
            .ContinueWith(t => !t.IsFaulted ? (object)new RecoverySuccess(t.Result) : new ReplayMessagesFailure(TryUnwrapException(t.Exception)), _continuationOptions)
            .PipeTo(replyTo)
            .ContinueWith(t =>
            {
                if (!t.IsFaulted && CanPublish)
                {
                    context.System.EventStream.Publish(message);
                }
            }, _continuationOptions);
        }