Package org.teiid.common.buffer.impl
Class BufferFrontedFileStoreCache
- java.lang.Object
-
- org.teiid.common.buffer.impl.BufferFrontedFileStoreCache
-
- All Implemented Interfaces:
Cache<org.teiid.common.buffer.impl.PhysicalInfo>
,StorageManager
public class BufferFrontedFileStoreCache extends Object implements Cache<org.teiid.common.buffer.impl.PhysicalInfo>
Implements storage against aFileStore
abstraction using a fronting memory buffer with a filesystem paradigm. All objects must go through the memory (typically off-heap) buffer so that they can be put into their appropriately sized storage bucket. The memory uses a 31bit address space on top of 2^13 byte blocks. Therefore there is 2^31*2^13 = 2^44 or 16 terabytes max of addressable space. This is well beyond any current needs. The 64 byte inode format is: 14 32 bit direct block pointers 1 32 bit block indirect pointer 1 32 bit block doubly indirect pointer (should be rarely used) This means that the maximum number of blocks available to an object is 14 + (2^13)/4 + ((2^13)/4)^2 ~= 2^22 Thus the max serialized object size is: 2^22*(2^13) ~= 32GB. Typically the max object size will be much smaller, such as 8MB. Inodes are held separately from the data/index blocks, and introduce an overhead that is ~ 1/128th the size of memory buffer. The filesystem stores are broken up into block specific sizes starting with 8KB. The root directory "physicalMapping" is held in memory for performance. It will grow in proportion to the number of tables/tuplebuffers in use. The locking is as fine grained as possible to prevent contention. SeePhysicalInfo
for flags that are used when it is used as a lock. It is important to not access the group maps when aPhysicalInfo
lock is held.
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_MAX_OBJECT_SIZE
static long
MAX_ADDRESSABLE_MEMORY
-
Constructor Summary
Constructors Constructor Description BufferFrontedFileStoreCache()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(CacheEntry entry, Serializer s)
Adds an entry to the cache.boolean
addToCacheGroup(Long gid, Long oid)
Must be called prior to adding an entryvoid
createCacheGroup(Long gid)
Must be called prior to adding any group entriesFileStore
createFileStore(String name)
CacheEntry
get(org.teiid.common.buffer.impl.PhysicalInfo info, Long oid, WeakReference<? extends Serializer<?>> ref)
Get method, must be called using the object obtained in the lockForLoad methodint
getCacheGroupCount()
int
getDataBlocksInUse()
long
getDiskUsage()
int
getInodesInUse()
int
getMaxMemoryBlocks()
long
getMaxStorageSpace()
long
getMemoryBufferSpace()
long
getMemoryInUseBytes()
StorageManager
getStorageManager()
long
getStorageReads()
long
getStorageWrites()
void
initialize()
org.teiid.common.buffer.impl.PhysicalInfo
lockForLoad(Long oid, Serializer<?> serializer)
Lock the object for load and return an identifier/lock that can be used to retrieve the object.Integer
remove(Long gid, Long id)
Remove an entry from the cache, return the sizeEstimate if the entry existedCollection<Long>
removeCacheGroup(Long gid)
Remove an entire cache group TODO: this should use a callback on the buffermangaer to remove memory entries without materializing all group keysvoid
setBufferManager(BufferManagerImpl bufferManager)
void
setCompactBufferFiles(boolean compactBufferFiles)
void
setDirect(boolean direct)
void
setMaxStorageObjectSize(int maxStorageBlockSize)
void
setMemoryBufferSpace(long maxBufferSpace)
void
setMinDefrag(long minDefrag)
void
setStorageManager(StorageManager storageManager)
void
setTruncateInterval(int truncateInterval)
void
shutdown()
void
unlockForLoad(org.teiid.common.buffer.impl.PhysicalInfo info)
Must be called after lockForLoad
-
-
-
Field Detail
-
DEFAULT_MAX_OBJECT_SIZE
public static final int DEFAULT_MAX_OBJECT_SIZE
- See Also:
- Constant Field Values
-
MAX_ADDRESSABLE_MEMORY
public static final long MAX_ADDRESSABLE_MEMORY
- See Also:
- Constant Field Values
-
-
Method Detail
-
initialize
public void initialize() throws TeiidComponentException
- Specified by:
initialize
in interfaceStorageManager
- Throws:
TeiidComponentException
-
add
public boolean add(CacheEntry entry, Serializer s)
Description copied from interface:Cache
Adds an entry to the cache.
-
lockForLoad
public org.teiid.common.buffer.impl.PhysicalInfo lockForLoad(Long oid, Serializer<?> serializer)
Description copied from interface:Cache
Lock the object for load and return an identifier/lock that can be used to retrieve the object.- Specified by:
lockForLoad
in interfaceCache<org.teiid.common.buffer.impl.PhysicalInfo>
- Returns:
- the identifier, may be null
-
unlockForLoad
public void unlockForLoad(org.teiid.common.buffer.impl.PhysicalInfo info)
Description copied from interface:Cache
Must be called after lockForLoad- Specified by:
unlockForLoad
in interfaceCache<org.teiid.common.buffer.impl.PhysicalInfo>
-
getCacheGroupCount
public int getCacheGroupCount()
- Specified by:
getCacheGroupCount
in interfaceCache<org.teiid.common.buffer.impl.PhysicalInfo>
-
get
public CacheEntry get(org.teiid.common.buffer.impl.PhysicalInfo info, Long oid, WeakReference<? extends Serializer<?>> ref) throws TeiidComponentException
Description copied from interface:Cache
Get method, must be called using the object obtained in the lockForLoad method- Specified by:
get
in interfaceCache<org.teiid.common.buffer.impl.PhysicalInfo>
- Returns:
- Throws:
TeiidComponentException
-
createFileStore
public FileStore createFileStore(String name)
- Specified by:
createFileStore
in interfaceStorageManager
-
setDirect
public void setDirect(boolean direct)
-
addToCacheGroup
public boolean addToCacheGroup(Long gid, Long oid)
Description copied from interface:Cache
Must be called prior to adding an entry- Specified by:
addToCacheGroup
in interfaceCache<org.teiid.common.buffer.impl.PhysicalInfo>
- Returns:
- if the add was successful
-
createCacheGroup
public void createCacheGroup(Long gid)
Description copied from interface:Cache
Must be called prior to adding any group entries- Specified by:
createCacheGroup
in interfaceCache<org.teiid.common.buffer.impl.PhysicalInfo>
-
remove
public Integer remove(Long gid, Long id)
Description copied from interface:Cache
Remove an entry from the cache, return the sizeEstimate if the entry existed
-
removeCacheGroup
public Collection<Long> removeCacheGroup(Long gid)
Description copied from interface:Cache
Remove an entire cache group TODO: this should use a callback on the buffermangaer to remove memory entries without materializing all group keys- Specified by:
removeCacheGroup
in interfaceCache<org.teiid.common.buffer.impl.PhysicalInfo>
- Returns:
-
setStorageManager
public void setStorageManager(StorageManager storageManager)
-
getStorageManager
public StorageManager getStorageManager()
-
setMemoryBufferSpace
public void setMemoryBufferSpace(long maxBufferSpace)
-
getInodesInUse
public int getInodesInUse()
-
getDataBlocksInUse
public int getDataBlocksInUse()
-
setMaxStorageObjectSize
public void setMaxStorageObjectSize(int maxStorageBlockSize)
-
getStorageReads
public long getStorageReads()
-
getStorageWrites
public long getStorageWrites()
-
getMemoryBufferSpace
public long getMemoryBufferSpace()
- Specified by:
getMemoryBufferSpace
in interfaceCache<org.teiid.common.buffer.impl.PhysicalInfo>
-
setMinDefrag
public void setMinDefrag(long minDefrag)
-
getMaxMemoryBlocks
public int getMaxMemoryBlocks()
-
getMemoryInUseBytes
public long getMemoryInUseBytes()
-
setBufferManager
public void setBufferManager(BufferManagerImpl bufferManager)
-
setTruncateInterval
public void setTruncateInterval(int truncateInterval)
-
getDiskUsage
public long getDiskUsage()
-
shutdown
public void shutdown()
-
setCompactBufferFiles
public void setCompactBufferFiles(boolean compactBufferFiles)
-
getMaxStorageSpace
public long getMaxStorageSpace()
- Specified by:
getMaxStorageSpace
in interfaceStorageManager
-
-