[elephant-devel] db gc

Gábor Melis mega at hotpop.com
Sat Feb 19 17:41:43 UTC 2005


On Thursday 18 November 2004 20:02, Ben wrote:
> Writing the GC is long overdue.  There are some technical issues with
> this which have yet to be solved, actually.  In the first pass, it
> will probably require taking the store off-line and running a separate
> gc program on it -- that shouldn't be too hard.  it may be possible to
> write an online collector but as of yet i don't know how to do it.  i
> expect the gc will come with the next release (in a month or so --
> after i'm done teaching this quarter!)

I started hacking on the gc. It works by replacing deserialize with a similar 
function that records the oids instead of calling get-cached-instance and 
reading all slots, key-value pairs in persistent classes and btrees.

(defmethod walk-persistent ((btree btree))
  (map-btree (lambda (key value) (declare (ignore key value)))
             btree
             :degree-2 t))

(defmethod walk-persistent ((obj persistent))
  (let ((class (class-of obj))
        (persistent-effective-slot-definition-class
         (find-class 'persistent-effective-slot-definition)))
    (loop for slot-definition in (class-slots class)
       when (eq (class-of slot-definition)
                persistent-effective-slot-definition-class)
       do (slot-value-using-class class obj slot-definition))))

(defun elephant-gc (&optional (sc *store-controller*))
  (let ((old-oids (make-hash-table))
        (new-oids (make-hash-table)))
    (flet ((marker (controller oid class)
             (declare (ignore controller))
             (unless (gethash oid old-oids)
               (setf (gethash oid new-oids) class))))
      (with-marking-deserialize (#'marker)
        ;; mark the root
        (setf (gethash -1 old-oids)
              (class-name (class-of (controller-root sc))))
        (walk-persistent (controller-root sc))
        ;;
        (loop while (< 0 (hash-table-count new-oids))
           do (maphash (lambda (oid class)
                         (walk-persistent (make-instance class :from-oid oid))
                         (setf (gethash oid old-oids) class))
                       new-oids)
           (clrhash new-oids))))
    ;; now OLD-OIDS contains the oids of all reachable objects
    (maphash (lambda (oid class)
               (format t "~S ~S~%" oid class))
             old-oids)
    ))

It seems to detect live objects OK. The next step is to iterate through 
controller-db and controller-btrees and delete records that have keys 
starting with a non-alive oid, right? Controller-indices and 
controller-indices-assoc can be left alone, I hope.

What are those technical issues you mentioned above?

Can references to a persistent object have different class names (maybe due to 
a change-class)?

G



More information about the elephant-devel mailing list