krati.store
Class DynamicDataStore

java.lang.Object
  extended by krati.store.DynamicDataStore
All Implemented Interfaces:
Iterable<Map.Entry<byte[],byte[]>>, DataStore<byte[],byte[]>

public class DynamicDataStore
extends Object
implements DataStore<byte[],byte[]>

DynamicDataStore is implemented using Linear Hashing. Its capacity grows as needed. The key-value pairs are stored in the underlying DataArray using the following format:

 [count:int][key-length:int][key:bytes][value-length:int][value:bytes][key-length:int][key:bytes][value-length:int][value:bytes]...
            +------------------ key-value pair 1 ---------------------+------------------- key-value pair 2 -------------------+
 

Author:
jwu

Constructor Summary
DynamicDataStore(File homeDir, int initLevel, int entrySize, int maxEntries, int segmentFileSizeMB, SegmentFactory segmentFactory)
          Creates a dynamic DataStore with the settings below:
DynamicDataStore(File homeDir, int initLevel, int entrySize, int maxEntries, int segmentFileSizeMB, SegmentFactory segmentFactory, double segmentCompactFactor, double hashLoadThreshold, HashFunction<byte[]> hashFunction)
          Creates a dynamic DataStore.
DynamicDataStore(File homeDir, int initLevel, int entrySize, int maxEntries, int segmentFileSizeMB, SegmentFactory segmentFactory, double hashLoadThreshold, HashFunction<byte[]> hashFunction)
          Creates a dynamic DataStore.
DynamicDataStore(File homeDir, int initLevel, int segmentFileSizeMB, SegmentFactory segmentFactory)
          Creates a dynamic DataStore with the settings below:
DynamicDataStore(File homeDir, int initLevel, int segmentFileSizeMB, SegmentFactory segmentFactory, double hashLoadThreshold, HashFunction<byte[]> hashFunction)
          Creates a dynamic DataStore with the settings below:
DynamicDataStore(File homeDir, int initLevel, SegmentFactory segmentFactory)
          Creates a dynamic DataStore with the settings below:
DynamicDataStore(File homeDir, int initLevel, SegmentFactory segmentFactory, HashFunction<byte[]> hashFunction)
          Creates a dynamic DataStore with the settings below:
DynamicDataStore(File homeDir, SegmentFactory segmentFactory)
          Creates a dynamic DataStore with the settings below:
 
Method Summary
 void clear()
           
protected  DynamicLongArray createAddressArray(int entrySize, int maxEntries, File homeDirectory)
           
 boolean delete(byte[] key)
           
protected  boolean deleteInternal(int index, byte[] key)
           
 byte[] get(byte[] key)
           
 int getCapacity()
           
 DataArray getDataArray()
           
protected  int getIndex(byte[] key)
           
protected  int getIndex(long hashCode)
           
 int getLevel()
           
 int getLevelCapacity()
           
 int getLoadCount()
           
 double getLoadFactor()
           
 double getLoadThreshold()
           
 int getSplit()
           
 String getStatus()
           
 int getUnitCapacity()
           
protected  long hash(byte[] key)
           
 Iterator<Map.Entry<byte[],byte[]>> iterator()
           
 Iterator<byte[]> keyIterator()
           
protected  long nextScn()
           
 void persist()
           
 boolean put(byte[] key, byte[] value)
           
protected  boolean putInternal(int index, byte[] key, byte[] value)
           
 void rehash()
           
protected  void split()
           
 void sync()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DynamicDataStore

public DynamicDataStore(File homeDir,
                        SegmentFactory segmentFactory)
                 throws Exception
Creates a dynamic DataStore with the settings below:
    Initial Level            : 0
    Entry Size               : 10000
    Max Entries              : 5
    Segment File Size        : 256MB
    Segment Compact Factor   : 0.5
    Store Hash Load Factor   : 0.75
    Store Hash Function      : krati.util.FnvHashFunction
 

