voldemort.store.memory
Class InMemoryStorageEngine<K,V,T>

java.lang.Object
  extended by voldemort.store.AbstractStore<K,V,T>
      extended by voldemort.store.AbstractStorageEngine<K,V,T>
          extended by voldemort.store.memory.InMemoryStorageEngine<K,V,T>
All Implemented Interfaces:
StorageEngine<K,V,T>, Store<K,V,T>

public class InMemoryStorageEngine<K,V,T>
extends AbstractStorageEngine<K,V,T>

A simple non-persistent, in-memory store. Useful for unit testing. TODO Rewrite this class using striped locks for more granular locking.


Field Summary
protected  java.util.concurrent.ConcurrentMap<K,java.util.List<Versioned<V>>> map
           
 
Constructor Summary
InMemoryStorageEngine(java.lang.String name)
           
InMemoryStorageEngine(java.lang.String name, java.util.concurrent.ConcurrentMap<K,java.util.List<Versioned<V>>> map)
           
 
Method Summary
 boolean delete(K key)
           
 boolean delete(K key, Version version)
          Delete all entries prior to the given version
 void deleteAll()
           
 ClosableIterator<Pair<K,Versioned<V>>> entries()
          Get an iterator over pairs of entries in the store.
 ClosableIterator<Pair<K,Versioned<V>>> entries(int partition)
          Get an iterator over pairs of entries in a store's partition.
 java.util.List<Versioned<V>> get(K key, T transform)
          Get the value associated with the given key
 java.util.Map<K,java.util.List<Versioned<V>>> getAll(java.lang.Iterable<K> keys, java.util.Map<K,T> transforms)
          Get the values associated with the given keys and returns them in a Map of keys to a list of versioned values.
 java.util.List<Version> getVersions(K key)
          Get the versions associated with the given key.
 ClosableIterator<K> keys()
          Get an iterator over keys in the store.
 ClosableIterator<K> keys(int partition)
          Get an iterator over keys in the store's partition Note that the iterator need not be threadsafe, and that it must be manually closed after use.
 java.util.List<Versioned<V>> multiVersionPut(K key, java.util.List<Versioned<V>> values)
          Atomically update storage with the list of versioned values for the given key, to improve storage efficiency.
 void put(K key, Versioned<V> value, T transforms)
          Associate the value with the key and version in this store
 java.lang.String toString()
           
 java.lang.String toString(int size)
           
 void truncate()
          Truncate all entries in the store
 
Methods inherited from class voldemort.store.AbstractStorageEngine
beginBatchModifications, endBatchModifications, isPartitionAware, isPartitionScanSupported, resolveAndConstructVersionsToPersist
 
Methods inherited from class voldemort.store.AbstractStore
close, delete, get, getAll, getCapability, getName, put
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface voldemort.store.Store
close, delete, get, getAll, getCapability, getName, put
 

Field Detail

map

protected final java.util.concurrent.ConcurrentMap<K,java.util.List<Versioned<V>>> map
Constructor Detail

InMemoryStorageEngine

public InMemoryStorageEngine(java.lang.String name)

InMemoryStorageEngine

public InMemoryStorageEngine(java.lang.String name,
                             java.util.concurrent.ConcurrentMap<K,java.util.List<Versioned<V>>> map)
Method Detail

deleteAll

public void deleteAll()

delete

public boolean delete(K key)

delete

public boolean delete(K key,
                      Version version)
Description copied from interface: Store
Delete all entries prior to the given version

Specified by:
delete in interface Store<K,V,T>
Overrides:
delete in class AbstractStore<K,V,T>
Parameters:
key - The key to delete
version - The current value of the key
Returns:
True if anything was deleted

getVersions

public java.util.List<Version> getVersions(K key)
Description copied from interface: Store
Get the versions associated with the given key. This is used in a put call to write a new value for this key

Specified by:
getVersions in interface Store<K,V,T>
Overrides:
getVersions in class AbstractStore<K,V,T>
Parameters:
key - The key to retrieve the versions for
Returns:
List of Versions associated with this key.

get

public java.util.List<Versioned<V>> get(K key,
                                        T transform)
                                 throws VoldemortException
