Next: Persistence environments, Previous: Operations on actormaps, Up: Persistence [Contents][Index]
When a vat is spawned, it can be spawned as a persistent vat with a given persistence environment and set of roots. The vat also has a storage provider associated with it. Vats can be persisted either on each churn (when the vat reaches quiescence), or manually. If a vat is configured to persist on churns, just the objects which have changed (using become) will be persisted.
[#:log-capacity] [#:persistence-registry] [#:version] [#:upgrade]
Create and return a reference to a new vat configured with persistence.
'churn will persist on churns, otherwise
in a manual persistence mode (default: 'churn).
spawn-fibrous-vat.
#t, log vat events; otherwise, do not.
0 when no version is specified.
The migrations macro is generally what would be expected to be
used for the upgrade procedure
(define-actor (^counter bcom value) (lambda () (bcom (^counter bcom (+ 1 value)) value))) (define persistence-env (make-persistence-env `((((counter) ^counter) ,^counter)))) (define-values (vat my-counter) (spawn-persistent-vat persistence-env (lambda () (spawn ^counter 0)) (make-memory-store)))
The ^persistence-registry actor is designed to be spawned anew
each time the program starts (i.e. is not part of the persistence
graph) and is shared amongst several persistent vats which want to
persist/rehydrate objects across vats.
Unlike local near refrs which are promises during rehydration, but are swapped
to local refrs after rehydration is complete, Far refrs remain promises and
should resolve after both vats are setup and have registered themselves with
the ^persistence-registry object.
Here’s an example of two vats, the cell on b-vat holds a reference to
an object on a-vat
;; Spawn the persistence registry in its own vat without persistence enabled. (define persistence-registry (with-vat (spawn-vat) (spawn ^persistence-registry))) ;; Spawn the initial a-vat with an a-cell object (define a-vat-store (make-memory-store)) (define-values (a-vat a-cell) (spawn-persistent-vat cell-env (lambda () (spawn ^cell)) a-vat-store #:persistence-registry persistence-registry)) ;; Spawn a b-vat with a b-cell object, that will reference the far refr a-cell. (define b-vat-store (make-memory-store)) (define-values (b-vat b-cell) (spawn-persistent-vat cell-env (lambda () (spawn ^cell a-cell)) b-vat-store #:persistence-registry persistence-registry)) ;; Let go of our persistence registry reference so it can be garbage collected. (set! persistence-registry #f)
The persistence registry builds a map of strong references to all the
references within a vat. This ensures references only held by far vats
are kept around until all the vats are spawned. A consequence of this
design is that if the reference to the persistence registry is kept
around, the initial graph of actors in vats can never be garbage
collected. Thus, it’s important to let go of the reference to the
^persistence-registry actor once all the vats which need it have
been spawned.
Next: Persistence environments, Previous: Operations on actormaps, Up: Persistence [Contents][Index]