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 ClassesModifier and TypeClassDescription(package private) class(package private) classNested classes/interfaces inherited from interface StorageEngine
StorageEngine.Owner -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate static final intprivate static final intprivate static final org.slf4j.Loggerprivate static final intprivate static final intprivate final longprivate StorageEngine.Ownerprivate final ConcurrentHashMap<Long, FileBackedStorageEngine<K, V>.FileWriteTask> private final ReopeningInterruptibleChannel<FileChannel> private final MappedPageSourceprivate static final intprivate final ReopeningInterruptibleChannel<FileChannel> private final ExecutorServiceFields inherited from class PortabilityBasedStorageEngine
keyPortability, valuePortability -
Constructor Summary
ConstructorsConstructorDescriptionFileBackedStorageEngine(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, ExecutorService writer) FileBackedStorageEngine(MappedPageSource source, long maxChunkSize, MemoryUnit maxChunkUnit, Portability<? super K> keyPortability, Portability<? super V> valuePortability, ExecutorService writer, boolean bootstrap) -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidbootstrap(ObjectInput input) protected voidvoidclose()private voidcompress(FileBackedStorageEngine<K, V>.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 ExecutorService> executorFactory, boolean bootstrap) voiddestroy()private FileBackedStorageEngine<K,V>.FileChunk findChunk(long address) voidflush()protected voidfree(long address) longReturns a measure of the amount of memory allocated for this storage engine.longReturns a measure of the total size of the keys and values stored in this storage engine.protected WriteContextgetKeyWriteContext(long address) longReturns a measure of the amount of memory consumed by this storage engine.protected WriteContextgetValueWriteContext(long address) longReturns a measure of the amount of vital memory allocated for this storage engine.voidpersist(ObjectOutput output) private intreadFromChannel(ByteBuffer buffer, long position) private intreadFromChannel(FileChannel channel, ByteBuffer buffer, long position) private intreadIntFromChannel(long position) protected ByteBufferreadKeyBuffer(long address) intreadKeyHash(long address) protected ByteBufferreadValueBuffer(long address) booleanshrink()private voidwriteIntToChannel(long position, int data) private voidwriteLongToChannel(long position, long data) protected LongwriteMappingBuffers(ByteBuffer keyBuffer, ByteBuffer valueBuffer, int hash) private voidwriteToChannel(long position, ByteBuffer buffer) Methods inherited from class PortabilityBasedStorageEngine
attachedMapping, clear, equalsBinaryKey, equalsKey, equalsValue, freeMapping, invalidateCache, readBinaryKey, readBinaryValue, readKey, readValue, writeBinaryMapping, writeBinaryMapping, writeMapping, writeMappingBuffersGatheringMethods inherited from class AbstractListenableStorageEngine
fireCleared, fireCopied, fireFreed, fireRecovered, fireWritten, hasListeners, hasRecoveryListeners, registerListenerMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface StorageEngine
attachedMapping, clear, equalsKey, equalsValue, freeMapping, invalidateCache, readKey, readValue, writeMapping
-
Field Details
-
MAGIC
private static final int MAGIC- See Also:
-
MAGIC_CHUNK
private static final int MAGIC_CHUNK- See Also:
-
LOGGER
private static final org.slf4j.Logger LOGGER -
KEY_HASH_OFFSET
private static final int KEY_HASH_OFFSET- See Also:
-
KEY_LENGTH_OFFSET
private static final int KEY_LENGTH_OFFSET- See Also:
-
VALUE_LENGTH_OFFSET
private static final int VALUE_LENGTH_OFFSET- See Also:
-
KEY_DATA_OFFSET
private static final int KEY_DATA_OFFSET- See Also:
-
pendingWrites
-
writeExecutor
-
source
-
writeChannel
-
readChannel
-
chunks
-
maxChunkSize
private final long maxChunkSize -
owner
-
-
Constructor Details
-
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, 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, ExecutorService writer, boolean bootstrap)
-
-
Method Details
-
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 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
- Specified by:
flushin interfacePersistent- Throws:
IOException
-
close
- Specified by:
closein interfacePersistent- Throws:
IOException
-
persist
- Specified by:
persistin interfacePersistent- Throws:
IOException
-
bootstrap
- Specified by:
bootstrapin interfacePersistent- Throws:
IOException
-
free
protected void free(long address) - Specified by:
freein classPortabilityBasedStorageEngine<K,V>
-
readKeyBuffer
- Specified by:
readKeyBufferin classPortabilityBasedStorageEngine<K,V>
-
getKeyWriteContext
- Specified by:
getKeyWriteContextin classPortabilityBasedStorageEngine<K,V>
-
readValueBuffer
- Specified by:
readValueBufferin classPortabilityBasedStorageEngine<K,V>
-
getValueWriteContext
- Specified by:
getValueWriteContextin classPortabilityBasedStorageEngine<K,V>
-
writeMappingBuffers
- 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
-
readIntFromChannel
- Throws:
IOException
-
writeIntToChannel
- Throws:
IOException
-
writeLongToChannel
- Throws:
IOException
-
writeToChannel
- Throws:
IOException
-
readFromChannel
- Throws:
IOException
-
readFromChannel
private int readFromChannel(FileChannel channel, ByteBuffer buffer, long position) throws IOException - Throws:
IOException
-
shrink
public boolean shrink()- Specified by:
shrinkin interfaceStorageEngine<K,V>
-
compress
-
bind
- Specified by:
bindin interfaceStorageEngine<K,V>
-
readKeyHash
public int readKeyHash(long address) - Specified by:
readKeyHashin interfaceBinaryStorageEngine
-