Description copied from interface: Store
Get the value associated with the given key

Specified by:
get in interface Store<K,V,T>
Overrides:
get in class AbstractStore<K,V,T>
Parameters:
key - The key to check for
Returns:
The value associated with the key or an empty list if no values are found.
Throws:
VoldemortException

getAll

public java.util.Map<K,java.util.List<Versioned<V>>> getAll(java.lang.Iterable<K> keys,
                                                            java.util.Map<K,T> transforms)
                                                     throws VoldemortException
Description copied from interface: Store
Get the values associated with the given keys and returns them in a Map of keys to a list of versioned values. Note that the returned map will only contain entries for the keys which have a value associated with them.

Specified by:
getAll in interface Store<K,V,T>
Overrides:
getAll in class AbstractStore<K,V,T>
Parameters:
keys - The keys to check for.
Returns:
A Map of keys to a list of versioned values.
Throws:
VoldemortException

put

public void put(K key,
                Versioned<V> value,
                T transforms)
         throws VoldemortException
Description copied from interface: Store
Associate the value with the key and version in this store

Specified by:
put in interface Store<K,V,T>
Overrides:
put in class AbstractStore<K,V,T>
Parameters:
key - The key to use
value - The value to store and its version.
Throws:
VoldemortException

multiVersionPut

public java.util.List<Versioned<V>> multiVersionPut(K key,
                                                    java.util.List<Versioned<V>> values)
Description copied from interface: StorageEngine
Atomically update storage with the list of versioned values for the given key, to improve storage efficiency.

Specified by:
multiVersionPut in interface StorageEngine<K,V,T>
Overrides:
multiVersionPut in class AbstractStorageEngine<K,V,T>
Parameters:
key - Key to write
values - List of versioned values to be written atomically.
Returns:
list of obsolete versions that were rejected

entries

public ClosableIterator<Pair<K,Versioned<V>>> entries()
Description copied from interface: StorageEngine
Get an iterator over pairs of entries in the store. The key is the first element in the pair and the versioned value is the second element. Note that the iterator need not be threadsafe, and that it must be manually closed after use.

Specified by:
entries in interface StorageEngine<K,V,T>
Overrides:
entries in class AbstractStorageEngine<K,V,T>
Returns:
An iterator over the entries in this StorageEngine.

keys

public ClosableIterator<K> keys()
Description copied from interface: StorageEngine
Get an iterator over keys in the store. Note that the iterator need not be threadsafe, and that it must be manually closed after use.

Specified by:
keys in interface StorageEngine<K,V,T>
Overrides:
keys in class AbstractStorageEngine<K,V,T>
Returns:
An iterator over the keys in this StorageEngine.

entries

public ClosableIterator<Pair<K,Versioned<V>>> entries(int partition)
Description copied from interface: StorageEngine
Get an iterator over pairs of entries in a store's partition. The key is the first element in the pair and the versioned value is the second element. Note that the iterator need not be threadsafe, and that it must be manually closed after use.

Specified by:
entries in interface StorageEngine<K,V,T>
Overrides:
entries in class AbstractStorageEngine<K,V,T>
Parameters:
partition - partition whose entries are to be fetched
Returns:
An iterator over the entries in this StorageEngine.

keys

public ClosableIterator<K> keys(int partition)
Description copied from interface: StorageEngine
Get an iterator over keys in the store's partition Note that the iterator need not be threadsafe, and that it must be manually closed after use.

Specified by:
keys in interface StorageEngine<K,V,T>
Overrides:
keys in class AbstractStorageEngine<K,V,T>
Parameters:
partition - partition whose keys are to be fetched
Returns:
An iterator over the keys in this StorageEngine.

truncate

public void truncate()
Description copied from interface: StorageEngine
Truncate all entries in the store

Specified by:
truncate in interface StorageEngine<K,V,T>
Overrides:
truncate in class AbstractStorageEngine<K,V,T>

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(int size)


Jay Kreps, Roshan Sumbaly, Alex Feinberg, Bhupesh Bansal, Lei Gao, Chinmay Soman, Vinoth Chandar, Zhongjie Wu