[rucksack-devel] Indexed classes

Arthur Lemmens alemmens at xs4all.nl
Wed Jan 16 14:28:39 UTC 2008


Brad Beveridge wrote:

> I have defined a class such:
> (defclass foo ()
>   ((data :initarg :data :accessor data
> 	 :index :case-insensitive-string-index))
>   (:index t)
>   (:metaclass persistent-class))
>
> If I run the following code:
>
> (with-rucksack-and-transaction
>   (make-instance 'foo :data "foobar")
>   )
>
> (with-rucksack-and-transaction
>   (rucksack-map-class *rucksack* 'foo
> 		      (lambda (obj)
> 			(format t "~A~%" obj)
> 			))
>   )
>
> I get nothing printed out!

Yes, if there is no current rucksack when the persistent class is
defined, Rucksack will not update any indices for that class.  Rucksack
should probably signal an error in this case, but it doesn't at the
moment.

> If I wrap the DEFCLASS in a WITH-RUCKSACK-AND-TRANSACTION, then it
> works.  I am guessing that at defclass time you must have a open
> rucksack and valid transaction, and that some MOP magic will populate
> a btree index.

Right.  See the file mop.lisp, and in particular the definitions of
UPDATE-INDEXES and around methods for INITIALIZE-INSTANCE and
REINITIALIZE-INSTANCE for PERSISTENT-CLASS.


> This feels quite strange to me, for example it would be common for an
> application to startup with no object store & expect to be able to
> correctly instance indexed objects and have them persist.  Otherwise
> you need to arrange to re-evaluate the defclass form whenever you
> delete your store.
>
> I would expect that when you MAKE-INSTANCE an indexed class Rucksack
> should test to see if the index exists, and if it doesn't it should
> create one.

Hmm, interesting idea.  I've never been very fond of the WITH-RUCKSACK
and WITH-TRANSACTION wrappers around DEFCLASS forms, but somehow I
thought they were necessary.  Maybe you're right and we can get rid of
them.  We already have a call to MAYBE-UPDATE-SLOT-INFO at the start
of the INITIALIZE-INSTANCE around method for PERSISTENT-OBJECT (see
objects.lisp), so maybe we can just add a MAYBE-UPDATE-INDEXES call at
that point.

> I'm new to MOP & haven't looked into this yet.  Any hints on where I
> should look to try & fix this.

Yes: the files and functions I just mentioned.

> Or am I misunderstanding a design feature/goal as a bug?

Initially I thought it was a feature, but maybe you're right and it's
a bug.  I need to think a bit more about this.

Thanks for your feedback,

Arthur




More information about the rucksack-devel mailing list