Re: [akka-user] Need of `onRecoveryCompleted` in akka typed for persistence

2017-11-06 Thread Alexandr Sova
Maybe in that case you still shouldn't make any "validation" or something else at applyEvent. Look at event adapters - it should solve your "renaming missing entry" case and similar cases. Events are much like

Re: [akka-user] Need of `onRecoveryCompleted` in akka typed for persistence

2017-10-27 Thread Patrik Nordwall
On Fri, Oct 27, 2017 at 12:19 PM, Yaroslav Klymko wrote: > Sure, > > But then I won't see the potential problems that during recovery for > instance we are renaming missing entry. > With ongoing development and more complicated data structures, when you > might have tens

Re: [akka-user] Need of `onRecoveryCompleted` in akka typed for persistence

2017-10-27 Thread Yaroslav Klymko
Sure, But then I won't see the potential problems that during recovery for instance we are renaming missing entry. With ongoing development and more complicated data structures, when you might have tens nesting deep it is becoming crucial to validate recovery against previous versions and to

Re: [akka-user] Need of `onRecoveryCompleted` in akka typed for persistence

2017-10-27 Thread Patrik Nordwall
You can rewrite that to: case class State(entries: Map[String, Entry]) { def applyEvent(event: Event): State = { event match { case Event.EntryAdded(id, name) => copy(entries + (id -> Entry(name))) case Event.EntryRenamed(id, newName) =>

Re: [akka-user] Need of `onRecoveryCompleted` in akka typed for persistence

2017-10-27 Thread Yaroslav Klymko
Hi Patrik, here is very simplified example: object Example { case class Entry(name: String) case class State(entries: Map[String, Entry]) { def applyEvent(event: Event): Either[String, State] = { event match { case Event.EntryAdded(id, name) => entries.get(id)

Re: [akka-user] Need of `onRecoveryCompleted` in akka typed for persistence

2017-10-27 Thread Patrik Nordwall
On Fri, Oct 20, 2017 at 5:29 PM, Yaroslav Klymko wrote: > > On Friday, October 20, 2017 at 4:44:35 PM UTC+2, Patrik Nordwall wrote: >> >> >> >> On Thu, Oct 19, 2017 at 2:52 PM, Yaroslav Klymko >> wrote: >> >>> >>> >>> >>> On Thursday, October 19, 2017 at

Re: [akka-user] Need of `onRecoveryCompleted` in akka typed for persistence

2017-10-20 Thread Yaroslav Klymko
On Friday, October 20, 2017 at 4:44:35 PM UTC+2, Patrik Nordwall wrote: > > > > On Thu, Oct 19, 2017 at 2:52 PM, Yaroslav Klymko > wrote: > >> >> >> >> On Thursday, October 19, 2017 at 9:33:59 PM UTC+2, Patrik Nordwall wrote: >>> >>> Invalid events must not be stored, because

Re: [akka-user] Need of `onRecoveryCompleted` in akka typed for persistence

2017-10-20 Thread Patrik Nordwall
On Thu, Oct 19, 2017 at 2:52 PM, Yaroslav Klymko wrote: > > > > On Thursday, October 19, 2017 at 9:33:59 PM UTC+2, Patrik Nordwall wrote: >> >> Invalid events must not be stored, because then the actor will not be >> able to recover after a restart (later startup). Validation

Re: [akka-user] Need of `onRecoveryCompleted` in akka typed for persistence

2017-10-19 Thread Yaroslav Klymko
On Thursday, October 19, 2017 at 9:33:59 PM UTC+2, Patrik Nordwall wrote: > > Invalid events must not be stored, because then the actor will not be able > to recover after a restart (later startup). Validation should typically be > done by validating the incoming command before persisting the

Re: [akka-user] Need of `onRecoveryCompleted` in akka typed for persistence

2017-10-19 Thread Patrik Nordwall
Invalid events must not be stored, because then the actor will not be able to recover after a restart (later startup). Validation should typically be done by validating the incoming command before persisting the event. Validation should not be placed in applyEvent, but as an additional protection

Re: [akka-user] Need of `onRecoveryCompleted` in akka typed for persistence

2017-10-19 Thread Yaroslav Klymko
I also have other concern regarding. case PersistAll(events) ⇒ // apply the event before persist so that validation exception is handled before persisting // the invalid event, in case such validation is implemented in the event handler. state = events.foldLeft(state)(applyEvent)

Re: [akka-user] Need of `onRecoveryCompleted` in akka typed for persistence

2017-10-18 Thread Yaroslav Klymko
I think renaming actions: State => Actions[Command, Event, State] to onRecoveryCompleted: State => Actions[Command, Event, State] Makes it really clear. Also you might just decide to stop the actor in case the state is wrong, etc. On Wednesday, October 18, 2017 at 10:22:12 PM

Re: [akka-user] Need of `onRecoveryCompleted` in akka typed for persistence

2017-10-18 Thread Patrik Nordwall
Do you suggest something like this? def immutable[Command, Event, State]( persistenceId: String, initialState: State, actions: State => Actions[Command, Event, State], applyEvent:(Event, State) ⇒ State): PersistentBehavior[Command, Event, State] I it would be rather

[akka-user] Need of `onRecoveryCompleted` in akka typed for persistence

2017-10-18 Thread Yaroslav Klymko
Hi guys, Not sure this is the right place to ask: I'm looking into akka typed for persistence and wondering whether we really need onRecoveryCompleted at https://github.com/akka/akka/blob/master/akka-typed/src/main/scala/akka/typed/persistence/scaladsl/PersistentActor.scala#L174 Why not just