[rucksack-devel] Practical ways of unlinking an instance from indexes, more info

Uwe von Loh uvl at htg1.de
Wed Jan 31 13:01:37 UTC 2007


OK, I abandoned the idea with change-class or slot-makunbound in 
rucksack and came back to index-delete. This works for the class index 
but not for the slot indexes. As I understand slot-indexes they are 
btrees with the instance slot value as keys and the instance object-id 
as values. So what is wrong with

(index-delete (rucksack-slot-index rs 'user 'pw)
		   (pw usr)
		   (object-id usr))   ???

Uwe 8-)


Here is the code and the backtrace. (Sorry, I'm a novice).
======================================================================
This is the lisp file:
======================================================================

(in-package :rucksack)

(eval-when (:compile-toplevel :load-toplevel :execute)

   (defparameter *uwes-rs* #p"/home/uvl/cl/src/ht/rs/")

   (with-rucksack (rs *uwes-rs*)
     (with-transaction ()
       (defclass user ()
	((name :initarg :name :accessor name
		 :index :case-insensitive-string-index)
	 (pw :initarg :pw :accessor pw :index :string-index))
	(:metaclass persistent-class)
	(:index t))))
   )

(defun show-class (class-name)
   (with-rucksack (rs *uwes-rs*)
     (with-transaction ()
       (rucksack-map-class rs class-name #'print))))

(defun show-user-with-password (value)
   (with-rucksack (rs *uwes-rs*)
     (with-transaction ()
       (rucksack-map-slot
        rs 'user 'pw
        (lambda (usr)
	 (format t "~A has password: ~A.~%"
		 (name usr)(pw usr)))
        :equal value))))

(defun nuke-user-named (user-name)
   (with-rucksack (rs *uwes-rs*)
     (with-transaction ()
       (rucksack-map-slot
        rs 'user 'name (lambda (x)(rm-usr-from-indexes x))
        :equal user-name))))

(defun rm-usr-from-indexes (usr)
   (with-rucksack (rs *uwes-rs*)
     (with-transaction ()

;;this works quite well
      (index-delete (rucksack-class-index rs 'user)
		   (object-id usr)
		   (object-id usr))

;;removing from slot indexes doesn't work:
      (index-delete (rucksack-slot-index rs 'user 'pw)
		   (pw usr)
		   (object-id usr))
      (index-delete (rucksack-slot-index rs 'user 'name)
		   (name usr)
		   (object-id usr)))))

;; From the source code just to keep in mind: Slot indexes are...
;; ... "A btree mapping class names to slot index tables, where each
;; slot index table is a btree mapping slot names to slot indexes.
;; Each slot index maps slot values to object ids."


======================================================================
I create three instances of 'user and try to remove one of them from
all three indexes.
======================================================================

RS>   (with-rucksack (rs *uwes-rs*)
	(with-transaction ()
	  (make-instance 'user :name "bob" :pw "bobpw" :rucksack rs)))
#<USER #37 in #<STANDARD-CACHE of size 10000, heap 
#P"/home/uvl/cl/src/ht/rs/heap" and 28 objects in memory.>>
T
RS>   (with-rucksack (rs *uwes-rs*)
	(with-transaction ()
	  (make-instance 'user :name "uwe" :pw "uwepw" :rucksack rs)))
#<USER #67 in #<STANDARD-CACHE of size 10000, heap 
#P"/home/uvl/cl/src/ht/rs/heap" and 43 objects in memory.>>
T
RS>   (with-rucksack (rs *uwes-rs*)
	(with-transaction ()
	  (make-instance 'user :name "jim" :pw "jimpw" :rucksack rs)))
#<USER #73 in #<STANDARD-CACHE of size 10000, heap 
#P"/home/uvl/cl/src/ht/rs/heap" and 46 objects in memory.>>
T
RS> (show-class 'user)

#<USER #37 in #<STANDARD-CACHE of size 10000, heap 
#P"/home/uvl/cl/src/ht/rs/heap" and 16 objects in memory.>>
#<USER #67 in #<STANDARD-CACHE of size 10000, heap 
#P"/home/uvl/cl/src/ht/rs/heap" and 21 objects in memory.>>
#<USER #73 in #<STANDARD-CACHE of size 10000, heap 
#P"/home/uvl/cl/src/ht/rs/heap" and 23 objects in memory.>>
NIL
T
RS> (nuke-user-named "uwe")

======================================================================
Gives following error
======================================================================

Argument X is not a REAL: NIL
    [Condition of type SIMPLE-TYPE-ERROR]
Argument X is not a REAL: NIL
    [Condition of type SIMPLE-TYPE-ERROR]

Restarts:
   0: [ABORT] Abort #<STANDARD-TRANSACTION #337924435200000 with 8 dirty 
objects>
   1: [RETRY] Retry #<STANDARD-TRANSACTION #337924435200000 with 8 dirty 
objects>
   2: [ABORT] Abort #<STANDARD-TRANSACTION #337924435200000 with 0 dirty 
objects>
   3: [RETRY] Retry #<STANDARD-TRANSACTION #337924435200000 with 0 dirty 
objects>
   4: [ABORT-REQUEST] Abort handling SLIME request.
   5: [TERMINATE-THREAD] Terminate this thread (#<THREAD 
"new-repl-thread" {B646CC1}>)

Backtrace:
   0: (SB-KERNEL:TWO-ARG-< NIL 1)
   1: (REMOVE-KEY #<BTREE-NODE with 2 bindings {BCCB341}> "uwepw")
       Locals:
         SB-DEBUG::ARG-0 = #<BTREE-NODE with 2 bindings {BCCB341}>
         SB-DEBUG::ARG-1 = "uwepw"
   2: (LEAF-DELETE-KEY #<BTREE #34 in #<STANDARD-CACHE of size 10000, 
heap #P"/home/uvl/cl/src/ht/rs/heap" and 45 objects in memory.>> 
#<BTREE-NODE with 2 bindings {BCCB341}> (#<BTREE-NODE with 2 bindings 
{BCCAAB9}> NIL) "uwepw" :IGNORE)
       Locals:
         SB-DEBUG::ARG-0 = #<BTREE #34 in #<STANDARD-CACHE of size 
10000, heap #P"/home/uvl/cl/src/ht/rs/heap" and 45 objects in memory.>>
         SB-DEBUG::ARG-1 = #<BTREE-NODE with 2 bindings {BCCB341}>
         SB-DEBUG::ARG-2 = (#<BTREE-NODE with 2 bindings {BCCAAB9}> NIL)
         SB-DEBUG::ARG-3 = "uwepw"
         SB-DEBUG::ARG-4 = :IGNORE
   3: ((SB-PCL::FAST-METHOD BTREE-DELETE (BTREE #1="#<...>" . #1#)) 
(#(NIL) . #()) #<unused argument> #<BTREE #34 in #<STANDARD-CACHE of 
size 10000, heap #P"/home/uvl/cl/src/ht/rs/heap" and 45 objects in 
memory.>> "uwepw" 67 :IF-DOES-NOT-EXIST :IGNORE)
       Locals:
         SB-PCL::.PV-CELL. = (#(NIL) . #())
         BTREE = #<BTREE #34 in #<STANDARD-CACHE of size 10000, heap 
#P"/home/uvl/cl/src/ht/rs/heap" and 45 objects in memory.>>
         #:IF-DOES-NOT-EXIST-DEFAULTING-TEMP = :IGNORE
         KEY = "uwepw"
         VALUE = 67
   4: (RM-USR-FROM-INDEXES #<USER #67 in #<STANDARD-CACHE of size 10000, 
heap #P"/home/uvl/cl/src/ht/rs/heap" and 26 objects in memory.>>)
       Locals:
         SB-DEBUG::ARG-0 = #<USER #67 in #<STANDARD-CACHE of size 10000, 
heap #P"/home/uvl/cl/src/ht/rs/heap" and 26 objects in memory.>>
   5: (P-MAPC #<CLOSURE (LAMBDA (ELT)) {BCA9E5D}> #<PERSISTENT-CONS #69 
in #<STANDARD-CACHE of size 10000, heap #P"/home/uvl/cl/src/ht/rs/heap" 
and 26 objects in memory.>>)
       Locals:
         SB-DEBUG::ARG-0 = #<CLOSURE (LAMBDA (ELT)) {BCA9E5D}>
         SB-DEBUG::ARG-1 = #<PERSISTENT-CONS #69 in #<STANDARD-CACHE of 
size 10000, heap #P"/home/uvl/cl/src/ht/rs/heap" and 26 objects in memory.>>
   6: ((LABELS MAP-SLOT) #<PERSISTENT-CLASS USER>)
       Locals:
         SB-DEBUG::ARG-0 = #<PERSISTENT-CLASS USER>
   7: ((SB-PCL::FAST-METHOD RUCKSACK-MAP-SLOT (STANDARD-RUCKSACK 
#1="#<...>" . #1#)) #<unavailable argument> #<unavailable argument> 
#<SERIAL-TRANSACTION-RUCKSACK in #P"/home/uvl/cl/src/ht/rs/" with 0 
roots {BC673F1}> USER NAME #<FUNCTION (LAMBDA (X)) {B5462B5}>)
       Locals:
         SB-DEBUG::ARG-0 = 8
         SB-DEBUG::ARG-1 = :<NOT-AVAILABLE>
         SB-DEBUG::ARG-2 = :<NOT-AVAILABLE>
         SB-DEBUG::ARG-3 = #<SERIAL-TRANSACTION-RUCKSACK in 
#P"/home/uvl/cl/src/ht/rs/" with 0 roots {BC673F1}>
         SB-DEBUG::ARG-4 = USER
         SB-DEBUG::ARG-5 = NAME
         SB-DEBUG::ARG-6 = #<FUNCTION (LAMBDA (X)) {B5462B5}>
   8: (NUKE-USER-NAMED "uwe")
       Locals:
         SB-DEBUG::ARG-0 = "uwe"
   9: (SB-INT:SIMPLE-EVAL-IN-LEXENV (NUKE-USER-NAMED "uwe") #<NULL-LEXENV>)
       Locals:
         SB-DEBUG::ARG-0 = 2
         SB-DEBUG::ARG-1 = (NUKE-USER-NAMED "uwe")
         SB-DEBUG::ARG-2 = #<NULL-LEXENV>
  10: (SWANK::EVAL-REGION "(nuke-user-named \"uwe\")
" T)
       Locals:
         SWANK::PACKAGE-UPDATE-P = T
         STRING = "(nuke-user-named \"uwe\")
"
  11: ((LAMBDA NIL))
  12: ((SB-PCL::FAST-METHOD SWANK-BACKEND:CALL-WITH-SYNTAX-HOOKS (T)) 
#<unused argument> #<unused argument> #<CLOSURE (LAMBDA NIL) {BC5D4CD}>)
  13: (SWANK::CALL-WITH-BUFFER-SYNTAX #<CLOSURE (LAMBDA NIL) {BC5D4CD}>)
  14: (SB-INT:SIMPLE-EVAL-IN-LEXENV (SWANK:LISTENER-EVAL 
"(nuke-user-named \"uwe\")
") #<NULL-LEXENV>)
  15: ((LAMBDA NIL))
  16: ((SB-PCL::FAST-METHOD SWANK-BACKEND:CALL-WITH-DEBUGGER-HOOK (T T)) 
#<unused argument> #<unused argument> #<FUNCTION 
SWANK:SWANK-DEBUGGER-HOOK> #<CLOSURE (LAMBDA NIL) {BC5CDFD}>)
  17: ((LAMBDA NIL))
  18: ((SB-PCL::FAST-METHOD SWANK-BACKEND:CALL-WITH-DEBUGGER-HOOK (T T)) 
#<unused argument> #<unused argument> #<FUNCTION 
SWANK:SWANK-DEBUGGER-HOOK> #<FUNCTION (LAMBDA NIL) {B3EBF7D}>)
  19: (SWANK::CALL-WITH-REDIRECTED-IO #<SWANK::CONNECTION {A9FD6B1}> 
#<CLOSURE (LAMBDA NIL) {BC5CCB5}>)
  20: (SWANK::CALL-WITH-CONNECTION #<SWANK::CONNECTION {A9FD6B1}> 
#<FUNCTION (LAMBDA NIL) {B3EBF7D}>)
  21: (SWANK::HANDLE-REQUEST #<SWANK::CONNECTION {A9FD6B1}>)
  22: ((LAMBDA NIL))
  23: ((LAMBDA NIL))
  24: ((SB-PCL::FAST-METHOD SWANK-BACKEND:CALL-WITH-DEBUGGER-HOOK (T T)) 
#<unused argument> #<unused argument> #<FUNCTION 
SWANK:SWANK-DEBUGGER-HOOK> #<CLOSURE (LAMBDA NIL) {B6790BD}>)
  25: (SWANK::CALL-WITH-REDIRECTED-IO #<SWANK::CONNECTION {A9FD6B1}> 
#<CLOSURE (LAMBDA NIL) {B6790CD}>)
  26: (SWANK::CALL-WITH-CONNECTION #<SWANK::CONNECTION {A9FD6B1}> 
#<CLOSURE (LAMBDA NIL) {B6790BD}>)
  27: (SWANK::CALL-WITH-BINDINGS NIL #<CLOSURE (LAMBDA NIL) {B67909D}>)
  28: ((LAMBDA NIL))
  29: ("foreign function: call_into_lisp")
  30: ("foreign function: funcall0")
  31: ("foreign function: new_thread_trampoline")
  32: ("foreign function: #xB7FCA504")



More information about the rucksack-devel mailing list