Skip to content

Persistence: persist() does not stash when invoked while handling RecoveryCompleted #21736

@jypma

Description

@jypma

I have a PersistentActor that wants to self-initialize like such:

    @Override
    public PartialFunction<Object, BoxedUnit> receiveRecover() {
        return ReceiveBuilder
            .match(RecoveryCompleted.class, msg -> {
                if (lastSequenceNr() == 0) {
                    persist(createInitialEvent(), e -> {
                        updateSomeState();
                    });
                }
            })
            .build()
            .orElse(super.receiveRecover());
    }

However, incoming commands aren't stashed between persisting the createInitialEvent() and getting the callback to updateSomeState() (which does happen eventually, I think as the next command is handled).

In EventSourcing.scala, the reason is that the detecting of pendingStashingPersistInvocations isn't performed until the state reaches processingCommands. Perhaps a well-placed changeState(persistingEvents) inside recoveryStarted(...) or recovering(...) could make it work.

Otherwise, blow up if persist() is invoked during receiveRecover.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedIssues that the core team will likely not have time to work ont:persistence

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions