# Store object in on disk / mini database

**URL:** <https://rubytalk.org/t/store-object-in-on-disk-mini-database/13694>\
**Category:** ruby-talk\
**Created:** [20 September 2004 18:54 UTC](https://rubytalk.org/t/store-object-in-on-disk-mini-database/13694 "2004-09-20T18:54:40Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kristian\_Sorensen](https://avatars.discourse-cdn.com/v4/letter/k/bc8723/32.png) [@Kristian\_Sorensen](https://rubytalk.org/u/Kristian_Sorensen)\
**Post date:** [20 September 2004 18:54 UTC](https://rubytalk.org/t/store-object-in-on-disk-mini-database/13694/1 "2004-09-20T18:54:40Z")

</div>

Hi!

Is there some way of writing e.g. a hash table to the filesystem, and read it again? - Without having to parse in and output (and create the table all over).

I need to store some information, which could be storred in a small database (like sqlite - but I can't get ruby-sqlite installed proporly, if sqlite is not installed in the default location). Is there an interface to the Berkley DB ([www.sleepycat.com](http://www.sleepycat.com))?

Best regards,  
Kristian Sørensen.

---

<div class="post-metadata">

**Author:** ![Lennon\_Day-Reynolds1](https://avatars.discourse-cdn.com/v4/letter/l/5f8ce5/32.png) [@Lennon\_Day-Reynolds1](https://rubytalk.org/u/Lennon_Day-Reynolds1)\
**Post date:** [20 September 2004 19:16 UTC](https://rubytalk.org/t/store-object-in-on-disk-mini-database/13694/2 "2004-09-20T19:16:59Z")

</div>

Kristian,

If you're working with small datasets, you can use the built-in  
'Marshal' module to persist data.

For example, if the variable 'data' contains your hash to be saved,  
you can just do the following:

> **···**
>
> --  
> open('myapp.dat', 'wb') do |fh|  
> &nbsp;&nbsp;Marshal.dump(data, fh)  
> end  
> --
> 
> To load your data later, you can use 'Marshal.load', which will  
> restore an object from either an open filehandle or a string. If you  
> need transactions, take a look at the 'PStore' library, which is part  
> of the standard distribution; it wraps a convenient database-like  
> interface on top of the Marshal methods, complete with transactional  
> access.
> 
> If you don't want to keep everything in RAM, there are also DBM, GDBM,  
> and SDBM bindings in the standard distribution.
> 
> --  
> Lennon  
> [rcoder.net](http://rcoder.net)

---

<div class="post-metadata">

**Author:** ![Ara.T.Howard6](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@Ara.T.Howard6](https://rubytalk.org/u/Ara.T.Howard6)\
**Post date:** [20 September 2004 19:25 UTC](https://rubytalk.org/t/store-object-in-on-disk-mini-database/13694/3 "2004-09-20T19:25:04Z")

</div>

yes. yes.

&nbsp;&nbsp;&nbsp;jib:~ \> cat a.rb  
&nbsp;&nbsp;&nbsp;require 'pstore'

&nbsp;&nbsp;&nbsp;db = PStore::new 'db'

&nbsp;&nbsp;&nbsp;this\_time = Time::now  
&nbsp;&nbsp;&nbsp;last\_time = nil

&nbsp;&nbsp;&nbsp;db.transaction do  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if db.root? 'time'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;last\_time = db['time']  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;db['time'] = this\_time  
&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;puts "this\_time \<#{ this\_time }\>"  
&nbsp;&nbsp;&nbsp;puts "last\_time \<#{ last\_time }\>"

&nbsp;&nbsp;&nbsp;jib:~ \> ruby a.rb  
&nbsp;&nbsp;&nbsp;this\_time \<Mon Sep 20 13:05:29 MDT 2004\>  
&nbsp;&nbsp;&nbsp;last\_time \<\>

&nbsp;&nbsp;&nbsp;jib:~ \> ruby a.rb  
&nbsp;&nbsp;&nbsp;this\_time \<Mon Sep 20 13:05:33 MDT 2004\>  
&nbsp;&nbsp;&nbsp;last\_time \<Mon Sep 20 13:05:29 MDT 2004\>

&nbsp;&nbsp;&nbsp;jib:~ \> ruby a.rb  
&nbsp;&nbsp;&nbsp;this\_time \<Mon Sep 20 13:05:38 MDT 2004\>  
&nbsp;&nbsp;&nbsp;last\_time \<Mon Sep 20 13:05:33 MDT 2004\>

&nbsp;&nbsp;&nbsp;jib:~ \> cat b.rb  
&nbsp;&nbsp;&nbsp;require 'bdb'

&nbsp;&nbsp;&nbsp;db = BDB::Btree.open "bdb", nil, BDB::CREATE, 0644

&nbsp;&nbsp;&nbsp;this\_time = Time::now  
&nbsp;&nbsp;&nbsp;last\_time = nil

&nbsp;&nbsp;&nbsp;last\_time = db['time']  
&nbsp;&nbsp;&nbsp;db['time'] = this\_time

&nbsp;&nbsp;&nbsp;puts "this\_time \<#{ this\_time }\>"  
&nbsp;&nbsp;&nbsp;puts "last\_time \<#{ last\_time }\>"

&nbsp;&nbsp;&nbsp;db.close

&nbsp;&nbsp;&nbsp;jib:~ \> ruby b.rb  
&nbsp;&nbsp;&nbsp;this\_time \<Mon Sep 20 13:10:55 MDT 2004\>  
&nbsp;&nbsp;&nbsp;last\_time \<\>

&nbsp;&nbsp;&nbsp;jib:~ \> ruby b.rb  
&nbsp;&nbsp;&nbsp;this\_time \<Mon Sep 20 13:10:56 MDT 2004\>  
&nbsp;&nbsp;&nbsp;last\_time \<Mon Sep 20 13:10:55 MDT 2004\>

&nbsp;&nbsp;&nbsp;jib:~ \> ruby b.rb  
&nbsp;&nbsp;&nbsp;this\_time \<Mon Sep 20 13:11:01 MDT 2004\>  
&nbsp;&nbsp;&nbsp;last\_time \<Mon Sep 20 13:10:56 MDT 2004\>

regards.

-a

> **···**
>
> On Mon, 20 Sep 2004, [ISO-8859-1] Kristian Sørensen wrote:
> 
> > Hi!
> > 
> > Is there some way of writing e.g. a hash table to the filesystem, and read  
> > it again? - Without having to parse in and output (and create the table all  
> > over).
> > 
> > I need to store some information, which could be storred in a small database  
> > (like sqlite - but I can't get ruby-sqlite installed proporly, if sqlite is  
> > not installed in the default location). Is there an interface to the Berkley  
> > DB (www.sleepycat.com)?
> > 
> > Best regards,  
> > Kristian Sørensen.
> 
> # --
> 
> > EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov  
> > PHONE :: 303.497.6469  
> > A flower falls, even though we love it;  
> > and a weed grows, even though we do not love it. --Dogen
> 
> ===============================================================================

---

<div class="post-metadata">

**Author:** ![Kristian\_Sorensen](https://avatars.discourse-cdn.com/v4/letter/k/bc8723/32.png) [@Kristian\_Sorensen](https://rubytalk.org/u/Kristian_Sorensen)\
**Post date:** [20 September 2004 20:14 UTC](https://rubytalk.org/t/store-object-in-on-disk-mini-database/13694/4 "2004-09-20T20:14:38Z")

</div>

Thanks for both your suggestions! That was just what I needed! 🙂

Kristian Sørensen wrote:

> **···**
>
> > Hi!
> > 
> > Is there some way of writing e.g. a hash table to the filesystem, and read it again? - Without having to parse in and output (and create the table all over).
> > 
> > I need to store some information, which could be storred in a small database (like sqlite - but I can't get ruby-sqlite installed proporly, if sqlite is not installed in the default location). Is there an interface to the Berkley DB (www.sleepycat.com)?
> > 
> > Best regards,  
> > Kristian Sørensen.

---

<div class="post-metadata">

**Author:** ![T\_Onoma](https://avatars.discourse-cdn.com/v4/letter/t/c2a13f/32.png) [@T\_Onoma](https://rubytalk.org/u/T_Onoma)\
**Post date:** [20 September 2004 20:37 UTC](https://rubytalk.org/t/store-object-in-on-disk-mini-database/13694/5 "2004-09-20T20:37:17Z")

</div>

There's also YAML.

&nbsp;&nbsp;require 'yaml'

&nbsp;&nbsp;# save  
&nbsp;&nbsp;open('myapp.dat', 'w') {|fh| fh \<\< data.to\_yaml }

&nbsp;&nbsp;# retrieve  
&nbsp;&nbsp;data = YAML.load(File.open('myapp.dat'))

[Note: This is off th top of my head, so it's untested. But basically like  
that.]

Nice thing about YAML is that the file it creates is human readable and  
editable!

T.

> **···**
>
> On Monday 20 September 2004 04:14 pm, Kristian Sørensen wrote:
> 
> > Thanks for both your suggestions! That was just what I needed! 🙂

---

<div class="post-metadata">

**Author:** ![Bill\_Kelly](https://avatars.discourse-cdn.com/v4/letter/b/cc9497/32.png) [@Bill\_Kelly](https://rubytalk.org/u/Bill_Kelly)\
**Post date:** [20 September 2004 20:52 UTC](https://rubytalk.org/t/store-object-in-on-disk-mini-database/13694/6 "2004-09-20T20:52:02Z")

</div>

> \> Thanks for both your suggestions! That was just what I needed! 🙂
> 
> There's also YAML.

[...]

> Nice thing about YAML is that the file it creates is human readable and  
> editable!

Additionally YAML supports a drop-in PStore equivalent, so if your code  
is already structured to use PStore, you can a YAML::Store the same way.

require 'yaml/store'

ystore = YAML::Store.new("my\_datafile.ystore")

# use ystore just as you would a pstore:

my\_hash = {"a"=\>1, "b"=\>2}  
my\_array = %w(dog cat elephant)

# store stuff in the database

ystore.transaction do  
&nbsp;&nbsp;ystore["my\_hash"] = my\_hash  
&nbsp;&nbsp;ystore["my\_array"] = my\_array  
end

# print out all keys/values in database

ystore.transaction do  
&nbsp;&nbsp;ystore.roots.each do |key|  
&nbsp;&nbsp;&nbsp;&nbsp;puts ystore[key].inspect  
&nbsp;&nbsp;end  
end

# note the above code is untested

Regards,

Bill

> **···**
>
> From: "trans. (T. Onoma)" \<transami@runbox.com\>
> 
> > On Monday 20 September 2004 04:14 pm, Kristian Sørensen wrote:

---

<div class="post-metadata">

**Author:** ![James\_Britt6](https://avatars.discourse-cdn.com/v4/letter/j/a87d85/32.png) [@James\_Britt6](https://rubytalk.org/u/James_Britt6)\
**Post date:** [20 September 2004 22:44 UTC](https://rubytalk.org/t/store-object-in-on-disk-mini-database/13694/7 "2004-09-20T22:44:33Z")

</div>

trans. (T. Onoma) wrote:

> **···**
>
> > On Monday 20 September 2004 04:14 pm, Kristian Sørensen wrote:
> > 
> > > Thanks for both your suggestions! That was just what I needed! 🙂
> > 
> > There's also YAML.
> > 
> > &nbsp;&nbsp;require 'yaml'
> > 
> > &nbsp;&nbsp;# save  
> > &nbsp;&nbsp;open('myapp.dat', 'w') {|fh| fh \<\< data.to\_yaml }
> > 
> > &nbsp;&nbsp;# retrieve  
> > &nbsp;&nbsp;data = YAML.load(File.open('myapp.dat'))
> > 
> > [Note: This is off th top of my head, so it's untested. But basically like that.]
> > 
> > Nice thing about YAML is that the file it creates is human readable and editable!
> 
> But you still reparse the data, which the OP wanted to avoid.
> 
> James

---

<div class="post-metadata">

**Author:** ![Ara.T.Howard6](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@Ara.T.Howard6](https://rubytalk.org/u/Ara.T.Howard6)\
**Post date:** [20 September 2004 21:24 UTC](https://rubytalk.org/t/store-object-in-on-disk-mini-database/13694/8 "2004-09-20T21:24:39Z")

</div>

yes - yaml is very, very cool - i use it alot for my own code. a couple of  
things to be aware of

&nbsp;&nbsp;&nbsp;- yaml is alot slower than marshal. if your db has only 10,000 entries or  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;so this no problem

&nbsp;&nbsp;&nbsp;- flock does not work on nfs filesystems (used by pstore an  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;yaml::store)

-a

> **···**
>
> On Tue, 21 Sep 2004, Bill Kelly wrote:
> 
> > From: "trans. (T. Onoma)" \<transami@runbox.com\>
> > 
> > > On Monday 20 September 2004 04:14 pm, Kristian Sørensen wrote:
> > > 
> > > > Thanks for both your suggestions! That was just what I needed! 🙂
> > > 
> > > There's also YAML.
> > 
> > [...]
> > 
> > > Nice thing about YAML is that the file it creates is human readable and  
> > > editable!
> > 
> > Additionally YAML supports a drop-in PStore equivalent, so if your code  
> > is already structured to use PStore, you can a YAML::Store the same way.
> > 
> > require 'yaml/store'
> > 
> > ystore = YAML::Store.new("my\_datafile.ystore")
> > 
> > # use ystore just as you would a pstore:
> > 
> > my\_hash = {"a"=\>1, "b"=\>2}  
> > my\_array = %w(dog cat elephant)
> > 
> > # store stuff in the database
> > 
> > ystore.transaction do  
> > ystore["my\_hash"] = my\_hash  
> > ystore["my\_array"] = my\_array  
> > end
> > 
> > # print out all keys/values in database
> > 
> > ystore.transaction do  
> > ystore.roots.each do |key|  
> > &nbsp;&nbsp;&nbsp;puts ystore[key].inspect  
> > end  
> > end
> > 
> > # note the above code is untested
> 
> # --
> 
> > EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov  
> > PHONE :: 303.497.6469  
> > A flower falls, even though we love it;  
> > and a weed grows, even though we do not love it. --Dogen
> 
> ===============================================================================

---

<div class="post-metadata">

**Author:** ![Kristian\_Sorensen](https://avatars.discourse-cdn.com/v4/letter/k/bc8723/32.png) [@Kristian\_Sorensen](https://rubytalk.org/u/Kristian_Sorensen)\
**Post date:** [20 September 2004 21:44 UTC](https://rubytalk.org/t/store-object-in-on-disk-mini-database/13694/9 "2004-09-20T21:44:40Z")

</div>

Hi!

This sounds VERY cool! I will definitly have a look at this tomorrow!! Thanks! 😃

Cheers, KS.

Bill Kelly wrote:

> **···**
>
> > From: "trans. (T. Onoma)" \<transami@runbox.com\>
> > 
> > > On Monday 20 September 2004 04:14 pm, Kristian Sørensen wrote:
> > > 
> > > > Thanks for both your suggestions! That was just what I needed! 🙂
> > > 
> > > There's also YAML.
> > 
> > [...]
> > 
> > > Nice thing about YAML is that the file it creates is human readable and  
> > > editable!
> > 
> > Additionally YAML supports a drop-in PStore equivalent, so if your code  
> > is already structured to use PStore, you can a YAML::Store the same way.
> > 
> > require 'yaml/store'
> > 
> > ystore = YAML::Store.new("my\_datafile.ystore")
> > 
> > # use ystore just as you would a pstore:
> > 
> > my\_hash = {"a"=\>1, "b"=\>2}  
> > my\_array = %w(dog cat elephant)
> > 
> > # store stuff in the database
> > 
> > ystore.transaction do  
> > &nbsp;&nbsp;ystore["my\_hash"] = my\_hash  
> > &nbsp;&nbsp;ystore["my\_array"] = my\_array  
> > end
> > 
> > # print out all keys/values in database
> > 
> > ystore.transaction do  
> > &nbsp;&nbsp;ystore.roots.each do |key|  
> > &nbsp;&nbsp;&nbsp;&nbsp;puts ystore[key].inspect  
> > &nbsp;&nbsp;end  
> > end
> > 
> > # note the above code is untested
> > 
> > Regards,
> > 
> > Bill

---

<div class="post-metadata">

**Author:** ![T\_Onoma](https://avatars.discourse-cdn.com/v4/letter/t/c2a13f/32.png) [@T\_Onoma](https://rubytalk.org/u/T_Onoma)\
**Post date:** [20 September 2004 22:49 UTC](https://rubytalk.org/t/store-object-in-on-disk-mini-database/13694/10 "2004-09-20T22:49:21Z")

</div>

Ah, shucks!! 🙂 Although, I imagine you reparse at some level no matter what.  
But certainly Marshal is closer to the metal.

> **···**
>
> On Monday 20 September 2004 06:44 pm, James Britt wrote:
> 
> > But you still reparse the data, which the OP wanted to avoid.
> 
> --  
> ( o \_ カラチ  
> // trans.  
> / \ transami@runbox.com
> 
> I don't give a damn for a man that can only spell a word one way.  
> -Mark Twain

---

<div class="post-metadata">

**Author:** ![Bill\_Kelly](https://avatars.discourse-cdn.com/v4/letter/b/cc9497/32.png) [@Bill\_Kelly](https://rubytalk.org/u/Bill_Kelly)\
**Post date:** [21 September 2004 00:31 UTC](https://rubytalk.org/t/store-object-in-on-disk-mini-database/13694/11 "2004-09-21T00:31:01Z")

</div>

> \> Nice thing about YAML is that the file it creates is human readable and  
> \> editable!
> 
> But you still reparse the data, which the OP wanted to avoid.

I'd thought the OP didn't want to manually write the code to parse keys  
and values from a text file.... 🙂 (As opposed to behind-the-scenes  
parsing going on in a library...)

But IANTOP ;-D

Regards,

Bill

> **···**
>
> From: "James Britt" \<jamesUNDERBARb@neurogami.com\>

---

<div class="post-metadata">

**Author:** ![Mauricio\_Fernndez](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@Mauricio\_Fernndez](https://rubytalk.org/u/Mauricio_Fernndez)\
**Post date:** [20 September 2004 21:37 UTC](https://rubytalk.org/t/store-object-in-on-disk-mini-database/13694/12 "2004-09-20T21:37:54Z")

</div>

- syck crashes quite often ☹

> **···**
>
> On Tue, Sep 21, 2004 at 06:24:39AM +0900, Ara.T.Howard@noaa.gov wrote:
> 
> > yes - yaml is very, very cool - i use it alot for my own code. a couple of  
> > things to be aware of
> > 
> > &nbsp;&nbsp;- yaml is alot slower than marshal. if your db has only 10,000 entries or  
> > &nbsp;&nbsp;&nbsp;&nbsp;so this no problem
> > 
> > &nbsp;&nbsp;- flock does not work on nfs filesystems (used by pstore an  
> > &nbsp;&nbsp;&nbsp;&nbsp;yaml::store)
> 
> --  
> Running Debian GNU/Linux Sid (unstable)  
> batsman dot geo at yahoo dot com

---

<div class="post-metadata">

**Author:** ![why\_the\_lucky\_stiff1](https://avatars.discourse-cdn.com/v4/letter/w/898d66/32.png) [@why\_the\_lucky\_stiff1](https://rubytalk.org/u/why_the_lucky_stiff1)\
**Post date:** [20 September 2004 21:49 UTC](https://rubytalk.org/t/store-object-in-on-disk-mini-database/13694/13 "2004-09-20T21:49:41Z")

</div>

Mauricio Fernández wrote:

> - syck crashes quite often ☹

Are you refering to the bug you found while working on rpa? [ruby-core:02729] Or are you alluding to other bugs?

\_why

---

<div class="post-metadata">

**Author:** ![Mauricio\_Fernndez](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@Mauricio\_Fernndez](https://rubytalk.org/u/Mauricio_Fernndez)\
**Post date:** [20 September 2004 22:28 UTC](https://rubytalk.org/t/store-object-in-on-disk-mini-database/13694/14 "2004-09-20T22:28:25Z")

</div>

Other bugs that look similar (assuming you fixed that one). And I've  
had syck-related bugs with rpa-base quite recently (with some 1.8.2  
CVS version).

I also have a proof of concept for a versioned FS datastore that  
has the very nice property of crashing syck in no time 🙂  
It's been a few weeks since I last tested it, but I hope its magic  
still works -- if so, you can expect a copy in short.

> **···**
>
> On Tue, Sep 21, 2004 at 06:49:41AM +0900, why the lucky stiff wrote:
> 
> > Mauricio Fernández wrote:
> > 
> > \>- syck crashes quite often ☹  
> > \>  
> > \>  
> > Are you refering to the bug you found while working on rpa?  
> > [ruby-core:02729] Or are you alluding to other bugs?
> 
> --  
> Running Debian GNU/Linux Sid (unstable)  
> batsman dot geo at yahoo dot com

---

<div class="post-metadata">

**Author:** ![Ara.T.Howard6](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@Ara.T.Howard6](https://rubytalk.org/u/Ara.T.Howard6)\
**Post date:** [20 September 2004 22:44 UTC](https://rubytalk.org/t/store-object-in-on-disk-mini-database/13694/15 "2004-09-20T22:44:39Z")

</div>

have you seen this?

[http://repetae.net/~john/computer/vsdb/](http://repetae.net/~john/computer/vsdb/)

super cool idea - but crashes alot. i have a little c binding for testing  
only if you are interested. what's the concept of your fs db?

cheers.

-a

> **···**
>
> On Tue, 21 Sep 2004, Mauricio [iso-8859-1] Fernández wrote:
> 
> > I also have a proof of concept for a versioned FS datastore that has the  
> > very nice property of crashing syck in no time 🙂 It's been a few weeks  
> > since I last tested it, but I hope its magic still works -- if so, you can  
> > expect a copy in short.
> 
> # --
> 
> > EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov  
> > PHONE :: 303.497.6469  
> > A flower falls, even though we love it;  
> > and a weed grows, even though we do not love it. --Dogen
> 
> ===============================================================================

---

<div class="post-metadata">

**Author:** ![Mauricio\_Fernndez](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@Mauricio\_Fernndez](https://rubytalk.org/u/Mauricio_Fernndez)\
**Post date:** [20 September 2004 23:24 UTC](https://rubytalk.org/t/store-object-in-on-disk-mini-database/13694/16 "2004-09-20T23:24:20Z")

</div>

> have you seen this?
> 
> [http://repetae.net/~john/computer/vsdb/](http://repetae.net/~john/computer/vsdb/)
> 
> super cool idea - but crashes alot. i have a little c binding for testing

heh looks like [http://cr.yp.to/cdb.html](http://cr.yp.to/cdb.html) with rewrite-on-update (have to  
read the code to make sure but it's 1am)  
I believe something like rdbm would be better ([http://www.fefe.de/rdbm/\](http://www.fefe.de/rdbm/%5C)).

> only if you are interested. what's the concept of your fs db?

I first learned about this approach via Eivind Eklund when talking about  
OVCS. It's the method used by Subversion and monotone (AFAIR): index  
data by its digest. A number of interesting things happen when you do so:  
\* full-tree versioning  
\* "implicit deltas" and fairly efficient compression of the data  
\* ...

I implemented a toy version control system on top of that which could host  
itself in a couple days and ~500LoCs; it had O(1) branching, could manage  
renaming, used implicit deltas and transparent compression of the data.

This can work on top of any structure able to hold key -\> value  
associations (where both are strings), so you can use any of the dbs  
(gdbm, ndbm, sdbm, bdb, etc) or even a full-fledged rdbms if you want  
(as done by monotone), but it could also work in-mem with a simple Hash  
and serialization via Marshal, etc...

> **···**
>
> On Tue, Sep 21, 2004 at 07:44:39AM +0900, Ara.T.Howard@noaa.gov wrote:
> 
> --  
> Running Debian GNU/Linux Sid (unstable)  
> batsman dot geo at yahoo dot com

---

<div class="post-metadata">

**Author:** ![Ara.T.Howard6](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@Ara.T.Howard6](https://rubytalk.org/u/Ara.T.Howard6)\
**Post date:** [21 September 2004 03:24 UTC](https://rubytalk.org/t/store-object-in-on-disk-mini-database/13694/17 "2004-09-21T03:24:41Z")

</div>

> heh looks like [http://cr.yp.to/cdb.html](http://cr.yp.to/cdb.html) with rewrite-on-update (have to read  
> the code to make sure but it's 1am)

yes - true.

> I believe something like rdbm would be better ([http://www.fefe.de/rdbm/\](http://www.fefe.de/rdbm/%5C)).

perhaps not as nfs safe...

> I first learned about this approach via Eivind Eklund when talking about  
> OVCS. It's the method used by Subversion and monotone (AFAIR): index  
> data by its digest. A number of interesting things happen when you do so:  
> \* full-tree versioning  
> \* "implicit deltas" and fairly efficient compression of the data  
> \* ...
> 
> I implemented a toy version control system on top of that which could host  
> itself in a couple days and ~500LoCs; it had O(1) branching, could manage  
> renaming, used implicit deltas and transparent compression of the data.

sound very cool.

> This can work on top of any structure able to hold key -\> value  
> associations (where both are strings), so you can use any of the dbs (gdbm,  
> ndbm, sdbm, bdb, etc) or even a full-fledged rdbms if you want (as done by  
> monotone), but it could also work in-mem with a simple Hash and  
> serialization via Marshal, etc...

any pointers to read about? sounds like a very interesting concept.

-a

> **···**
>
> # On Tue, 21 Sep 2004, Mauricio [iso-8859-1] Fernández wrote: --
> 
> > EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov  
> > PHONE :: 303.497.6469  
> > A flower falls, even though we love it;  
> > and a weed grows, even though we do not love it. --Dogen
> 
> ===============================================================================

---

<div class="post-metadata">

**Author:** ![Dick\_Davies1](https://avatars.discourse-cdn.com/v4/letter/d/22d042/32.png) [@Dick\_Davies1](https://rubytalk.org/u/Dick_Davies1)\
**Post date:** [21 September 2004 09:24 UTC](https://rubytalk.org/t/store-object-in-on-disk-mini-database/13694/18 "2004-09-21T09:24:52Z")

</div>

\* Mauricio Fern?ndez \<batsman.geo@yahoo.com\> [0924 00:24]:

> **···**
>
> > On Tue, Sep 21, 2004 at 07:44:39AM +0900, Ara.T.Howard@noaa.gov wrote:  
> > \> have you seen this?  
> > \>  
> > \> [http://repetae.net/~john/computer/vsdb/](http://repetae.net/~john/computer/vsdb/)  
> > \>  
> > \> super cool idea - but crashes alot. i have a little c binding for testing
> > 
> > heh looks like [http://cr.yp.to/cdb.html](http://cr.yp.to/cdb.html) with rewrite-on-update (have to  
> > read the code to make sure but it's 1am)  
> > I believe something like rdbm would be better ([http://www.fefe.de/rdbm/\](http://www.fefe.de/rdbm/%5C)).
> > 
> > \> only if you are interested. what's the concept of your fs db?
> > 
> > I first learned about this approach via Eivind Eklund when talking about  
> > OVCS. It's the method used by Subversion and monotone (AFAIR): index  
> > data by its digest. A number of interesting things happen when you do so:  
> > \* full-tree versioning  
> > \* "implicit deltas" and fairly efficient compression of the data  
> > \* ...
> 
> By 'index by digest', do you mean something like Venti:
> 
> [http://www.cs.bell-labs.com/sys/doc/venti/venti.html](http://www.cs.bell-labs.com/sys/doc/venti/venti.html)
> 
> ? I tried playing with a ruby-based version of this a while ago, but couldn't  
> find a good way of chopping up files to store them efficiently.....
> 
> --  
> In order to make an apple pie from scratch, you must first create the  
> universe.  
> &nbsp;&nbsp;&nbsp;&nbsp;-- Carl Sagan, Cosmos  
> Rasputin :: Jack of All Trades - Master of Nuns

---

<div class="post-metadata">

**Author:** ![Mauricio\_Fernndez](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@Mauricio\_Fernndez](https://rubytalk.org/u/Mauricio_Fernndez)\
**Post date:** [21 September 2004 19:25 UTC](https://rubytalk.org/t/store-object-in-on-disk-mini-database/13694/19 "2004-09-21T19:25:00Z")

</div>

> \> I first learned about this approach via Eivind Eklund when talking about  
> \> OVCS. It's the method used by Subversion and monotone (AFAIR): index  
> \> data by its digest. A number of interesting things happen when you do so:  
> \> \* full-tree versioning  
> \> \* "implicit deltas" and fairly efficient compression of the data  
> \> \* ...
> 
> By 'index by digest', do you mean something like Venti:
> 
> [http://www.cs.bell-labs.com/sys/doc/venti/venti.html](http://www.cs.bell-labs.com/sys/doc/venti/venti.html)

Yes, the fundamental idea is the same.

> ? I tried playing with a ruby-based version of this a while ago, but couldn't  
> find a good way of chopping up files to store them efficiently.....

A moving CRC will do, e.g.

&nbsp;&nbsp;if crc(buffer, offset, CRCLEN) % AVERAGE\_LENGTH == 1  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chop up to current offset  
&nbsp;&nbsp;&nbsp;insert fragment  
&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;offset += 1  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;... logic if offset \>= MAX\_FRAGMENT\_SIZE ...  
&nbsp;&nbsp;end

that gives you chunks of length averaging AVERAGE\_LENGTH, in most  
cases. Lower values mean higher P(node reuse) but there's a per-chunk overhead  
(key + pointer to it in a list, etc).

> **···**
>
> On Tue, Sep 21, 2004 at 06:24:52PM +0900, Dick Davies wrote:
> 
> --  
> Running Debian GNU/Linux Sid (unstable)  
> batsman dot geo at yahoo dot com
