[gambit-list] Mnesia

Joe Hosteny jhosteny at gmail.com
Fri Jan 18 11:04:58 EST 2008


On Jan 17, 2008, at 10:02 PM, Marc Feeley wrote:

>
> 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.
>

Marc,

	I haven't really dug into a lot of examples with Mnesia, but my  
understanding is that these are some of the main features.

* Embedded
* Allows for replication or distribution of tables
* Transactions (I'm not sure about the full capabilities of these)
* Native data structure storage
* Live backups
* Live schema upgrades

	Here's an overview, published a few years back:

http://www.erlang.se/publications/mnesia_overview.pdf

	I know there's been some traffic on the list about a Scheme web  
framework. I have some interest in this as well, but mainly just for  
applications that could use a distributed DB in a utility environment,  
e.g., on Amazon's EC2 (note: I cross posted to the Snow mailing list  
about work on an EC2 package). It seems to me that a framework could  
have value over something like Rails, though, if it addressed some  
difficulties it currently has, such as scalability of both the web  
server and back end (obviously, the back end is a separate issue from  
Rails). Incidentally, one of the pain points with EC2 currently is its  
lack of persistent storage. So, some method of DB replication, in  
addition to incremental backup, is really necessary.

	I'm also interested in self-configuring compute clusters. I wanted to  
put a feeler out to see if anyone in the Scheme community was working  
on these things, or would like to. I don't really have a background in  
databases, but I do in filesystems and journaling.

Joe

P.S. Are there any Schemers on this list from Pittsburgh?



More information about the Gambit-list mailing list