File
hstore.rb
Home
Path: hstore.rb
Modified: Mon Dec 29 09:17:08 GMT-7:00 2003

hstore.rb - This is a Hash Store

Copyright: (C) 2000, 2001, 2002, 2003 Seva Inc. and Seva Software - www.sevasoftware.com

License: Same as Ruby

Download: www.sevasoftware.org/hstore/hstore_0_91.tar.gz

Installation procedures:

  tar -zvxf hstore_0_91.tar.gz
  cd hstore_0_91
  ruby install.rb

An HStore stores and retrieves key/value pairs to and from disk similar to a Pstore. An HStore uses two files, an index file containing a Hash of keys and the file position for each object and a data file containing the values in the HStore. The index file is cached in a Hash in memory for fast look-ups. The values are stored in a separate data file and are individually retrieved from disk with [] or fetch() and written back to disk with []= or update()/insert(). The following files are used/created by HStore:

The premise is that the index Hash (filename.hsi) is rewritten only when a new value is inserted, a value is relocated because it no longer fits in it’s current space, or a value is deleted. The values are individually read and written using Marshal.load/dump to/from filename.hs. This should reduce the memory needed by an HStore to the size of the key + pos of the object. The I/O is faster because less data is read/written during a transaction.

The HStore is thread safe and multi-process safe (only if File.flock is supported, it works on linux and Windows 2000). Many concurrent processes or threads can read from an HStore at the same time. Only one process or thread can write to the HStore at the same time. If one process or thread changes the HStore, other readers will reload the index hash at the beginning of the next transaction. Example:

 hs.initialize(filename)
 hs.open{|store| store[key] = value}          # close() is automatically called when open is called with a block

or

 hs.initialize(filename).open
 hs[key] = value                              # automatically starts an implied transaction
 hs.transaction{|store| store[key] = value}   # transactions load data only if it has been changed by another process or thread and yields the HStore
 hs.transaction{|store| store.delete(key)}
 hs.close

Starting a transaction will automatically reloads an updated HStore only when needed.

The HStore is similar to a Pstore. Here are the basic differences:

There is a module called tst/convert_pstore_to_hstore.rb that will read the content of a Pstore and create a HStore.

When to use an HStore/Pstore verses a database server:

Pros compared to a Pstore:

Cons compared to a Pstore:

Create the HTML documentation (required RDoc):

  rdoc --title HStore --template kilmer hstore.rb hstore_backup.rb hstore_restore.rb hstore_compact.rb

Support

Testing

Status

Todo

History

Required files

thread
Classes and Modules

Class HStore
Class HStoreLoc
Class HStoreLockError


Seva Software


Thank you for taking the time to visit this web page. I trust you found the information contained in this page useful.
Please email any questions, concerns, or issues with this web site to webmaster@sevasoftware.com.
Please remember Seva Software when your company would benefit from an experienced database architect and software engineer.

http://www.arunadb.org http://www.locana.org http://www.ruby-lang.org http://www.coolwell.org http://www.sevasoftware.com