ostore.cache
Class BufferCache

java.lang.Object
  |
  +--ostore.cache.BufferCache
All Implemented Interfaces:
DataCache, EventHandlerIF

public class BufferCache
extends Object
implements EventHandlerIF, DataCache

Manages file blocks and (someday soon) archival fragments in memory, keeping the total core size to a given limit--an intended replacement for DataCacheImpl, LRUCacheImpl, MemoryCache, and CacheDb.


Field Summary
protected  int _pinned_bytes
           
protected  SinkIF _sink
           
protected  Object _size_lock
           
protected  int _space_wait_queue_bytes_reserved
           
protected  int _total_pin_count
           
protected  Object _total_pin_count_lock
           
protected  NodeId self_node_id
           
protected static int STATE_DISK_ONLY
           
protected static int STATE_FLUSHING_TO_DISK
           
protected static int STATE_LOADING_FROM_DISK
           
protected static int STATE_MEM_AND_DISK
           
protected static int STATE_MEM_ONLY
           
protected static int STATE_MODIFIED_DURING_FLUSH
           
protected static int STATE_REMOVED
           
protected static String[] state_to_string
           
 
Constructor Summary
BufferCache()
           
 
Method Summary
protected  boolean acquire_space(int bytes)
           
 void assign(CacheablePinned pin, Cacheable cacheable)
          Assign a block to reserved space
 void assign(CacheablePinned pin, CacheableIdentity identifier)
          Give a reserved block an identity; if an id already exists, the new identifiers will be appended to the existing id.
protected  boolean block_being_flushed(ostore.cache.BufferCache.CacheItem item)
           
 boolean cache_contains(CacheableIdentity id)
          cache_contains returns true if the cache contains the item labeled by the CacheableIdentity; false, otherwise.
protected  boolean cheap_need_space(int total_needed)
          Returns true if space has been acquired.
protected  boolean check_cache_type(CacheableIdentity id, boolean die, QueueElementIF event)
           
protected  boolean check_cache_type(CacheableIdentity id, int cacheType, boolean die, QueueElementIF event)
           
protected  boolean check_cache_type(int cacheType, boolean die, QueueElementIF event)
           
protected static SecureHash ci_to_diss(CacheableIdentity id)
           
protected static SecureHash ci_to_guid(CacheableIdentity id)
           
protected static SecureHash ci_to_vhash(CacheableIdentity id)
           
protected static VID ci_to_vid(CacheableIdentity id)
          idToVid converts a CacheableIdentity to a VID.
 void destroy()
           
protected  ostore.cache.BufferCache.CacheItem find_cache_item(CacheableIdentity identifier)
           
protected  void flush_block(ostore.cache.BufferCache.CacheItem item)
           
protected  void get_block(CacheableIdentity id, int req_id, boolean want_pin)
           
