Revision: 3935 Author: hans URL: http://bknr.net/trac/changeset/3935
Fix indentation
U branches/anon-transaction-fixes-2/bknr/datastore/src/data/tutorial.lisp
Modified: branches/anon-transaction-fixes-2/bknr/datastore/src/data/tutorial.lisp =================================================================== --- branches/anon-transaction-fixes-2/bknr/datastore/src/data/tutorial.lisp 2008-09-21 21:26:39 UTC (rev 3934) +++ branches/anon-transaction-fixes-2/bknr/datastore/src/data/tutorial.lisp 2008-09-22 08:06:08 UTC (rev 3935) @@ -131,17 +131,17 @@ (close-store) (make-instance 'tutorial-store :directory "/tmp/tutorial-store/" :subsystems nil) - ; Warning: restoring #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> - ; => #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> +; Warning: restoring #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> +; => #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/">
(tutorial-store-counter *store*) - ; => 0 +; => 0 (incf-counter) - ; => 1 +; => 1 (incf-counter) - ; => 2 +; => 2 (decf-counter) - ; => 1 +; => 1
;;; The three transactions have been logged to the transaction log in ;;; "/tmp/tutorial-store/", as we can see: @@ -149,13 +149,13 @@ (with-open-file (s "/tmp/tutorial-store/current/transaction-log" :direction :input) (file-length s)) - ; => 126 +; => 126 (incf-counter) - ; => 2 +; => 2 (with-open-file (s "/tmp/tutorial-store/current/transaction-log" :direction :input) (file-length s)) - ; => 168 +; => 168
;;; The transaction log is kept in a directory called "current", which ;;; is where the currently active version of the snapshots and log @@ -166,29 +166,29 @@ ;;; the persistent data (the counter value).
(snapshot) - ; => Error in function (METHOD SNAPSHOT-STORE NIL (STORE)): - ; => Cannot snapshot store without subsystems... - ; => [Condition of type SIMPLE-ERROR] +; => Error in function (METHOD SNAPSHOT-STORE NIL (STORE)): +; => Cannot snapshot store without subsystems... +; => [Condition of type SIMPLE-ERROR]
;;; We can close the store by using the function `CLOSE-STORE'. *store* - ; => #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> +; => #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> (close-store) - ; => NIL +; => NIL (boundp '*store*) - ; => NIL +; => NIL
;;; The store can then be recreated, and the transaction log will be ;;; read and executed upon restore. (make-instance 'tutorial-store :directory "/tmp/tutorial-store/" :subsystems nil)
- ; Warning: restoring #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> - ; Warning: loading transaction log - ; /tmp/tutorial-store/current/transaction-log - ; => #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> +; Warning: restoring #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> +; Warning: loading transaction log +; /tmp/tutorial-store/current/transaction-log +; => #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> (tutorial-store-counter *store*) - ; => 2 +; => 2
;;; The store can also be restored in a later LISP session. Make sure ;;; that all the code necessary to the execution of the transaction @@ -205,26 +205,26 @@ ;;; `UNTIL' argument of `RESTORE-STORE'.
(setf *store-debug* t) - ; => T +; => T (restore-store *store*) - ; restoring #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> - ; loading transaction log /tmp/tutorial-store/current/transaction-log - ; executing transaction #<TRANSACTION 21.04.2008 07:08:22 TX-INCF-COUNTER > at timestamp 3417743302 - ; executing transaction #<TRANSACTION 21.04.2008 07:08:25 TX-INCF-COUNTER > at timestamp 3417743305 - ; executing transaction #<TRANSACTION 21.04.2008 07:08:26 TX-DECF-COUNTER > at timestamp 3417743306 - ; executing transaction #<TRANSACTION 21.04.2008 07:08:34 TX-INCF-COUNTER > at timestamp 3417743314 - ; => NIL +; restoring #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> +; loading transaction log /tmp/tutorial-store/current/transaction-log +; executing transaction #<TRANSACTION 21.04.2008 07:08:22 TX-INCF-COUNTER > at timestamp 3417743302 +; executing transaction #<TRANSACTION 21.04.2008 07:08:25 TX-INCF-COUNTER > at timestamp 3417743305 +; executing transaction #<TRANSACTION 21.04.2008 07:08:26 TX-DECF-COUNTER > at timestamp 3417743306 +; executing transaction #<TRANSACTION 21.04.2008 07:08:34 TX-INCF-COUNTER > at timestamp 3417743314 +; => NIL (tutorial-store-counter *store*) - ; => 2 - ; !! Update the timestamp below to correspond to the fist transaction executed above !! +; => 2 +; !! Update the timestamp below to correspond to the fist transaction executed above !! (restore-store *store* :until 3417743302) ... - ; restoring #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> - ; loading transaction log /tmp/tutorial-store/current/transaction-log - ; executing transaction #<TRANSACTION 21.04.2008 07:08:22 TX-INCF-COUNTER > at timestamp 3417743302 - ; creating log file backup: /tmp/tutorial-store/current/transaction-log.backup - ; truncating transaction log at position 42. +; restoring #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> +; loading transaction log /tmp/tutorial-store/current/transaction-log +; executing transaction #<TRANSACTION 21.04.2008 07:08:22 TX-INCF-COUNTER > at timestamp 3417743302 +; creating log file backup: /tmp/tutorial-store/current/transaction-log.backup +; truncating transaction log at position 42. (tutorial-store-counter *store*) - ; => 1 +; => 1
;;;## Adding a subsystem
@@ -287,22 +287,22 @@ ;;; `COUNTER-SUBSYSTEM'.
(close-store) - ; => NIL +; => NIL (make-instance 'tutorial-store :directory "/tmp/tutorial-store/" :subsystems (list (make-instance 'counter-subsystem))) - ; Warning: restoring #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> - ; Warning: Could not find store counter value, setting to 0. - ; Warning: loading transaction log - ; /tmp/tutorial-store/current/transaction-log - ; => #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> +; Warning: restoring #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> +; Warning: Could not find store counter value, setting to 0. +; Warning: loading transaction log +; /tmp/tutorial-store/current/transaction-log +; => #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> (snapshot) - ; Snapshotting subsystem #<COUNTER-SUBSYSTEM #xE65F866> of #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> - ; Successfully snapshotted #<COUNTER-SUBSYSTEM #xE65F866> of #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> - ; => NIL +; Snapshotting subsystem #<COUNTER-SUBSYSTEM #xE65F866> of #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> +; Successfully snapshotted #<COUNTER-SUBSYSTEM #xE65F866> of #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> +; => NIL (restore) - ; restoring #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> - ; Restoring the subsystem #<COUNTER-SUBSYSTEM #xE65F866> of #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> - ; => NUL +; restoring #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> +; Restoring the subsystem #<COUNTER-SUBSYSTEM #xE65F866> of #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> +; => NUL
;;;# An object store example
@@ -340,11 +340,11 @@ :subsystems (list (make-instance 'store-object-subsystem)))
- ; Warning: restoring #<MP-STORE DIR: "/tmp/object-store/"> - ; restoring #<MP-STORE DIR: "/tmp/object-store/"> - ; Restoring the subsystem #<STORE-OBJECT-SUBSYSTEM #xE63F866> of #<MP-STORE DIR: "/tmp/object-store/"> +; Warning: restoring #<MP-STORE DIR: "/tmp/object-store/"> +; restoring #<MP-STORE DIR: "/tmp/object-store/"> +; Restoring the subsystem #<STORE-OBJECT-SUBSYSTEM #xE63F866> of #<MP-STORE DIR: "/tmp/object-store/"> (all-store-objects) - ; => NIL +; => NIL
;;; We can now create a few store objects (which is not very ;;; interesting in itself). Store objects have to be created inside a @@ -354,28 +354,28 @@ ;;; separate transaction.
(make-instance 'store-object) - ; => #<STORE-OBJECT ID: 0> +; => #<STORE-OBJECT ID: 0> (make-instance 'store-object) - ; => #<STORE-OBJECT ID: 1> +; => #<STORE-OBJECT ID: 1> (all-store-objects) - ; => (#<STORE-OBJECT ID: 0> #<STORE-OBJECT ID: 1>) +; => (#<STORE-OBJECT ID: 0> #<STORE-OBJECT ID: 1>) (all-store-classes) - ; => (STORE-OBJECT) +; => (STORE-OBJECT)
;;; Object deletion also has to be done through the transaction ;;; `DELETE-OBJECT', which will log the deletion of the object in the ;;; transaction log, and remove the object from all its indices.
(make-instance 'store-object) - ; executing transaction #<TRANSACTION 21.04.2008 08:02:10 MAKE-INSTANCE STORE-OBJECT ID 2> at timestamp 3417746530 - ; => #<STORE-OBJECT ID: 12> +; executing transaction #<TRANSACTION 21.04.2008 08:02:10 MAKE-INSTANCE STORE-OBJECT ID 2> at timestamp 3417746530 +; => #<STORE-OBJECT ID: 12> (store-object-with-id 2) - ; => #<STORE-OBJECT ID: 2> +; => #<STORE-OBJECT ID: 2> (delete-object (store-object-with-id 2)) - ; executing transaction #<TRANSACTION 21.04.2008 08:52:14 TX-DELETE-OBJECT 2> at timestamp 3417749534 - ; => T +; executing transaction #<TRANSACTION 21.04.2008 08:52:14 TX-DELETE-OBJECT 2> at timestamp 3417749534 +; => T (store-object-with-id 2) - ; => NIL +; => NIL
;;;## Defining persistent classes
@@ -412,25 +412,25 @@ ;;; We can now create a few instance of `TUTORIAL-OBJECT':
(make-instance 'tutorial-object :a 2) - ; => #<TUTORIAL-OBJECT ID: 3> +; => #<TUTORIAL-OBJECT ID: 3> (make-instance 'tutorial-object :a 2) - ; => #<TUTORIAL-OBJECT ID: 4> +; => #<TUTORIAL-OBJECT ID: 4> (make-instance 'tutorial-object :a 2) - ; => #<TUTORIAL-OBJECT ID: 5> +; => #<TUTORIAL-OBJECT ID: 5>
(store-object-with-id 5) - ; => #<TUTORIAL-OBJECT ID: 5> +; => #<TUTORIAL-OBJECT ID: 5>
(all-store-classes) - ; => (STORE-OBJECT TUTORIAL-OBJECT) +; => (STORE-OBJECT TUTORIAL-OBJECT)
(store-objects-with-class 'tutorial-object) - ; => (#<TUTORIAL-OBJECT ID: 3> #<TUTORIAL-OBJECT ID: 4> - ; #<TUTORIAL-OBJECT ID: 5>) +; => (#<TUTORIAL-OBJECT ID: 3> #<TUTORIAL-OBJECT ID: 4> +; #<TUTORIAL-OBJECT ID: 5>) (store-objects-with-class 'store-object) - ; => (#<STORE-OBJECT ID: 0> #<STORE-OBJECT ID: 1> - ; #<FOO ID: 2> #<TUTORIAL-OBJECT ID: 3> - ; #<TUTORIAL-OBJECT ID: 4> #<TUTORIAL-OBJECT ID: 5>) +; => (#<STORE-OBJECT ID: 0> #<STORE-OBJECT ID: 1> +; #<FOO ID: 2> #<TUTORIAL-OBJECT ID: 3> +; #<TUTORIAL-OBJECT ID: 4> #<TUTORIAL-OBJECT ID: 5>)
;;; In order to change the slot values of persistent object, the ;;; application needs to be in a transaction context. This can be @@ -442,16 +442,16 @@ ((b :update)))
(make-instance 'tutorial-object2 :b 3) - ; executing transaction #<TRANSACTION 21.04.2008 08:03:27 MAKE-INSTANCE TUTORIAL-OBJECT2 ID 6 B 3> at timestamp 3417746607 - ; => #<TUTORIAL-OBJECT2 ID: 6> +; executing transaction #<TRANSACTION 21.04.2008 08:03:27 MAKE-INSTANCE TUTORIAL-OBJECT2 ID 6 B 3> at timestamp 3417746607 +; => #<TUTORIAL-OBJECT2 ID: 6> (setf (slot-value (store-object-with-id 6) 'b) 4) - ; => Error - ; Attempt to set persistent slot B of #<TUTORIAL-OBJECT2 ID: 6> outside of a transaction +; => Error +; Attempt to set persistent slot B of #<TUTORIAL-OBJECT2 ID: 6> outside of a transaction (with-transaction () (setf (slot-value (store-object-with-id 6) 'b) 4)) - ; => 4 +; => 4 (tutorial-object2-b (store-object-with-id 6)) - ; => 4 +; => 4
;;;## Object creation and deletion protocol
@@ -479,17 +479,17 @@
;;; We can modify the slot `A' outside a transaction: (make-instance 'protocol-object :a 1 :b 2) - ; executing transaction #<TRANSACTION 21.04.2008 08:10:49 MAKE-INSTANCE PROTOCOL-OBJECT ID 7 A 1 B 2> at timestamp 3417747049 - ; => #<PROTOCOL-OBJECT ID: 7> +; executing transaction #<TRANSACTION 21.04.2008 08:10:49 MAKE-INSTANCE PROTOCOL-OBJECT ID 7 A 1 B 2> at timestamp 3417747049 +; => #<PROTOCOL-OBJECT ID: 7> (setf (protocol-object-a (store-object-with-id 7)) 2) - ; => 2 +; => 2
;;; However, we cannot modify the slot `B', as it is persistent and ;;; has to be changed inside a transaction.
(setf (protocol-object-b (store-object-with-id 7)) 4) - ; => Error - ; Attempt to set persistent slot B of #<PROTOCOL-OBJECT ID: 7> outside of a transaction +; => Error +; Attempt to set persistent slot B of #<PROTOCOL-OBJECT ID: 7> outside of a transaction
;;; An object can be removed from the datastore using the transaction ;;; `DELETE-OBJECT', which calls the method `DESTROY-OBJECT' on the @@ -502,19 +502,19 @@ ;;; We can snapshot the persistent state of all created objects by ;;; using `SNAPSHOT'. (snapshot) - ; Snapshotting subsystem #<STORE-OBJECT-SUBSYSTEM #xE54991E> of #<MP-STORE DIR: "/tmp/object-store/"> - ; Successfully snapshotted #<STORE-OBJECT-SUBSYSTEM #xE54991E> of #<MP-STORE DIR: "/tmp/object-store/"> +; Snapshotting subsystem #<STORE-OBJECT-SUBSYSTEM #xE54991E> of #<MP-STORE DIR: "/tmp/object-store/"> +; Successfully snapshotted #<STORE-OBJECT-SUBSYSTEM #xE54991E> of #<MP-STORE DIR: "/tmp/object-store/">
;;; This will create a backup directory containing the old transaction ;;; log, and the creation of a snapshot file in the "current" ;;; directory.
(directory "/tmp/object-store/**/*.*") - ; => (#P"/tmp/object-store/20080421T061210/random-state" - ; #P"/tmp/object-store/20080421T061210/transaction-log" - ; #P"/tmp/object-store/current/random-state" - ; #P"/tmp/object-store/current/store-object-subsystem-snapshot" - ; #P"/tmp/object-store/current/transaction-log") +; => (#P"/tmp/object-store/20080421T061210/random-state" +; #P"/tmp/object-store/20080421T061210/transaction-log" +; #P"/tmp/object-store/current/random-state" +; #P"/tmp/object-store/current/store-object-subsystem-snapshot" +; #P"/tmp/object-store/current/transaction-log")
;;; The snapshot file contains all persistent objects present at ;;; snapshotting time, and the value of their persistent @@ -538,15 +538,15 @@ :index-keys all-gorilla-moods)))
(make-instance 'gorilla :name "lucy" :mood :aggressive) - ; => #<GORILLA ID: 8> +; => #<GORILLA ID: 8> (make-instance 'gorilla :name "john" :mood :playful) - ; => #<GORILLA ID: 9> +; => #<GORILLA ID: 9> (make-instance 'gorilla :name "peter" :mood :playful) - ; => #<GORILLA ID: 10> +; => #<GORILLA ID: 10> (gorilla-with-name "lucy") - ; => #<GORILLA ID: 8> +; => #<GORILLA ID: 8> (gorillas-with-mood :playful) - ; => (#<GORILLA ID: 10> #<GORILLA ID: 9>) +; => (#<GORILLA ID: 10> #<GORILLA ID: 9>)
;;;## Adding blobs
@@ -606,7 +606,7 @@
(make-blob-from-file "/tmp/bla.jpg" 'photo :name "foobar" :type :jpg) - ; => #<PHOTO ID: 11, TYPE: jpg> +; => #<PHOTO ID: 11, TYPE: jpg>
;;; We can work with the photo object in the same way as when we work ;;; with a normal object. However, we can access the binary data using @@ -615,7 +615,7 @@ ;;; object.
(blob-pathname (store-object-with-id 11)) - ; => #P"/tmp/object-store/blob-root/11" +; => #P"/tmp/object-store/blob-root/11"
;;; The method `BLOB-TO-FILE' and `BLOB-TO-STREAM' write the binary ;;; data of the object to the specified file or stream (the stream has @@ -642,37 +642,37 @@ ((a :update :relaxed-object-reference t)))
(make-instance 'relaxed-object) - ; => #<RELAXED-OBJECT ID: 12> +; => #<RELAXED-OBJECT ID: 12> (make-instance 'relaxed-object) - ; => #<RELAXED-OBJECT ID: 13> +; => #<RELAXED-OBJECT ID: 13> (with-transaction () (setf (slot-value (store-object-with-id 12) 'a) (store-object-with-id 13))) - ; => #<RELAXED-OBJECT ID: 13> +; => #<RELAXED-OBJECT ID: 13> (delete-object (store-object-with-id 13)) - ; => T +; => T (snapshot) - ; Warning: Backup of the datastore in /tmp/object-store/20080421T064811/. - ; While executing: (:INTERNAL (SNAPSHOT-STORE (STORE))), in process worker(1750). - ; Snapshotting subsystem #<STORE-OBJECT-SUBSYSTEM #xE6069EE> of #<MP-STORE DIR: "/tmp/object-store/"> - ; Warning: Encoding reference to destroyed object with ID 13 from slot A of object RELAXED-OBJECT with ID 12. - ; While executing: #<STANDARD-METHOD ENCODE-OBJECT (STORE-OBJECT T)>, in process worker(1750). - ; Successfully snapshotted #<STORE-OBJECT-SUBSYSTEM #xE6069EE> of #<MP-STORE DIR: "/tmp/object-store/"> - ; Snapshotting subsystem #<BLOB-SUBSYSTEM #xE6069CE> of #<MP-STORE DIR: "/tmp/object-store/"> - ; Successfully snapshotted #<BLOB-SUBSYSTEM #xE6069CE> of #<MP-STORE DIR: "/tmp/object-store/"> - ; => NIL +; Warning: Backup of the datastore in /tmp/object-store/20080421T064811/. +; While executing: (:INTERNAL (SNAPSHOT-STORE (STORE))), in process worker(1750). +; Snapshotting subsystem #<STORE-OBJECT-SUBSYSTEM #xE6069EE> of #<MP-STORE DIR: "/tmp/object-store/"> +; Warning: Encoding reference to destroyed object with ID 13 from slot A of object RELAXED-OBJECT with ID 12. +; While executing: #<STANDARD-METHOD ENCODE-OBJECT (STORE-OBJECT T)>, in process worker(1750). +; Successfully snapshotted #<STORE-OBJECT-SUBSYSTEM #xE6069EE> of #<MP-STORE DIR: "/tmp/object-store/"> +; Snapshotting subsystem #<BLOB-SUBSYSTEM #xE6069CE> of #<MP-STORE DIR: "/tmp/object-store/"> +; Successfully snapshotted #<BLOB-SUBSYSTEM #xE6069CE> of #<MP-STORE DIR: "/tmp/object-store/"> +; => NIL (restore) - ; restoring #<MP-STORE DIR: "/tmp/object-store/"> - ; Restoring the subsystem #<STORE-OBJECT-SUBSYSTEM #xE6069EE> of #<MP-STORE DIR: "/tmp/object-store/"> - ; loading snapshot file /tmp/object-store/current/store-object-subsystem-snapshot - ; Warning: internal inconsistency during restore: can't find store object 13 in loaded store - ; While executing: %DECODE-STORE-OBJECT, in process worker(1754). - ; Warning: Reference to inexistent object with id 13 from unnamed container, returning NIL. - ; While executing: %DECODE-STORE-OBJECT, in process worker(1754). - ; Restoring the subsystem #<BLOB-SUBSYSTEM #xE6069CE> of #<MP-STORE DIR: "/tmp/object-store/"> - ; loading transaction log /tmp/object-store/current/transaction-log - ; executing transaction #<ANONYMOUS-TRANSACTION 21.04.2008 08:48:48 PREPARE-FOR-SNAPSHOT NIL> at timestamp 3417749328 +; restoring #<MP-STORE DIR: "/tmp/object-store/"> +; Restoring the subsystem #<STORE-OBJECT-SUBSYSTEM #xE6069EE> of #<MP-STORE DIR: "/tmp/object-store/"> +; loading snapshot file /tmp/object-store/current/store-object-subsystem-snapshot +; Warning: internal inconsistency during restore: can't find store object 13 in loaded store +; While executing: %DECODE-STORE-OBJECT, in process worker(1754). +; Warning: Reference to inexistent object with id 13 from unnamed container, returning NIL. +; While executing: %DECODE-STORE-OBJECT, in process worker(1754). +; Restoring the subsystem #<BLOB-SUBSYSTEM #xE6069CE> of #<MP-STORE DIR: "/tmp/object-store/"> +; loading transaction log /tmp/object-store/current/transaction-log +; executing transaction #<ANONYMOUS-TRANSACTION 21.04.2008 08:48:48 PREPARE-FOR-SNAPSHOT NIL> at timestamp 3417749328 (relaxed-object-a (store-object-with-id 12)) - ; => NIL +; => NIL
;;;# Store internals