Class FileBackedStorageEngine<K,V>
- java.lang.Object
-
- org.terracotta.offheapstore.storage.listener.AbstractListenableStorageEngine<K,V>
-
- org.terracotta.offheapstore.storage.PortabilityBasedStorageEngine<K,V>
-
- org.terracotta.offheapstore.disk.storage.FileBackedStorageEngine<K,V>
-
- All Implemented Interfaces:
Persistent,PersistentStorageEngine<K,V>,BinaryStorageEngine,ListenableStorageEngine<K,V>,StorageEngine<K,V>
public class FileBackedStorageEngine<K,V> extends PortabilityBasedStorageEngine<K,V> implements PersistentStorageEngine<K,V>
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) classFileBackedStorageEngine.FileChunk(package private) classFileBackedStorageEngine.FileWriteTask-
Nested classes/interfaces inherited from interface org.terracotta.offheapstore.storage.StorageEngine
StorageEngine.Owner
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.TreeMap<java.lang.Long,FileBackedStorageEngine.FileChunk>chunksprivate static intKEY_DATA_OFFSETprivate static intKEY_HASH_OFFSETprivate static intKEY_LENGTH_OFFSETprivate static org.slf4j.LoggerLOGGERprivate static intMAGICprivate static intMAGIC_CHUNKprivate longmaxChunkSizeprivate StorageEngine.Ownerownerprivate java.util.concurrent.ConcurrentHashMap<java.lang.Long,FileBackedStorageEngine.FileWriteTask>pendingWritesprivate ReopeningInterruptibleChannel<java.nio.channels.FileChannel>readChannelprivate MappedPageSourcesourceprivate static intVALUE_LENGTH_OFFSETprivate ReopeningInterruptibleChannel<java.nio.channels.FileChannel>writeChannelprivate java.util.concurrent.ExecutorServicewriteExecutor-
Fields inherited from class org.terracotta.offheapstore.storage.PortabilityBasedStorageEngine
keyPortability, valuePortability
-
-
Constructor Summary
Constructors Constructor Description FileBackedStorageEngine(MappedPageSource source, long maxChunkSize, MemoryUnit maxChunkUnit, Portability<? super K> keyPortability, Portability<? super V> valuePortability)FileBackedStorageEngine(MappedPageSource source, long maxChunkSize, MemoryUnit maxChunkUnit, Portability<? super K> keyPortability, Portability<? super V> valuePortability, boolean bootstrap)FileBackedStorageEngine(MappedPageSource source, long maxChunkSize, MemoryUnit maxChunkUnit, Portability<? super K> keyPortability, Portability<? super V> valuePortability, java.util.concurrent.ExecutorService writer)FileBackedStorageEngine(MappedPageSource source, long maxChunkSize, MemoryUnit maxChunkUnit, Portability<? super K> keyPortability, Portability<? super V> valuePortability, java.util.concurrent.ExecutorService writer, boolean bootstrap)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbind(StorageEngine.Owner m)voidbootstrap(java.io.ObjectInput input)protected voidclearInternal()voidclose()private voidcompress(FileBackedStorageEngine.FileChunk from)static <K,V>
Factory<FileBackedStorageEngine<K,V>>createFactory(MappedPageSource source, long maxChunkSize, MemoryUnit maxChunkUnit, Portability<? super K> keyPortability, Portability<? super V> valuePortability)static <K,V>
Factory<FileBackedStorageEngine<K,V>>createFactory(MappedPageSource source, long maxChunkSize, MemoryUnit maxChunkUnit, Portability<? super K> keyPortability, Portability<? super V> valuePortability, boolean bootstrap)static <K,V>
Factory<FileBackedStorageEngine<K,V>>createFactory(MappedPageSource source, long maxChunkSize, MemoryUnit maxChunkUnit, Portability<? super K> keyPortability, Portability<? super V> valuePortability, Factory<? extends java.util.concurrent.ExecutorService> executorFactory, boolean bootstrap)voiddestroy()private FileBackedStorageEngine.FileChunkfindChunk(long address)voidflush()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.voidpersist(java.io.ObjectOutput output)private intreadFromChannel(java.nio.ByteBuffer buffer, long position)private intreadFromChannel(java.nio.channels.FileChannel channel, java.nio.ByteBuffer buffer, long position)private intreadIntFromChannel(long position)protected java.nio.ByteBufferreadKeyBuffer(long address)intreadKeyHash(long address)protected java.nio.ByteBufferreadValueBuffer(long address)booleanshrink()private voidwriteIntToChannel(long position, int data)private voidwriteLongToChannel(long position, long data)protected java.lang.LongwriteMappingBuffers(java.nio.ByteBuffer keyBuffer, java.nio.ByteBuffer valueBuffer, int hash)private voidwriteToChannel(long position, java.nio.ByteBuffer buffer)-
Methods inherited from class org.terracotta.offheapstore.storage.PortabilityBasedStorageEngine
attachedMapping, clear, equalsBinaryKey, equalsKey, equalsValue, freeMapping, invalidateCache, readBinaryKey, readBinaryValue, readKey, readValue, writeBinaryMapping, writeBinaryMapping, writeMapping, writeMappingBuffersGathering
-
Methods inherited from class org.terracotta.offheapstore.storage.listener.AbstractListenableStorageEngine
fireCleared, fireCopied, fireFreed, fireRecovered, fireWritten, hasListeners, hasRecoveryListeners, registerListener
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.terracotta.offheapstore.storage.StorageEngine
attachedMapping, clear, equalsKey, equalsValue, freeMapping, invalidateCache, readKey, readValue, writeMapping
-
-
-
-
Field Detail
-
MAGIC
private static final int MAGIC
- See Also:
- Constant Field Values
-
MAGIC_CHUNK
private static final int MAGIC_CHUNK
- See Also:
- Constant Field Values
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
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
-
KEY_DATA_OFFSET
private static final int KEY_DATA_OFFSET
- See Also:
- Constant Field Values
-
pendingWrites
private final java.util.concurrent.ConcurrentHashMap<java.lang.Long,FileBackedStorageEngine.FileWriteTask> pendingWrites
-
writeExecutor
private final java.util.concurrent.ExecutorService writeExecutor
-
source
private final MappedPageSource source
-
writeChannel
private final ReopeningInterruptibleChannel<java.nio.channels.FileChannel> writeChannel
-
readChannel
private final ReopeningInterruptibleChannel<java.nio.channels.FileChannel> readChannel
-
chunks
private final java.util.TreeMap<java.lang.Long,FileBackedStorageEngine.FileChunk> chunks
-
maxChunkSize
private final long maxChunkSize
-
owner
private volatile StorageEngine.Owner owner
-
-
Constructor Detail
-
FileBackedStorageEngine
public FileBackedStorageEngine(MappedPageSource source, long maxChunkSize, MemoryUnit maxChunkUnit, Portability<? super K> keyPortability, Portability<? super V> valuePortability)
-
FileBackedStorageEngine
public FileBackedStorageEngine(MappedPageSource source, long maxChunkSize, MemoryUnit maxChunkUnit, Portability<? super K> keyPortability, Portability<? super V> valuePortability, java.util.concurrent.ExecutorService writer)
-
FileBackedStorageEngine
public FileBackedStorageEngine(MappedPageSource source, long maxChunkSize, MemoryUnit maxChunkUnit, Portability<? super K> keyPortability, Portability<? super V> valuePortability, boolean bootstrap)
-
FileBackedStorageEngine
public FileBackedStorageEngine(MappedPageSource source, long maxChunkSize, MemoryUnit maxChunkUnit, Portability<? super K> keyPortability, Portability<? super V> valuePortability, java.util.concurrent.ExecutorService writer, boolean bootstrap)
-
-
Method Detail
-
createFactory
public static <K,V> Factory<FileBackedStorageEngine<K,V>> createFactory(MappedPageSource source, long maxChunkSize, MemoryUnit maxChunkUnit, Portability<? super K> keyPortability, Portability<? super V> valuePortability)
-
createFactory
public static <K,V> Factory<FileBackedStorageEngine<K,V>> createFactory(MappedPageSource source, long maxChunkSize, MemoryUnit maxChunkUnit, Portability<? super K> keyPortability, Portability<? super V> valuePortability, boolean bootstrap)
-
createFactory
public static <K,V> Factory<FileBackedStorageEngine<K,V>> createFactory(MappedPageSource source, long maxChunkSize, MemoryUnit maxChunkUnit, Portability<? super K> keyPortability, Portability<? super V> valuePortability, Factory<? extends java.util.concurrent.ExecutorService> executorFactory, boolean bootstrap)
-
clearInternal
protected void clearInternal()
- Specified by:
clearInternalin classPortabilityBasedStorageEngine<K,V>
-
destroy
public void destroy()
- Specified by:
destroyin interfaceStorageEngine<K,V>
-
flush
public void flush() throws java.io.IOException- Specified by:
flushin interfacePersistent- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacePersistent- Throws:
java.io.IOException
-
persist
public void persist(java.io.ObjectOutput output) throws java.io.IOException- Specified by:
persistin interfacePersistent- Throws:
java.io.IOException
-
bootstrap
public void bootstrap(java.io.ObjectInput input) throws java.io.IOException- Specified by:
bootstrapin interfacePersistent- Throws:
java.io.IOException
-
free
protected void free(long address)
- Specified by:
freein classPortabilityBasedStorageEngine<K,V>
-
readKeyBuffer
protected 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
protected java.nio.ByteBuffer readValueBuffer(long address)
- Specified by:
readValueBufferin classPortabilityBasedStorageEngine<K,V>
-
getValueWriteContext
protected WriteContext getValueWriteContext(long address)
- Specified by:
getValueWriteContextin classPortabilityBasedStorageEngine<K,V>
-
writeMappingBuffers
protected java.lang.Long writeMappingBuffers(java.nio.ByteBuffer keyBuffer, java.nio.ByteBuffer valueBuffer, int hash)- Specified by:
writeMappingBuffersin 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
-
findChunk
private FileBackedStorageEngine.FileChunk findChunk(long address)
-
readIntFromChannel
private int readIntFromChannel(long position) throws java.io.IOException- Throws:
java.io.IOException
-
writeIntToChannel
private void writeIntToChannel(long position, int data) throws java.io.IOException- Throws:
java.io.IOException
-
writeLongToChannel
private void writeLongToChannel(long position, long data) throws java.io.IOException- Throws:
java.io.IOException
-
writeToChannel
private void writeToChannel(long position, java.nio.ByteBuffer buffer) throws java.io.IOException- Throws:
java.io.IOException
-
readFromChannel
private int readFromChannel(java.nio.ByteBuffer buffer, long position) throws java.io.IOException- Throws:
java.io.IOException
-
readFromChannel
private int readFromChannel(java.nio.channels.FileChannel channel, java.nio.ByteBuffer buffer, long position) throws java.io.IOException- Throws:
java.io.IOException
-
shrink
public boolean shrink()
- Specified by:
shrinkin interfaceStorageEngine<K,V>
-
compress
private void compress(FileBackedStorageEngine.FileChunk from)
-
bind
public void bind(StorageEngine.Owner m)
- Specified by:
bindin interfaceStorageEngine<K,V>
-
readKeyHash
public int readKeyHash(long address)
- Specified by:
readKeyHashin interfaceBinaryStorageEngine
-
-