Parameters:
homeDir - the home directory of DataStore
segmentFileSizeMB - the size of segment file in MB
segmentFactory - the segment factory
Throws:
Exception - if this dynamic data store cannot be created.

DynamicDataStore

public DynamicDataStore(File homeDir,
                        int initLevel,
                        SegmentFactory segmentFactory)
                 throws Exception
Creates a dynamic DataStore with the settings below:
    Entry Size               : 10000
    Max Entries              : 5
    Segment File Size        : 256MB
    Segment Compact Factor   : 0.5
    Store Hash Load Factor   : 0.75
    Store Hash Function      : krati.util.FnvHashFunction
 

Parameters:
homeDir - the home directory of DataStore
initLevel - the initial level when DataStore is created
segmentFactory - the segment factory
Throws:
Exception - if this dynamic data store cannot be created.

DynamicDataStore

public DynamicDataStore(File homeDir,
                        int initLevel,
                        SegmentFactory segmentFactory,
                        HashFunction<byte[]> hashFunction)
                 throws Exception
Creates a dynamic DataStore with the settings below:
    Entry Size               : 10000
    Max Entries              : 5
    Segment File Size        : 256MB
    Segment Compact Factor   : 0.5
    Store Hash Load Factor   : 0.75
 

Parameters:
homeDir - the home directory of DataStore
initLevel - the initial level when DataStore is created
segmentFactory - the segment factory
hashFunction - the hash function for mapping keys to indexes
Throws:
Exception - if this dynamic data store cannot be created.

DynamicDataStore

public DynamicDataStore(File homeDir,
                        int initLevel,
                        int segmentFileSizeMB,
                        SegmentFactory segmentFactory)
                 throws Exception
Creates a dynamic DataStore with the settings below:
    Entry Size               : 10000
    Max Entries              : 5
    Segment Compact Factor   : 0.5
    Store Hash Load Factor   : 0.75
    Store Hash Function      : krati.util.FnvHashFunction
 

Parameters:
homeDir - the home directory of DataStore
initLevel - the initial level when DataStore is created
segmentFileSizeMB - the size of segment file in MB
segmentFactory - the segment factory
Throws:
Exception - if this dynamic data store cannot be created.

DynamicDataStore

public DynamicDataStore(File homeDir,
                        int initLevel,
                        int segmentFileSizeMB,
                        SegmentFactory segmentFactory,
                        double hashLoadThreshold,
                        HashFunction<byte[]> hashFunction)
                 throws Exception
Creates a dynamic DataStore with the settings below:
    Entry Size               : 10000
    Max Entries              : 5
    Segment Compact Factor   : 0.5
 

Parameters:
homeDir - the home directory of DataStore
initLevel - the initial level when DataStore is created
segmentFileSizeMB - the size of segment file in MB
segmentFactory - the segment factory
hashLoadThreshold - the load factor of the underlying address array (hash table)
hashFunction - the hash function for mapping keys to indexes
Throws:
Exception - if this dynamic data store cannot be created.

DynamicDataStore

public DynamicDataStore(File homeDir,
                        int initLevel,
                        int entrySize,
                        int maxEntries,
                        int segmentFileSizeMB,
                        SegmentFactory segmentFactory)
                 throws Exception
Creates a dynamic DataStore with the settings below:
    Segment Compact Factor   : 0.5
    Store Hash Load Factor   : 0.75
    Store Hash Function      : krati.util.FnvHashFunction
 

Parameters:
homeDir - the home directory of DataStore
initLevel - the initial level when DataStore is created
entrySize - the redo entry size (i.e., batch size)
maxEntries - the number of redo entries required for updating the underlying address array
segmentFileSizeMB - the size of segment file in MB
segmentFactory - the segment factory
Throws:
Exception - if this dynamic data store cannot be created.

DynamicDataStore

public DynamicDataStore(File homeDir,
                        int initLevel,
                        int entrySize,
                        int maxEntries,
                        int segmentFileSizeMB,
                        SegmentFactory segmentFactory,
                        double hashLoadThreshold,
                        HashFunction<byte[]> hashFunction)
                 throws Exception
Creates a dynamic DataStore.
    Segment Compact Factor   : 0.5
 

Parameters:
homeDir - the home directory of DataStore
initLevel - the initial level when DataStore is created
entrySize - the redo entry size (i.e., batch size)
maxEntries - the number of redo entries required for updating the underlying address array
segmentFileSizeMB - the size of segment file in MB
segmentFactory - the segment factory
hashLoadThreshold - the load factor of the underlying address array (hash table)
hashFunction - the hash function for mapping keys to indexes
Throws:
Exception - if this dynamic data store cannot be created.

DynamicDataStore

public DynamicDataStore(File homeDir,
                        int initLevel,
                        int entrySize,
                        int maxEntries,
                        int segmentFileSizeMB,
                        SegmentFactory segmentFactory,
                        double segmentCompactFactor,
                        double hashLoadThreshold,
                        HashFunction<byte[]> hashFunction)
                 throws Exception
Creates a dynamic DataStore.

Parameters:
homeDir - the home directory of DataStore
initLevel - the initial level when DataStore is created
entrySize - the redo entry size (i.e., batch size)
maxEntries - the number of redo entries required for updating the underlying address array
segmentFileSizeMB - the size of segment file in MB
segmentFactory - the segment factory
segmentCompactFactor - the load factor of segment, below which a segment is eligible for compaction
hashLoadThreshold - the load factor of the underlying address array (hash table)
hashFunction - the hash function for mapping keys to indexes
Throws:
Exception - if this dynamic data store cannot be created.
Method Detail

createAddressArray

protected DynamicLongArray createAddressArray(int entrySize,
                                              int maxEntries,
                                              File homeDirectory)
                                       throws Exception
Throws:
Exception

hash

protected long hash(byte[] key)

nextScn

protected long nextScn()

sync

public void sync()
          throws IOException
Specified by:
sync in interface DataStore<byte[],byte[]>
Throws:
IOException

persist

public void persist()
             throws IOException
Specified by:
persist in interface DataStore<byte[],byte[]>
Throws:
IOException

get

public byte[] get(byte[] key)
Specified by:
get in interface DataStore<byte[],byte[]>

put

public boolean put(byte[] key,
                   byte[] value)
            throws Exception
Specified by:
put in interface DataStore<byte[],byte[]>
Throws:
Exception

delete

public boolean delete(byte[] key)
               throws Exception
Specified by:
delete in interface DataStore<byte[],byte[]>
Throws:
Exception

clear

public void clear()
           throws IOException
Specified by:
clear in interface DataStore<byte[],byte[]>
Throws:
IOException

getIndex

protected final int getIndex(byte[] key)

getIndex

protected final int getIndex(long hashCode)

putInternal

protected boolean putInternal(int index,
                              byte[] key,
                              byte[] value)
                       throws Exception
Throws:
Exception

deleteInternal

protected boolean deleteInternal(int index,
                                 byte[] key)
                          throws Exception
Throws:
Exception

getLevel

public final int getLevel()

getSplit

public final int getSplit()

getCapacity

public final int getCapacity()

getUnitCapacity

public final int getUnitCapacity()

getLevelCapacity

public final int getLevelCapacity()

getLoadCount

public final int getLoadCount()

getLoadFactor

public final double getLoadFactor()

getLoadThreshold

public final double getLoadThreshold()

split

protected void split()
              throws Exception
Throws:
Exception

rehash

public void rehash()
            throws Exception
Throws:
Exception

getStatus

public String getStatus()
Returns:
the status of this data store.

getDataArray

public DataArray getDataArray()
Returns:
the underlying data array.

keyIterator

public Iterator<byte[]> keyIterator()
Specified by:
keyIterator in interface DataStore<byte[],byte[]>

iterator

public Iterator<Map.Entry<byte[],byte[]>> iterator()
Specified by:
iterator in interface Iterable<Map.Entry<byte[],byte[]>>


Copyright © 2011. All Rights Reserved.