Package bw :: Package poseidon :: Module diskindex :: Class DiskIndex
[frames] | no frames]

Class DiskIndex

object --+
         |
        DiskIndex

This is the top-level abstract class which defines the interface for all DiskIndexes in use. DiskIndexes are dictionary-like objects and can be accessed and updated by index assignment. However, they are also transaction based and must be committed to save changes to disk. However, they do *not* support MVCC semantics. Storage objects must be careful to acquire a common lock when doing updates.

Instance Methods
 
__init__(self, fn, options)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
 
__setitem__(self, key, value)
Add a key-value pair.
 
update(self, d)
Same as dict.update
 
__getitem__(self, key)
Retrieve the value of a key.
 
__contains__(self, key)
Returns True if key is in the DiskIndex.
 
has_key(self, key)
Same as __contains__
 
get(self, key, failobj=None)
Same as dict.get
 
__len__(self)
Not implemented.
 
__iter__(self)
 
iteritems(self)
 
commit(self)
Commit the DiskIndex.
 
clean(self, oldest)
Clean the cache of old-entries.
 
close(self)
Safely shut down the index.
 
read_disk(self, key)
Read key from disk.

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Properties

Inherited from object: __class__

Method Details

__init__(self, fn, options)
(Constructor)

 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Parameters:
  • fn - The fully qualified pathname of the storage. e.g. "/home/username/brainwave/db/mmap". No extension is provided.
  • options (dict) - A dictionary containing additional options
Overrides: object.__init__

__setitem__(self, key, value)
(Index assignment operator)

 

Add a key-value pair. Does not commit.

__getitem__(self, key)
(Indexing operator)

 

Retrieve the value of a key.

Reads from an internal read-cache before searching on disk.

__contains__(self, key)
(In operator)

 

Returns True if key is in the DiskIndex. Not implemented.

commit(self)

 

Commit the DiskIndex. Not Implemented

clean(self, oldest)

 

Clean the cache of old-entries. Should be run asynchronously in a separate thread. Does *not* lock the dictionary before making modifications. This method is the *only* place where cache entries are removed. If the cache is added to while this method is in progress, the clean will silenty fail with a "Dictionary size changed during iteration" error. This is not a problem. The next time, it will work fine. The idea is that this method should never hog CPU from a main worker thread.

close(self)

 

Safely shut down the index. Not Implemented

read_disk(self, key)

 

Read key from disk. Not implemented

Parameters:
  • key - The key whose value is to be read