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 aFileStoreabstraction 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. SeePhysicalInfofor flags that are used when it is used as a lock. It is important to not access the group maps when aPhysicalInfolock is held.
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_MAX_OBJECT_SIZEstatic longMAX_ADDRESSABLE_MEMORY
-
Constructor Summary
Constructors Constructor Description BufferFrontedFileStoreCache()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(CacheEntry entry, Serializer s)Adds an entry to the cache.booleanaddToCacheGroup(Long gid, Long oid)Must be called prior to adding an entryvoidcreateCacheGroup(Long gid)Must be called prior to adding any group entriesFileStorecreateFileStore(String name)CacheEntryget(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 methodintgetCacheGroupCount()intgetDataBlocksInUse()longgetDiskUsage()intgetInodesInUse()intgetMaxMemoryBlocks()longgetMaxStorageSpace()longgetMemoryBufferSpace()longgetMemoryInUseBytes()StorageManagergetStorageManager()longgetStorageReads()longgetStorageWrites()voidinitialize()org.teiid.common.buffer.impl.PhysicalInfolockForLoad(Long oid, Serializer<?> serializer)Lock the object for load and return an identifier/lock that can be used to retrieve the object.Integerremove(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 keysvoidsetBufferManager(BufferManagerImpl bufferManager)voidsetCompactBufferFiles(boolean compactBufferFiles)voidsetDirect(boolean direct)voidsetMaxStorageObjectSize(int maxStorageBlockSize)voidsetMemoryBufferSpace(long maxBufferSpace)voidsetMinDefrag(long minDefrag)voidsetStorageManager(StorageManager storageManager)voidsetTruncateInterval(int truncateInterval)voidshutdown()voidunlockForLoad(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:
initializein interfaceStorageManager- Throws:
TeiidComponentException
-
add
public boolean add(CacheEntry entry, Serializer s)
Description copied from interface:CacheAdds an entry to the cache.
-
lockForLoad
public org.teiid.common.buffer.impl.PhysicalInfo lockForLoad(Long oid, Serializer<?> serializer)
Description copied from interface:CacheLock the object for load and return an identifier/lock that can be used to retrieve the object.- Specified by:
lockForLoadin 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:CacheMust be called after lockForLoad- Specified by:
unlockForLoadin interfaceCache<org.teiid.common.buffer.impl.PhysicalInfo>
-
getCacheGroupCount
public int getCacheGroupCount()
- Specified by:
getCacheGroupCountin 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:CacheGet method, must be called using the object obtained in the lockForLoad method- Specified by:
getin interfaceCache<org.teiid.common.buffer.impl.PhysicalInfo>- Returns:
- Throws:
TeiidComponentException
-
createFileStore
public FileStore createFileStore(String name)
- Specified by:
createFileStorein interfaceStorageManager
-
setDirect
public void setDirect(boolean direct)
-
addToCacheGroup
public boolean addToCacheGroup(Long gid, Long oid)
Description copied from interface:CacheMust be called prior to adding an entry- Specified by:
addToCacheGroupin interfaceCache<org.teiid.common.buffer.impl.PhysicalInfo>- Returns:
- if the add was successful
-
createCacheGroup
public void createCacheGroup(Long gid)
Description copied from interface:CacheMust be called prior to adding any group entries- Specified by:
createCacheGroupin interfaceCache<org.teiid.common.buffer.impl.PhysicalInfo>
-
remove
public Integer remove(Long gid, Long id)
Description copied from interface:CacheRemove an entry from the cache, return the sizeEstimate if the entry existed
-
removeCacheGroup
public Collection<Long> removeCacheGroup(Long gid)
Description copied from interface:CacheRemove an entire cache group TODO: this should use a callback on the buffermangaer to remove memory entries without materializing all group keys- Specified by:
removeCacheGroupin 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:
getMemoryBufferSpacein 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:
getMaxStorageSpacein interfaceStorageManager
-
-