protected  CacheableHandle get(CacheableIdentity id)
           
 CacheablePinned getPin(CacheableIdentity id)
           
 CacheablePinned getPinWithException(CacheableIdentity id)
          Request a page and pin it (regardless if it's already pinned).
 CacheableHandle getWithException(CacheableIdentity id)
          Request a handle to a block in the cache.
protected  void handle_assign(CacheAssignRequest req)
           
protected  void handle_block_req_have_space(ostore.cache.BufferCache.CacheItem item)
           
protected  void handle_block_req(CacheBlockRequestMessage req)
           
protected  void handle_get_comp(StorageManager.GetBlockCompleted gc)
           
protected  void handle_pin_req(CachePinnedRequest.Local req)
           
protected  void handle_put_comp(StorageManager.PutBlockCompleted pc)
           
protected  void handle_reserve_have_space(CacheReserveSpaceMessage req)
           
protected  void handle_reserve(CacheReserveSpaceMessage req)
           
protected  void handle_unpin(CacheUnpinRequest req)
           
 void handleEvent(QueueElementIF item)
          FIXME remove the storage_manager declaration protected StorageManager _storage_manager;
 void handleEvents(QueueElementIF[] items)
           
 void init(ConfigDataIF config)
           
protected  void item_pinned(int sz)
           
protected  void item_unpinned(int sz)
           
 boolean local_node_contains(CacheableIdentity id)
          local_node_contains returns true if the local node contains the item labeled by the CacheableIdentity anywhere in the cache, on disk, or anywhere inbetween; false, otherwise.
protected  CacheableIdentity make_ci(ostore.cache.BufferCache.CacheItem item)
           
protected  void need_space(Object req, int total_needed)
          Called to indicate that whatever function is trying to satisfy the given request needs more space in order to do so; requests are satisfied in FIFO order; will result in a call to space_available when it is.
protected  CacheablePinned reserve(int n)
           
 CacheablePinned reserveWithException(int n)
          Reserve n bytes in the cache if there is room; otherwise throw a CacheFullException.
 LinkedList reserveWithException(int b, int sz)
          Reserve b blocks of sz bytes each in the cache if there is room; otherwise throw a CacheFullException.
protected  void space_available(Object obj)
           
 String toString()
           
 int totalPins()
          return the total number of pins being held
 CacheableHandle unpin(CacheablePinned p)
          Unpin the pinned block; it is an error to call this function if the CacheablePinned has already been used for another unpin call.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_sink

protected SinkIF _sink

self_node_id

protected NodeId self_node_id

_total_pin_count

protected int _total_pin_count

_pinned_bytes

protected int _pinned_bytes

_total_pin_count_lock

protected Object _total_pin_count_lock

STATE_MEM_ONLY

protected static final int STATE_MEM_ONLY
See Also:
Constant Field Values

STATE_MEM_AND_DISK

protected static final int STATE_MEM_AND_DISK
See Also:
Constant Field Values

STATE_DISK_ONLY

protected static final int STATE_DISK_ONLY
See Also:
Constant Field Values

STATE_LOADING_FROM_DISK

protected static final int STATE_LOADING_FROM_DISK
See Also:
Constant Field Values

STATE_FLUSHING_TO_DISK

protected static final int STATE_FLUSHING_TO_DISK
See Also:
Constant Field Values

STATE_MODIFIED_DURING_FLUSH

protected static final int STATE_MODIFIED_DURING_FLUSH
See Also:
Constant Field Values

STATE_REMOVED

protected static final int STATE_REMOVED
See Also:
Constant Field Values

state_to_string

protected static final String[] state_to_string

_size_lock

protected Object _size_lock

_space_wait_queue_bytes_reserved

protected int _space_wait_queue_bytes_reserved
Constructor Detail

BufferCache

public BufferCache()
Method Detail

cache_contains

public boolean cache_contains(CacheableIdentity id)
cache_contains returns true if the cache contains the item labeled by the CacheableIdentity; false, otherwise. That is, cache_contains will return false if the cache item is contained only on disk. NOTE: if the item is currently loading from disk. cache_contains returns true. WARNING: this is just a hint. The status of the item can change between calls.

Parameters:
id - CacheableIdentity.
Returns:
returns true if the cache contains the item labeled by the CacheableIdentity; false, otherwise.

local_node_contains

public boolean local_node_contains(CacheableIdentity id)
local_node_contains returns true if the local node contains the item labeled by the CacheableIdentity anywhere in the cache, on disk, or anywhere inbetween; false, otherwise. WARNING: this is just a hint. The status of the item can change between calls.

Parameters:
id - CacheableIdentity.
Returns:
returns true if the local node contains the item labeled by the CacheableIdentity; false, otherwise.

init

public void init(ConfigDataIF config)
          throws Exception
Specified by:
init in interface EventHandlerIF
Exception

handleEvent

public void handleEvent(QueueElementIF item)
                 throws EventHandlerException
FIXME remove the storage_manager declaration protected StorageManager _storage_manager;

Specified by:
handleEvent in interface EventHandlerIF
EventHandlerException

handleEvents

public void handleEvents(QueueElementIF[] items)
                  throws EventHandlerException
Specified by:
handleEvents in interface EventHandlerIF
EventHandlerException

destroy

public void destroy()
             throws Exception
Specified by:
destroy in interface EventHandlerIF
Exception

handle_put_comp

protected void handle_put_comp(StorageManager.PutBlockCompleted pc)

handle_block_req

protected void handle_block_req(CacheBlockRequestMessage req)

get_block

protected void get_block(CacheableIdentity id,
                         int req_id,
                         boolean want_pin)

handle_block_req_have_space

protected void handle_block_req_have_space(ostore.cache.BufferCache.CacheItem item)

handle_get_comp

protected void handle_get_comp(StorageManager.GetBlockCompleted gc)

handle_pin_req

protected void handle_pin_req(CachePinnedRequest.Local req)

handle_reserve

protected void handle_reserve(CacheReserveSpaceMessage req)

handle_reserve_have_space

protected void handle_reserve_have_space(CacheReserveSpaceMessage req)

handle_unpin

protected void handle_unpin(CacheUnpinRequest req)

handle_assign

protected void handle_assign(CacheAssignRequest req)

get

protected CacheableHandle get(CacheableIdentity id)

getWithException

public CacheableHandle getWithException(CacheableIdentity id)
                                 throws CacheMissException
Description copied from interface: DataCache
Request a handle to a block in the cache.

Specified by:
getWithException in interface DataCache
Returns:
CacheableHandle for particular id
Throws:
CacheMissException - if block is not in the cache

getPin

public CacheablePinned getPin(CacheableIdentity id)

getPinWithException

public CacheablePinned getPinWithException(CacheableIdentity id)
                                    throws CacheMissException
Description copied from interface: DataCache
Request a page and pin it (regardless if it's already pinned).

Specified by:
getPinWithException in interface DataCache
Returns:
CacheablePinned for particular id
Throws:
CacheMissException - if block is not in the cache

assign

public void assign(CacheablePinned pin,
                   CacheableIdentity identifier)
Description copied from interface: DataCache
Give a reserved block an identity; if an id already exists, the new identifiers will be appended to the existing id.

Specified by:
assign in interface DataCache

assign

public void assign(CacheablePinned pin,
                   Cacheable cacheable)
Description copied from interface: DataCache
Assign a block to reserved space

Specified by:
assign in interface DataCache

reserve

protected CacheablePinned reserve(int n)

reserveWithException

public CacheablePinned reserveWithException(int n)
                                     throws CacheFullException
Description copied from interface: DataCache
Reserve n bytes in the cache if there is room; otherwise throw a CacheFullException.

Specified by:
reserveWithException in interface DataCache
Parameters:
n - the number of bytes to reserve
Throws:
CacheFullException - if not enough space is available

reserveWithException

public LinkedList reserveWithException(int b,
                                       int sz)
                                throws CacheFullException
Description copied from interface: DataCache
Reserve b blocks of sz bytes each in the cache if there is room; otherwise throw a CacheFullException.

Specified by:
reserveWithException in interface DataCache
Parameters:
b - the number of block to reserve
sz - the size of each block
Throws:
CacheFullException - if not enough space is available

unpin

public CacheableHandle unpin(CacheablePinned p)
Description copied from interface: DataCache
Unpin the pinned block; it is an error to call this function if the CacheablePinned has already been used for another unpin call.

Specified by:
unpin in interface DataCache

make_ci

protected CacheableIdentity make_ci(ostore.cache.BufferCache.CacheItem item)

totalPins

public int totalPins()
Description copied from interface: DataCache
return the total number of pins being held

Specified by:
totalPins in interface DataCache

item_pinned

protected final void item_pinned(int sz)

item_unpinned

protected final void item_unpinned(int sz)

block_being_flushed

protected boolean block_being_flushed(ostore.cache.BufferCache.CacheItem item)

flush_block

protected void flush_block(ostore.cache.BufferCache.CacheItem item)

check_cache_type

protected boolean check_cache_type(CacheableIdentity id,
                                   boolean die,
                                   QueueElementIF event)

check_cache_type

protected boolean check_cache_type(int cacheType,
                                   boolean die,
                                   QueueElementIF event)

check_cache_type

protected boolean check_cache_type(CacheableIdentity id,
                                   int cacheType,
                                   boolean die,
                                   QueueElementIF event)

acquire_space

protected final boolean acquire_space(int bytes)

cheap_need_space

protected boolean cheap_need_space(int total_needed)
Returns true if space has been acquired. For use in functional interface. Will throw out all victim lines until enough space is free or until the next victim has been modified, and thus must be flushed before being thrown away.


need_space

protected void need_space(Object req,
                          int total_needed)
Called to indicate that whatever function is trying to satisfy the given request needs more space in order to do so; requests are satisfied in FIFO order; will result in a call to space_available when it is. Call with null request to check existing queue.


space_available

protected void space_available(Object obj)

ci_to_vhash

protected static final SecureHash ci_to_vhash(CacheableIdentity id)

ci_to_guid

protected static final SecureHash ci_to_guid(CacheableIdentity id)

ci_to_diss

protected static final SecureHash ci_to_diss(CacheableIdentity id)

ci_to_vid

protected static final VID ci_to_vid(CacheableIdentity id)
idToVid converts a CacheableIdentity to a VID. The presedence is to first assign the VID a guid if the CacheableIdentity.GUID is not null. Otherwise, assigns the VID a VHASH.


find_cache_item

protected ostore.cache.BufferCache.CacheItem find_cache_item(CacheableIdentity identifier)

toString

public String toString()
Overrides:
toString in class Object