Show
Ignore:
Timestamp:
04/29/08 23:48:20 (4 months ago)
Author:
hans
Message:

Update tutorials to reflect reality better

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/bknr/datastore/src/data/tutorial.lisp

    r2609 r3035  
    113113;;; transaction, and logged to disk. 
    114114 
    115 (PROGN 
    116  (DEFUN TX-DECF-COUNTER () 
    117    (UNLESS (IN-TRANSACTION-P) (ERROR 'NOT-IN-TRANSACTION)) 
    118    (DECF (TUTORIAL-STORE-COUNTER *STORE*))) 
    119  (DEFUN DECF-COUNTER (&REST #:G3047) 
    120    (EXECUTE 
    121     (MAKE-INSTANCE 'TRANSACTION 
    122                    :FUNCTION-SYMBOL 
    123                    'TX-DECF-COUNTER 
    124                    :TIMESTAMP 
    125                    (GET-UNIVERSAL-TIME) 
    126                    :ARGS 
    127                    #:G3047)))) 
     115(PROGN (DEFUN TX-DECF-COUNTER () 
     116         (UNLESS (IN-TRANSACTION-P) (ERROR 'NOT-IN-TRANSACTION)) 
     117         (DECF (TUTORIAL-STORE-COUNTER *STORE*))) 
     118       (DEFUN DECF-COUNTER () 
     119         (EXECUTE (MAKE-INSTANCE 'TRANSACTION 
     120                                 :FUNCTION-SYMBOL 'TX-DECF-COUNTER 
     121                                 :TIMESTAMP (GET-UNIVERSAL-TIME) 
     122                                 :ARGS (LIST))))) 
    128123 
    129124;;; The new datastore only supports a single datastore instance per 
    130 ;;; LISP session. When creating a `STORE' object, the `*STORE*' 
     125;;; LISP instance. When creating a `STORE' object, the `*STORE*' 
    131126;;; special variable is modified to point to the datastore. Thus, we 
    132127;;; can create our simple datastore by creating an object of type 
     
    213208; => T 
    214209(restore-store *store*) 
    215 ; Warning:  restoring #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> 
    216 ; Warning:  loading transaction log 
    217 ; /tmp/tutorial-store/current/transaction-log 
    218 ; executing transaction #$(TX-INCF-COUNTER) at timestamp 3309258381 
    219 ; executing transaction #$(TX-INCF-COUNTER) at timestamp 3309258383 
    220 ; executing transaction #$(TX-DECF-COUNTER) at timestamp 3309258387 
    221 ; executing transaction #$(TX-INCF-COUNTER) at timestamp 3309258390 
    222 ; => :NORMAL 
     210; restoring #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> 
     211; loading transaction log /tmp/tutorial-store/current/transaction-log 
     212; executing transaction #<TRANSACTION 21.04.2008 07:08:22 TX-INCF-COUNTER > at timestamp 3417743302 
     213; executing transaction #<TRANSACTION 21.04.2008 07:08:25 TX-INCF-COUNTER > at timestamp 3417743305 
     214; executing transaction #<TRANSACTION 21.04.2008 07:08:26 TX-DECF-COUNTER > at timestamp 3417743306 
     215; executing transaction #<TRANSACTION 21.04.2008 07:08:34 TX-INCF-COUNTER > at timestamp 3417743314 
     216; => NIL 
    223217(tutorial-store-counter *store*) 
    224218; => 2 
    225 (restore-store *store* :until 3309258387) 
    226 ; Warning:  restoring #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> 
    227 ; Warning:  loading transaction log 
    228 ; /tmp/tutorial-store/current/transaction-log 
    229 ; executing transaction #$(TX-INCF-COUNTER) at timestamp 3309258381 
    230 ; executing transaction #$(TX-INCF-COUNTER) at timestamp 3309258383 
    231 ; executing transaction #$(TX-DECF-COUNTER) at timestamp 3309258387 
    232 ; => :NORMAL 
     219; !! Update the timestamp below to correspond to the fist transaction executed above !! 
     220(restore-store *store* :until 3417743302) ... 
     221; restoring #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> 
     222; loading transaction log /tmp/tutorial-store/current/transaction-log 
     223; executing transaction #<TRANSACTION 21.04.2008 07:08:22 TX-INCF-COUNTER > at timestamp 3417743302 
     224; creating log file backup: /tmp/tutorial-store/current/transaction-log.backup 
     225; truncating transaction log at position 42. 
    233226(tutorial-store-counter *store*) 
    234227; => 1 
     
    304297; => #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> 
    305298(snapshot) 
     299; Snapshotting subsystem #<COUNTER-SUBSYSTEM #xE65F866> of #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> 
     300; Successfully snapshotted #<COUNTER-SUBSYSTEM #xE65F866> of #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> 
    306301; => NIL 
    307302(restore) 
    308 ; Warning:  restoring #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> 
    309 ; => :NORMAL 
     303; restoring #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> 
     304; Restoring the subsystem #<COUNTER-SUBSYSTEM #xE65F866> of #<TUTORIAL-STORE DIR: "/tmp/tutorial-store/"> 
     305; => NUL 
    310306 
    311307;;;# An object store example 
     
    346342 
    347343; Warning:  restoring #<MP-STORE DIR: "/tmp/object-store/"> 
    348 ; => #<MP-STORE DIR: "/tmp/object-store/"> 
     344; restoring #<MP-STORE DIR: "/tmp/object-store/"> 
     345; Restoring the subsystem #<STORE-OBJECT-SUBSYSTEM #xE63F866> of #<MP-STORE DIR: "/tmp/object-store/"> 
    349346(all-store-objects) 
    350347; => NIL 
     
    371368 
    372369(make-object 'store-object) 
    373 ; executing transaction #$(TX-MAKE-OBJECT STORE-OBJECT) 
    374 ; at timestamp 3309260107 
     370; executing transaction #<TRANSACTION 21.04.2008 08:02:10 TX-MAKE-OBJECT STORE-OBJECT ID 2> at timestamp 3417746530 
    375371; => #<STORE-OBJECT ID: 12> 
    376372(store-object-with-id 2) 
    377373; => #<STORE-OBJECT ID: 2> 
    378374(delete-object (store-object-with-id 2)) 
    379 ; executing transaction #$(TX-DELETE-OBJECT 2) 
    380 ; at timestamp 3309260112 
     375; executing transaction #<TRANSACTION 21.04.2008 08:52:14 TX-DELETE-OBJECT 2> at timestamp 3417749534 
    381376; => T 
    382377(store-object-with-id 2) 
     
    438433;  #<TUTORIAL-OBJECT ID: 4> #<TUTORIAL-OBJECT ID: 5>) 
    439434 
    440 ;;; A basic transaction used to work on persistent objects is the 
    441 ;;; transaction `CHANGE-SLOT-VALUES', which sets the values of slots 
    442 ;;; in an object. The value of a persistent slot can not be changed 
    443 ;;; outside of a transaction, as restoring the datastore would not 
    444 ;;; change the slot value
     435;;; In order to change the slot values of persistent object, the 
     436;;; application needs to be in a transaction context.  This can be 
     437;;; done either by invoking a named transaction as above, or by 
     438;;; creating an anonymous transaction.  In an anonymous transaction, 
     439;;; all write accesses to persistent objects are logged
    445440 
    446441(define-persistent-class tutorial-object2 () 
     
    448443 
    449444(make-object 'tutorial-object2 :b 3) 
    450 ; executing transaction #$(TX-MAKE-OBJECT TUTORIAL-OBJECT2 B 3) 
    451 ; at timestamp 3309263046 
    452 ; => #<TUTORIAL-OBJECT2 ID: 16> 
    453 (setf (slot-value (store-object-with-id 16) 'b) 4) 
     445; executing transaction #<TRANSACTION 21.04.2008 08:03:27 TX-MAKE-OBJECT TUTORIAL-OBJECT2 ID 6 B 3> at timestamp 3417746607 
     446; => #<TUTORIAL-OBJECT2 ID: 6> 
     447(setf (slot-value (store-object-with-id 6) 'b) 4) 
    454448; => Error 
    455 (change-slot-values (store-object-with-id 16) 'b 4) 
    456 ; executing transaction #$(TX-CHANGE-SLOT-VALUES 
    457 ; #<TUTORIAL-OBJECT2 ID: 16> B 4) at timestamp 3309263109 
    458 ; => NIL 
    459 (tutorial-object2-b (store-object-with-id 16)) 
     449; Attempt to set persistent slot B of #<TUTORIAL-OBJECT2 ID: 6> outside of a transaction 
     450(with-transaction () 
     451  (setf (slot-value (store-object-with-id 6) 'b) 4)) 
     452; => 4 
     453(tutorial-object2-b (store-object-with-id 6)) 
    460454; => 4 
    461455 
     
    484478;;; We can modify the slot `A' outside a transaction: 
    485479(make-object 'protocol-object :a 1 :b 2) 
    486 ; executing transaction #$(TX-MAKE-OBJECT PROTOCOL-OBJECT A 1 B 2) 
    487 ; at timestamp 3309262613 
    488 ; => #<PROTOCOL-OBJECT ID: 14> 
    489 (setf (protocol-object-a *) 2) 
     480; executing transaction #<TRANSACTION 21.04.2008 08:10:49 TX-MAKE-OBJECT PROTOCOL-OBJECT ID 7 A 1 B 2> at timestamp 3417747049 
     481; => #<PROTOCOL-OBJECT ID: 7> 
     482(setf (protocol-object-a (store-object-with-id 7)) 2) 
    490483; => 2 
    491484 
     
    493486;;; has to be changed inside a transaction. 
    494487 
    495 (setf (protocol-object-b (store-object-with-id 14)) 4) 
     488(setf (protocol-object-b (store-object-with-id 7)) 4) 
    496489; => Error 
     490; Attempt to set persistent slot B of #<PROTOCOL-OBJECT ID: 7> outside of a transaction 
    497491 
    498492;;; An object can be removed from the datastore using the transaction 
     
    507501;;; using `SNAPSHOT'. 
    508502(snapshot) 
    509 ; Warning:  Backup of the datastore in 
    510 ; /tmp/object-store/20041112T153046/. 
    511 ; Warning: 
    512 ;   Snapshotting subsystem #<STORE-OBJECT-SUBSYSTEM {49396ED5}> 
    513 ;    of #<MP-STORE DIR: "/tmp/object-store/">... 
    514 ; Warning: 
    515 ;   Successfully snapshotted #<STORE-OBJECT-SUBSYSTEM {49396ED5}> 
    516 ;   of #<MP-STORE DIR: "/tmp/object-store/">. 
    517 ; => NIL 
     503; Snapshotting subsystem #<STORE-OBJECT-SUBSYSTEM #xE54991E> of #<MP-STORE DIR: "/tmp/object-store/"> 
     504; Successfully snapshotted #<STORE-OBJECT-SUBSYSTEM #xE54991E> of #<MP-STORE DIR: "/tmp/object-store/"> 
    518505 
    519506;;; This will create a backup directory containing the old transaction 
     
    522509 
    523510(directory "/tmp/object-store/**/*.*") 
    524 ; => (#p"/tmp/object-store/20041112T153046/" 
    525 ;  #p"/tmp/object-store/20041112T153046/transaction-log" 
    526 ;  #p"/tmp/object-store/current/" 
    527 ;  #p"/tmp/object-store/current/store-object-subsystem-snapshot") 
     511; => (#P"/tmp/object-store/20080421T061210/random-state" 
     512;     #P"/tmp/object-store/20080421T061210/transaction-log" 
     513;     #P"/tmp/object-store/current/random-state" 
     514;     #P"/tmp/object-store/current/store-object-subsystem-snapshot" 
     515;     #P"/tmp/object-store/current/transaction-log") 
    528516 
    529517;;; The snapshot file contains all persistent objects present at 
     
    549537 
    550538(make-object 'gorilla :name "lucy" :mood :aggressive) 
    551 ; => #<GORILLA ID: 17
     539; => #<GORILLA ID: 8
    552540(make-object 'gorilla :name "john" :mood :playful) 
    553 ; => #<GORILLA ID: 18
     541; => #<GORILLA ID: 9
    554542(make-object 'gorilla :name "peter" :mood :playful) 
    555 ; => #<GORILLA ID: 19
     543; => #<GORILLA ID: 10
    556544(gorilla-with-name "lucy") 
    557 ; => #<GORILLA ID: 17
     545; => #<GORILLA ID: 8
    558546(gorillas-with-mood :playful) 
    559 ; => (#<GORILLA ID: 19> #<GORILLA ID: 18>) 
    560  
    561 ;;;## Exporting store objects to XML 
    562  
    563 ;;; Exporting store objects to XML is not possible right now, but it 
    564 ;;; will soon be available in the BKNR Framework. Stay tuned. 
     547; => (#<GORILLA ID: 10> #<GORILLA ID: 9>) 
    565548 
    566549;;;## Adding blobs 
     
    599582;;; adding the blob subsystem to its list of subsystems. 
    600583 
     584(close-store) 
    601585(make-instance 'mp-store :directory "/tmp/object-store/" 
    602586               :subsystems (list 
     
    619603;;; object in the blob root directory of the blob subsystem. 
    620604 
    621 (make-blob-from-file "/tmp/bla.png" 'photo :name "foobar" 
    622                      :type :png) 
    623 ; => #<PHOTO ID: 16, TYPE: png> 
     605(make-blob-from-file "/tmp/bla.jpg" 'photo :name "foobar" 
     606                     :type :jpg) 
     607; => #<PHOTO ID: 11, TYPE: jpg> 
    624608 
    625609;;; We can work with the photo object in the same way as when we work 
     
    629613;;; object. 
    630614 
    631 (blob-pathname (store-object-with-id 16)) 
    632 ; => #p"/tmp/object-store/blob-root/16
     615(blob-pathname (store-object-with-id 11)) 
     616; => #P"/tmp/object-store/blob-root/11
    633617 
    634618;;; The method `BLOB-TO-FILE' and `BLOB-TO-STREAM' write the binary 
     
    657641 
    658642(make-object 'relaxed-object) 
    659 ; => #<RELAXED-OBJECT ID: 20
     643; => #<RELAXED-OBJECT ID: 12
    660644(make-object 'relaxed-object) 
    661 ; => #<RELAXED-OBJECT ID: 21
    662 (change-slot-values (store-object-with-id 19
    663                    'a (store-object-with-id 20)) 
    664 ; => NIL 
    665 (delete-object (store-object-with-id 20)) 
     645; => #<RELAXED-OBJECT ID: 13
     646(with-transaction (
     647  (setf (slot-value (store-object-with-id 12) 'a) (store-object-with-id 13))) 
     648; => #<RELAXED-OBJECT ID: 13> 
     649(delete-object (store-object-with-id 13)) 
    666650; => T 
    667651(snapshot) 
    668 ; Warning: 
    669 ;    Encoding reference to destroyed object with ID 20 
    670 ;    from slot A of object RELAXED-OBJECT with ID 19. 
     652; Warning: Backup of the datastore in /tmp/object-store/20080421T064811/. 
     653; While executing: (:INTERNAL (SNAPSHOT-STORE (STORE))), in process worker(1750). 
     654; Snapshotting subsystem #<STORE-OBJECT-SUBSYSTEM #xE6069EE> of #<MP-STORE DIR: "/tmp/object-store/"> 
     655; Warning: Encoding reference to destroyed object with ID 13 from slot A of object RELAXED-OBJECT with ID 12. 
     656; While executing: #<STANDARD-METHOD ENCODE-OBJECT (STORE-OBJECT T)>, in process worker(1750). 
     657; Successfully snapshotted #<STORE-OBJECT-SUBSYSTEM #xE6069EE> of #<MP-STORE DIR: "/tmp/object-store/"> 
     658; Snapshotting subsystem #<BLOB-SUBSYSTEM #xE6069CE> of #<MP-STORE DIR: "/tmp/object-store/"> 
     659; Successfully snapshotted #<BLOB-SUBSYSTEM #xE6069CE> of #<MP-STORE DIR: "/tmp/object-store/"> 
    671660; => NIL 
    672661(restore) 
    673 ; Warning:  restoring #<MP-STORE DIR: "/tmp/object-store/"> 
    674 ; Warning: 
    675 ;    loading snapshot file 
    676 ;    /tmp/object-store/current/store-object-subsystem-snapshot 
    677 ; Warning: 
    678 ;    Reference to inexistent object with id 20 in 
    679 ; relaxed slot A of object with class RELAXED-OBJECT with ID 19. 
    680 ; => :NORMAL 
    681 (relaxed-object-a (store-object-with-id 19)) 
     662; restoring #<MP-STORE DIR: "/tmp/object-store/"> 
     663; Restoring the subsystem #<STORE-OBJECT-SUBSYSTEM #xE6069EE> of #<MP-STORE DIR: "/tmp/object-store/"> 
     664; loading snapshot file /tmp/object-store/current/store-object-subsystem-snapshot 
     665; Warning: internal inconsistency during restore: can't find store object 13 in loaded store 
     666; While executing: %DECODE-STORE-OBJECT, in process worker(1754). 
     667; Warning: Reference to inexistent object with id 13 from unnamed container, returning NIL. 
     668; While executing: %DECODE-STORE-OBJECT, in process worker(1754). 
     669; Restoring the subsystem #<BLOB-SUBSYSTEM #xE6069CE> of #<MP-STORE DIR: "/tmp/object-store/"> 
     670; loading transaction log /tmp/object-store/current/transaction-log 
     671; executing transaction #<ANONYMOUS-TRANSACTION 21.04.2008 08:48:48 PREPARE-FOR-SNAPSHOT NIL> at timestamp 3417749328 
     672(relaxed-object-a (store-object-with-id 12)) 
    682673; => NIL 
    683674