On 17-Jan-08, at 3:53 PM, Joe Hosteny wrote:
Hi all,
Apologies if this is the wrong place, but it is somewhat Termite specific.
Has anyone taken a close look at Mnesia, to the point of considering doing something like it using Termite? I'm not necessarily thinking of an architectural clone, but perhaps something similarly geared towards horizontal scalability that has native code queries?
Can you refresh my memory concerning the features of Mnesia? ;)
If I recall correctly it is a "in RAM memory" database, and you can dump or restore the database to/from the filesystem. Those operations are possible with Gambit's table datatype (hash tables) and the serialization/deserialization procedures. Here's a simple example.
(define db (make-table))
(define (dump obj fn) (let ((v (object->u8vector obj))) (with-output-to-file fn (lambda () (write-subu8vector v 0 (u8vector-length v))))))
(define (restore fn) (let ((x (call-with-input-file fn (lambda (p) (list->u8vector (read-all p read-u8)))))) (u8vector->object x)))
(define-type hacker id: 1A673423-70D6-4922-92A6-0C2D43DA5CC6 name language proc)
(table-set! db "Marc" (make-hacker "Marc" "Scheme" dump)) (table-set! db "James" (make-hacker "James" "Java" restore)) (table-set! db "Bjarne" (make-hacker "Bjarne" "C++" (lambda (x) x)))
(dump db "mydb")
(define db2 (restore "mydb"))
(define m (table-ref db2 "Marc"))
(pp (hacker-proc m)) ;; prints: (lambda (obj fn) (let ((v ...
Marc
P.S. While trying out this example I noticed a small bug in the deserialization of tables. You'll need to get the latest patch from the Gambit repository for this to work properly.