Class OffHeapBufferStorageEngine<K,V>
- java.lang.Object
-
- org.terracotta.offheapstore.storage.listener.AbstractListenableStorageEngine<K,V>
-
- org.terracotta.offheapstore.storage.PortabilityBasedStorageEngine<K,V>
-
- org.terracotta.offheapstore.storage.OffHeapBufferStorageEngine<K,V>
-
- Type Parameters:
K- key type handled by this engineV- value type handled by this engine
- All Implemented Interfaces:
OffHeapStorageArea.Owner,BinaryStorageEngine,ListenableStorageEngine<K,V>,StorageEngine<K,V>
- Direct Known Subclasses:
SerializableStorageEngine,StringStorageEngine
public class OffHeapBufferStorageEngine<K,V> extends PortabilityBasedStorageEngine<K,V> implements OffHeapStorageArea.Owner
A generic ByteBuffer based key/value store.This storage engine implementation uses
Portabilityinstances to convert key/value instances in to ByteBuffers. The content of these ByteBuffers are then stored in slices of a single large data area.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.terracotta.offheapstore.storage.PortabilityBasedStorageEngine
PortabilityBasedStorageEngine.CachedEncode<K,V>
-
Nested classes/interfaces inherited from interface org.terracotta.offheapstore.storage.StorageEngine
StorageEngine.Owner
-
-
Field Summary
Fields Modifier and Type Field Description private static intDATA_OFFSETprivate static intHEADER_SIZEprivate static intKEY_HASH_OFFSETprivate static intKEY_LENGTH_OFFSETprotected StorageEngine.Ownerownerprotected OffHeapStorageAreastorageAreaprivate static intVALUE_LENGTH_OFFSET-
Fields inherited from class org.terracotta.offheapstore.storage.PortabilityBasedStorageEngine
keyPortability, valuePortability
-
-
Constructor Summary
Constructors Constructor Description OffHeapBufferStorageEngine(PointerSize width, PageSource source, int initialPageSize, int maximalPageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability)OffHeapBufferStorageEngine(PointerSize width, PageSource source, int initialPageSize, int maximalPageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability, boolean thief, boolean victim)OffHeapBufferStorageEngine(PointerSize width, PageSource source, int initialPageSize, int maximalPageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability, boolean thief, boolean victim, float compressThreshold)OffHeapBufferStorageEngine(PointerSize width, PageSource source, int initialPageSize, int maximalPageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability, float compressThreshold)OffHeapBufferStorageEngine(PointerSize width, PageSource source, int pageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability)Creates a storage engine using the given page source, and portabilities.OffHeapBufferStorageEngine(PointerSize width, PageSource source, int pageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability, boolean thief, boolean victim)OffHeapBufferStorageEngine(PointerSize width, PageSource source, int pageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability, boolean thief, boolean victim, float compressThreshold)OffHeapBufferStorageEngine(PointerSize width, PageSource source, int pageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability, float compressThreshold)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbind(StorageEngine.Owner m)protected voidclearInternal()static <K,V>
Factory<OffHeapBufferStorageEngine<K,V>>createFactory(PointerSize width, PageSource source, int initialPageSize, int maximalPageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability, boolean thief, boolean victim)static <K,V>
Factory<OffHeapBufferStorageEngine<K,V>>createFactory(PointerSize width, PageSource source, int initialPageSize, int maximalPageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability, boolean thief, boolean victim, float compressThreshold)static <K,V>
Factory<OffHeapBufferStorageEngine<K,V>>createFactory(PointerSize width, PageSource source, int pageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability, boolean thief, boolean victim)static <K,V>
Factory<OffHeapBufferStorageEngine<K,V>>createFactory(PointerSize width, PageSource source, int pageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability, boolean thief, boolean victim, float compressThreshold)voiddestroy()java.util.Collection<java.lang.Long>evictAtAddress(long address, boolean shrink)protected voidfree(long address)longgetAllocatedMemory()Returns a measure of the amount of memory allocated for this storage engine.longgetDataSize()Returns a measure of the total size of the keys and values stored in this storage engine.protected WriteContextgetKeyWriteContext(long address)longgetOccupiedMemory()Returns a measure of the amount of memory consumed by this storage engine.protected WriteContextgetValueWriteContext(long address)longgetVitalMemory()Returns a measure of the amount of vital memory allocated for this storage engine.private WriteContextgetWriteContext(long address, int max)booleanisThief()booleanmoved(long from, long to)java.nio.ByteBufferreadKeyBuffer(long address)intreadKeyHash(long encoding)java.nio.ByteBufferreadValueBuffer(long address)booleanshrink()intsizeOf(long address)java.lang.StringtoString()java.util.concurrent.locks.LockwriteLock()protected java.lang.LongwriteMappingBuffers(java.nio.ByteBuffer keyBuffer, java.nio.ByteBuffer valueBuffer, int hash)protected java.lang.LongwriteMappingBuffersGathering(java.nio.ByteBuffer[] keyBuffers, java.nio.ByteBuffer[] valueBuffers, int hash)-
Methods inherited from class org.terracotta.offheapstore.storage.PortabilityBasedStorageEngine
attachedMapping, clear, equalsBinaryKey, equalsKey, equalsValue, freeMapping, invalidateCache, readBinaryKey, readBinaryValue, readKey, readValue, writeBinaryMapping, writeBinaryMapping, writeMapping
-
Methods inherited from class org.terracotta.offheapstore.storage.listener.AbstractListenableStorageEngine
fireCleared, fireCopied, fireFreed, fireRecovered, fireWritten, hasListeners, hasRecoveryListeners, registerListener
-
-
-
-
Field Detail
-
KEY_HASH_OFFSET
private static final int KEY_HASH_OFFSET
- See Also:
- Constant Field Values
-
KEY_LENGTH_OFFSET
private static final int KEY_LENGTH_OFFSET
- See Also:
- Constant Field Values
-
VALUE_LENGTH_OFFSET
private static final int VALUE_LENGTH_OFFSET
- See Also:
- Constant Field Values
-
DATA_OFFSET
private static final int DATA_OFFSET
- See Also:
- Constant Field Values
-
HEADER_SIZE
private static final int HEADER_SIZE
- See Also:
- Constant Field Values
-
storageArea
protected final OffHeapStorageArea storageArea
-
owner
protected volatile StorageEngine.Owner owner
-
-
Constructor Detail
-
OffHeapBufferStorageEngine
public OffHeapBufferStorageEngine(PointerSize width, PageSource source, int pageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability)
Creates a storage engine using the given page source, and portabilities.- Parameters:
width-intorlongbased enginesource- allocator used for storage allocationpageSize- internal (constant) page sizekeyPortability- key type portabilityvaluePortability- value type portability
-
OffHeapBufferStorageEngine
public OffHeapBufferStorageEngine(PointerSize width, PageSource source, int pageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability, float compressThreshold)
-
OffHeapBufferStorageEngine
public OffHeapBufferStorageEngine(PointerSize width, PageSource source, int initialPageSize, int maximalPageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability)
-
OffHeapBufferStorageEngine
public OffHeapBufferStorageEngine(PointerSize width, PageSource source, int initialPageSize, int maximalPageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability, float compressThreshold)
-
OffHeapBufferStorageEngine
public OffHeapBufferStorageEngine(PointerSize width, PageSource source, int pageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability, boolean thief, boolean victim)
-
OffHeapBufferStorageEngine
public OffHeapBufferStorageEngine(PointerSize width, PageSource source, int pageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability, boolean thief, boolean victim, float compressThreshold)
-
OffHeapBufferStorageEngine
public OffHeapBufferStorageEngine(PointerSize width, PageSource source, int initialPageSize, int maximalPageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability, boolean thief, boolean victim)
-
OffHeapBufferStorageEngine
public OffHeapBufferStorageEngine(PointerSize width, PageSource source, int initialPageSize, int maximalPageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability, boolean thief, boolean victim, float compressThreshold)
-
-
Method Detail
-
createFactory
public static <K,V> Factory<OffHeapBufferStorageEngine<K,V>> createFactory(PointerSize width, PageSource source, int pageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability, boolean thief, boolean victim)
-
createFactory
public static <K,V> Factory<OffHeapBufferStorageEngine<K,V>> createFactory(PointerSize width, PageSource source, int pageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability, boolean thief, boolean victim, float compressThreshold)
-
createFactory
public static <K,V> Factory<OffHeapBufferStorageEngine<K,V>> createFactory(PointerSize width, PageSource source, int initialPageSize, int maximalPageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability, boolean thief, boolean victim)
-
createFactory
public static <K,V> Factory<OffHeapBufferStorageEngine<K,V>> createFactory(PointerSize width, PageSource source, int initialPageSize, int maximalPageSize, Portability<? super K> keyPortability, Portability<? super V> valuePortability, boolean thief, boolean victim, float compressThreshold)
-
clearInternal
protected void clearInternal()
- Specified by:
clearInternalin classPortabilityBasedStorageEngine<K,V>
-
free
protected void free(long address)
- Specified by:
freein classPortabilityBasedStorageEngine<K,V>
-
readKeyBuffer
public java.nio.ByteBuffer readKeyBuffer(long address)
- Specified by:
readKeyBufferin classPortabilityBasedStorageEngine<K,V>
-
getKeyWriteContext
protected WriteContext getKeyWriteContext(long address)
- Specified by:
getKeyWriteContextin classPortabilityBasedStorageEngine<K,V>
-
readValueBuffer
public java.nio.ByteBuffer readValueBuffer(long address)
- Specified by:
readValueBufferin classPortabilityBasedStorageEngine<K,V>
-
getValueWriteContext
protected WriteContext getValueWriteContext(long address)
- Specified by:
getValueWriteContextin classPortabilityBasedStorageEngine<K,V>
-
getWriteContext
private WriteContext getWriteContext(long address, int max)
-
writeMappingBuffers
protected java.lang.Long writeMappingBuffers(java.nio.ByteBuffer keyBuffer, java.nio.ByteBuffer valueBuffer, int hash)- Specified by:
writeMappingBuffersin classPortabilityBasedStorageEngine<K,V>
-
writeMappingBuffersGathering
protected java.lang.Long writeMappingBuffersGathering(java.nio.ByteBuffer[] keyBuffers, java.nio.ByteBuffer[] valueBuffers, int hash)- Overrides:
writeMappingBuffersGatheringin classPortabilityBasedStorageEngine<K,V>
-
getAllocatedMemory
public long getAllocatedMemory()
Description copied from interface:StorageEngineReturns a measure of the amount of memory allocated for this storage engine.- Specified by:
getAllocatedMemoryin interfaceStorageEngine<K,V>- Returns:
- memory allocated for this engine in bytes
-
getOccupiedMemory
public long getOccupiedMemory()
Description copied from interface:StorageEngineReturns a measure of the amount of memory consumed by this storage engine.- Specified by:
getOccupiedMemoryin interfaceStorageEngine<K,V>- Returns:
- memory occupied by this engine in bytes
-
getVitalMemory
public long getVitalMemory()
Description copied from interface:StorageEngineReturns a measure of the amount of vital memory allocated for this storage engine.- Specified by:
getVitalMemoryin interfaceStorageEngine<K,V>- Returns:
- vital memory allocated for this engine in bytes
-
getDataSize
public long getDataSize()
Description copied from interface:StorageEngineReturns a measure of the total size of the keys and values stored in this storage engine.- Specified by:
getDataSizein interfaceStorageEngine<K,V>- Returns:
- size of the stored keys and values in bytes
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
destroy
public void destroy()
- Specified by:
destroyin interfaceStorageEngine<K,V>
-
shrink
public boolean shrink()
- Specified by:
shrinkin interfaceStorageEngine<K,V>
-
evictAtAddress
public java.util.Collection<java.lang.Long> evictAtAddress(long address, boolean shrink)- Specified by:
evictAtAddressin interfaceOffHeapStorageArea.Owner
-
isThief
public boolean isThief()
- Specified by:
isThiefin interfaceOffHeapStorageArea.Owner
-
readKeyHash
public int readKeyHash(long encoding)
- Specified by:
readKeyHashin interfaceBinaryStorageEngine
-
moved
public boolean moved(long from, long to)- Specified by:
movedin interfaceOffHeapStorageArea.Owner
-
sizeOf
public int sizeOf(long address)
- Specified by:
sizeOfin interfaceOffHeapStorageArea.Owner
-
bind
public void bind(StorageEngine.Owner m)
- Specified by:
bindin interfaceStorageEngine<K,V>
-
writeLock
public java.util.concurrent.locks.Lock writeLock()
- Specified by:
writeLockin interfaceOffHeapStorageArea.Owner
-
-