!per #3631 Snapshotting
- capture and save snapshots of processor state - start processor recovery from saved snapshots - snapshot storage on local filesystem - snapshot store completely isolated from journal - LevelDB journal modularized (and completely re-rwritten) - In-memory journal removed
This commit is contained in:
parent
c55189f615
commit
842ac672f7
34 changed files with 1348 additions and 477 deletions
|
|
@ -1,16 +1,20 @@
|
|||
package docs.persistence
|
||||
|
||||
import akka.actor.ActorSystem
|
||||
import akka.persistence.{ Recover, Persistent, Processor }
|
||||
import akka.testkit.{ ImplicitSender, AkkaSpec }
|
||||
import akka.persistence._
|
||||
import akka.persistence.SaveSnapshotSucceeded
|
||||
import scala.Some
|
||||
|
||||
trait PersistenceDocSpec {
|
||||
val system: ActorSystem
|
||||
val config =
|
||||
"""
|
||||
//#config
|
||||
//#journal-config
|
||||
akka.persistence.journal.leveldb.dir = "target/journal"
|
||||
//#config
|
||||
//#journal-config
|
||||
//#snapshot-config
|
||||
akka.persistence.snapshot-store.local.dir = "target/snapshots"
|
||||
//#snapshot-config
|
||||
"""
|
||||
|
||||
import system._
|
||||
|
|
@ -63,7 +67,7 @@ trait PersistenceDocSpec {
|
|||
//#deletion
|
||||
override def preRestart(reason: Throwable, message: Option[Any]) {
|
||||
message match {
|
||||
case Some(p: Persistent) ⇒ delete(p)
|
||||
case Some(p: Persistent) ⇒ deleteMessage(p)
|
||||
case _ ⇒
|
||||
}
|
||||
super.preRestart(reason, message)
|
||||
|
|
@ -184,4 +188,41 @@ trait PersistenceDocSpec {
|
|||
}
|
||||
//#fsm-example
|
||||
}
|
||||
|
||||
new AnyRef {
|
||||
//#save-snapshot
|
||||
class MyProcessor extends Processor {
|
||||
var state: Any = _
|
||||
|
||||
def receive = {
|
||||
case "snap" ⇒ saveSnapshot(state)
|
||||
case SaveSnapshotSucceeded(metadata) ⇒ // ...
|
||||
case SaveSnapshotFailed(metadata, reason) ⇒ // ...
|
||||
}
|
||||
}
|
||||
//#save-snapshot
|
||||
}
|
||||
|
||||
new AnyRef {
|
||||
//#snapshot-offer
|
||||
class MyProcessor extends Processor {
|
||||
var state: Any = _
|
||||
|
||||
def receive = {
|
||||
case SnapshotOffer(metadata, offeredSnapshot) ⇒ state = offeredSnapshot
|
||||
case Persistent(payload, sequenceNr) ⇒ // ...
|
||||
}
|
||||
}
|
||||
//#snapshot-offer
|
||||
|
||||
import akka.actor.Props
|
||||
|
||||
val processor = system.actorOf(Props[MyProcessor])
|
||||
|
||||
//#snapshot-criteria
|
||||
processor ! Recover(fromSnapshot = SnapshotSelectionCriteria(
|
||||
maxSequenceNr = 457L,
|
||||
maxTimestamp = System.currentTimeMillis))
|
||||
//#snapshot-criteria
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue