Download Elephant User Manual - Common
Transcript
76 Elephant User Manual "Register a standard object. Not recorded until the snapshot function is called on db" (aif (lookup-cached-id object set) (values object it) (let ((id (incf (snapshot-set-next-id set)))) (cache-snapshot-object id object set) (values object id)))) (defun lookup-cached-id (obj set) (gethash obj (snapshot-set-cache set))) (defun cache-snapshot-object (id obj set) (setf (gethash obj (snapshot-set-cache set)) id)) A parallel function registers hash tables. One very important invariant implied here is that the cache always contains objects that are eq and mapped back to a serialized object in the backing btree. There is no need, however, to immediately write objects to the store and this gives us some transactional properties: snapshots are atomic, consistent and durable. Isolation is not enforced by snapshots. This means that the transient cache has to be valid immediately after the snapshot set is loaded from the data store. (defmethod initialize-instance :after ((set snapshot-set) &key lazy-load &allow-other-k (unless lazy-load (restore set))) This also has consequences for unregistration. Removing a root object should also result in the removal of all objects that are unreachable from other roots. However, since side effects are not permanent until a snapshot operation, we merely have to garbage collect id’s that were not touched during a snapshot operation. This makes unregistration simple. (defmethod unregister-object (object (set snapshot-set)) "Drops the object from the cache and backing store" (let ((id (gethash object (snapshot-set-cache set)))) (when (null id) (error "Object ~A not registered in ~A" object set)) (drop-cached-object object set))) But snapshots are a little bit more work. (defmethod snapshot ((set snapshot-set)) "Saves all objects in the set (and any objects reachable from the current set of objects) to the persistent store" (with-transaction (:store-controller (get-con (snapshot-set-index set))) (loop for (obj . id) in (get-cache-entries (snapshot-set-cache set)) do (save-snapshot-object id obj set)) (collect-untouched set))) (defun save-snapshot-object (id obj set)