Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow persisting events when recovery has completed #21893

Merged
merged 3 commits into from
Dec 14, 2016

Conversation

ortibazar
Copy link
Contributor

Refs #21736

@akka-ci
Copy link

akka-ci commented Nov 24, 2016

Can one of the repo owners verify this patch?

else {
changeState(processingCommands)
internalStash.unstashAll()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, that makes sense

class PersistInRecovery(name: String) extends ExamplePersistentActor(name) {
override def receiveRecover = super.receiveRecover orElse {
case RecoveryCompleted ⇒
persist(Evt(RecoveryCompleted))(updateState)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if persist is done when processing events in receiveRecover, i.e. not only when RecoveryCompleted?

class PersistInRecovery(name: String) extends ExamplePersistentActor(name) {
override def receiveRecover = super.receiveRecover orElse {
case RecoveryCompleted ⇒
persist(Evt(RecoveryCompleted))(updateState)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would also be interesting with a test that is using persistAsync from receiveRecover

Copy link
Member

@patriknw patriknw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -43,7 +43,7 @@ trait AsyncWriteJournal extends Actor with WriteJournalBase with AsyncRecovery {
case "fail" ⇒ ReplayFilter.Fail
case "warn" ⇒ ReplayFilter.Warn
case other ⇒ throw new IllegalArgumentException(
s"invalid replay-filter.mode [$other], supported values [off, repair, fail, warn]")
s"invalid replay-filter.mode [$other], supported values [off, repair-by-discard-old, fail, warn]")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

@patriknw
Copy link
Member

patriknw commented Dec 6, 2016

OK TO TEST

@akka-ci akka-ci added validating PR is currently being validated by Jenkins tested PR that was successfully built and tested by Jenkins and removed validating PR is currently being validated by Jenkins labels Dec 6, 2016
@akka-ci
Copy link

akka-ci commented Dec 6, 2016

Test PASSed.

@@ -316,6 +316,7 @@ private[persistence] trait Eventsourced extends Snapshotter with PersistenceStas
* @param handler handler for each persisted `event`
*/
def persist[A](event: A)(handler: A ⇒ Unit): Unit = {
if (recoveryRunning) throw new IllegalStateException("Cannot persist event during recovery")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't the whole point to be able to persist events during recovery? I am confused here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I too cannot get this to match the name of the PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR adds support for persisting when recovery is completed, before any commands are received. It's still not possible to persist new events when replaying events. Replaying events should typically be free of external side effects so it doesn't make much sense to support persisting during the actual replay, but there might be some use cases for doing it right afterwards.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that "Cannot persist event during recovery" message is not descriptive. Could you suggest suitable one?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot persist during replay. Events can be persisted when receiving RecoveryCompleted or later.

expectMsg(List("a-1", "a-2", "rc-1", "rc-2", "rc-3", "invalid"))
watch(persistentActor)
persistentActor ! "boom"
expectTerminated(persistentActor)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it is actually fail-fast on persist during recovery, but allow it in RecoveryCompleted?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

@johanandren johanandren changed the title be able to persist events that happen during recovery Allow persisting events when recovery has completed Dec 13, 2016
Copy link
Member

@johanandren johanandren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@akka-ci akka-ci added validating PR is currently being validated by Jenkins tested PR that was successfully built and tested by Jenkins and removed tested PR that was successfully built and tested by Jenkins labels Dec 13, 2016
@akka-ci
Copy link

akka-ci commented Dec 13, 2016

Test PASSed.

@akka-ci akka-ci removed the validating PR is currently being validated by Jenkins label Dec 13, 2016
@ktoso
Copy link
Member

ktoso commented Dec 14, 2016

LGTM, thanks - nice improvement!

@ktoso ktoso merged commit ef1e0e0 into akka:master Dec 14, 2016
@ortibazar ortibazar deleted the wip-21736-persistence branch December 14, 2016 12:44
patriknw pushed a commit that referenced this pull request Feb 21, 2017
* be able to persist events that happen during recovery, #21736

* prohibit persiting events during recovery, #21736

* change error message #21736

(cherry picked from commit ef1e0e0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tested PR that was successfully built and tested by Jenkins
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants