krati.store
Class DataCacheImpl

java.lang.Object
  extended by krati.store.DataCacheImpl
All Implemented Interfaces:
Persistable, DataCache

public class DataCacheImpl
extends Object
implements DataCache

DataCache: A Persistent Full Cache. This class is not thread-safe by design. It is expected that the conditions below hold within one JVM.

    1. There is one and only one instance of DataCacheImpl for a given cacheDirectory.
    2. There is one and only one thread calling the set methods at any given time. 
 
It is expected that this class is used in the case of multiple readers and single writer.

Author:
jwu

Constructor Summary
DataCacheImpl(int memberIdStart, int memberIdCount, File cacheDirectory)
          Constructs a data cache with default values below.
DataCacheImpl(int memberIdStart, int memberIdCount, File cacheDirectory, int segmentFileSizeMB)
          Constructs a data cache with default values below.
DataCacheImpl(int memberIdStart, int memberIdCount, File cacheDirectory, SegmentFactory segmentFactory)
          Constructs a data cache with default values below.
DataCacheImpl(int memberIdStart, int memberIdCount, File cacheDirectory, SegmentFactory segmentFactory, int segmentFileSizeMB)
          Constructs a data cache with default values below.
DataCacheImpl(int memberIdStart, int memberIdCount, int maxEntrySize, int maxEntries, File cacheDirectory, SegmentFactory segmentFactory, int segmentFileSizeMB, boolean checked)
          Constructs a data cache with Segment Compact Factor default to 0.5.
DataCacheImpl(int memberIdStart, int memberIdCount, int maxEntrySize, int maxEntries, File cacheDirectory, SegmentFactory segmentFactory, int segmentFileSizeMB, double segmentCompactFactor, boolean checked)
          Constructs a data cache.
 
Method Summary
 void clear()
           
 void delete(int memberId, long scn)
           
 byte[] get(int memberId)
           
 int get(int memberId, byte[] dst)
           
 int get(int memberId, byte[] dst, int offset)
           
 long getHWMark()
          Gets the high water mark.
 int getIdCount()
           
 int getIdStart()
           
 long getLWMark()
          Gets the low water mark.
protected  String getStatus()
           
 void persist()
          Persist all updates from memory buffer into redo log files in non-blocking mode.
 void saveHWMark(long endOfPeriod)
          Save the high water mark.
 void set(int memberId, byte[] data, int offset, int length, long scn)
           
 void set(int memberId, byte[] data, long scn)
           
 void sync()
          Force all updates from memory buffer and redo log files to synchronize with the underlying persistent file in blocking mode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataCacheImpl

public DataCacheImpl(int memberIdStart,
                     int memberIdCount,
                     File cacheDirectory)
              throws Exception
Constructs a data cache with default values below.
    Segment File Size      : 256MB
    Segment Compact Factor : 0.5
    Redo entry size        : 10000
    Number of Redo Entries : 5
    Data integrity check   : No
    Segment Factory        : MemorySegmentFactory
 

Parameters:
memberIdStart - Start of memberId
memberIdCount - Total of memberId(s)
cacheDirectory - Cache directory where persistent data will be stored
Throws:
Exception

DataCacheImpl

public DataCacheImpl(int memberIdStart,
                     int memberIdCount,
                     File cacheDirectory,
                     int segmentFileSizeMB)
              throws Exception
Constructs a data cache with default values below.
    Segment Compact Factor : 0.5
    Redo entry size        : 10000
    Number of Redo Entries : 5
    Data integrity check   : No
    Segment Factory        : MemorySegmentFactory
 

Parameters:
memberIdStart - Start of memberId
memberIdCount - Total of memberId(s)
cacheDirectory - Cache directory where persistent data will be stored
segmentFileSizeMB - Segment size in MB
Throws:
Exception

DataCacheImpl

public DataCacheImpl(int memberIdStart,
                     int memberIdCount,
                     File cacheDirectory,
                     SegmentFactory segmentFactory)
              throws Exception
Constructs a data cache with default values below.
    Segment File Size      : 256MB
    Segment Compact Factor : 0.5
    Redo entry size        : 10000
    Number of Redo Entries : 5
    Data integrity check   : No
 

Parameters:
memberIdStart - Start of memberId
memberIdCount - Total of memberId(s)
cacheDirectory - Cache directory where persistent data will be stored
segmentFactory - Factory for creating Segment(s)
Throws:
Exception

DataCacheImpl

public DataCacheImpl(int memberIdStart,
                     int memberIdCount,
                     File cacheDirectory,
                     SegmentFactory segmentFactory,
                     int segmentFileSizeMB)
              throws Exception
Constructs a data cache with default values below.
    Segment Compact Factor : 0.5
    Redo Entry Size        : 10000
    Number of redo entries : 5
    Data integrity check   : No
 

Parameters:
memberIdStart - Start of memberId
memberIdCount - Total of memberId(s)
cacheDirectory - Cache directory where persistent data will be stored
segmentFactory - Factory for creating Segment(s)
segmentFileSizeMB - Segment size in MB
Throws:
Exception

DataCacheImpl

public DataCacheImpl(int memberIdStart,
                     int memberIdCount,
                     int maxEntrySize,
                     int maxEntries,
                     File cacheDirectory,
                     SegmentFactory segmentFactory,
                     int segmentFileSizeMB,
                     boolean checked)
              throws Exception
Constructs a data cache with Segment Compact Factor default to 0.5.

Parameters:
memberIdStart - Start of memberId
memberIdCount - Total of memberId(s)
maxEntrySize - Redo entry size (i.e., batch size)
maxEntries - Number of redo entries required for updating the underlying address array
cacheDirectory - Cache directory where persistent data will be stored
segmentFactory - Factory for creating Segment(s)
segmentFileSizeMB - Segment size in MB
checked - whether to apply default checksum (Adler32) to ensure data integrity
Throws:
Exception

DataCacheImpl

public DataCacheImpl(int memberIdStart,
                     int memberIdCount,
                     int maxEntrySize,
                     int maxEntries,
                     File cacheDirectory,
                     SegmentFactory segmentFactory,
                     int segmentFileSizeMB,
                     double segmentCompactFactor,
                     boolean checked)
              throws Exception
Constructs a data cache.

Parameters:
memberIdStart - Start of memberId
memberIdCount - Total of memberId(s)
maxEntrySize - Redo entry size (i.e., batch size)
maxEntries - Number of redo entries required for updating the underlying address array
cacheDirectory - Cache directory where persistent data will be stored
segmentFactory - Factory for creating Segment(s)
segmentFileSizeMB - Segment size in MB
segmentCompactFactor - Load factor of segment, below which a segment is eligible for compaction
checked - whether to apply default checksum (Adler32) to ensure data integrity
Throws:
Exception
Method Detail

getStatus

protected String getStatus()

getIdCount

public int getIdCount()
Specified by:
getIdCount in interface DataCache

getIdStart

public int getIdStart()
Specified by:
getIdStart in interface DataCache

get

public byte[] get(int memberId)
Specified by:
get in interface DataCache

get

public int get(int memberId,
               byte[] dst)
Specified by:
get in interface DataCache

get

public int get(int memberId,
               byte[] dst,
               int offset)
Specified by:
get in interface DataCache

set

public void set(int memberId,
                byte[] data,
                long scn)
         throws Exception
Specified by:
set in interface DataCache
Throws:
Exception

set

public void set(int memberId,
                byte[] data,
                int offset,
                int length,
                long scn)
         throws Exception
Specified by:
set in interface DataCache
Throws:
Exception

delete

public void delete(int memberId,
                   long scn)
            throws Exception
Specified by:
delete in interface DataCache
Throws:
Exception

sync

public void sync()
          throws IOException
Description copied from interface: Persistable
Force all updates from memory buffer and redo log files to synchronize with the underlying persistent file in blocking mode.

Specified by:
sync in interface Persistable
Throws:
IOException

persist

public void persist()
             throws IOException
Description copied from interface: Persistable
Persist all updates from memory buffer into redo log files in non-blocking mode.

Specified by:
persist in interface Persistable
Throws:
IOException

getHWMark

public long getHWMark()
Description copied from interface: Persistable
Gets the high water mark.

Specified by:
getHWMark in interface Persistable

getLWMark

public long getLWMark()
Description copied from interface: Persistable
Gets the low water mark.

Specified by:
getLWMark in interface Persistable

saveHWMark

public void saveHWMark(long endOfPeriod)
                throws Exception
Description copied from interface: Persistable
Save the high water mark.

Specified by:
saveHWMark in interface Persistable
Throws:
Exception

clear

public void clear()
           throws IOException
Specified by:
clear in interface DataCache
Throws:
IOException


Copyright © 2011. All Rights Reserved.