Package org.h2.mvstore
Class RandomAccessStore
- java.lang.Object
-
- org.h2.mvstore.FileStore<SFChunk>
-
- org.h2.mvstore.RandomAccessStore
-
- Direct Known Subclasses:
OffHeapStore,SingleFileStore
public abstract class RandomAccessStore extends FileStore<SFChunk>
Class RandomAccessStore.- 4/5/20 2:51 PM initial creation
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.h2.mvstore.FileStore
FileStore.PageSerializationManager
-
-
Field Summary
Fields Modifier and Type Field Description protected FreeSpaceBitSetfreeSpaceThe free spaces between the chunks.-
Fields inherited from class org.h2.mvstore.FileStore
lastChunk, META_ID_KEY, PIPE_LENGTH, readBytes, readCount, recoveryMode, saveChunkLock, storeHeader, writeBytes, writeCount
-
-
Constructor Summary
Constructors Constructor Description RandomAccessStore(java.util.Map<java.lang.String,java.lang.Object> config)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidadjustStoreToLastChunk()Make persistent changes after lastChunk was resetprotected voidallocateChunkSpace(SFChunk chunk, WriteBuffer buff)Allocate logical space and assign position of the buffer within the store.voidclear()Mark the file as empty.voidcompactMoveChunks(int targetFillRate, long moveSize, MVStore mvStore)Compact the store by moving all chunks next to each other, if there is free space between chunks.protected voidcompactStore(int thresholdFillRate, long maxCompactTime, int maxWriteSize, MVStore mvStore)Compact store file, that is, compact blocks that have a low fill rate, and move chunks next to each other.protected SFChunkcreateChunk(int newChunkId)SFChunkcreateChunk(java.lang.String s)Build a Chunk from the given string.protected SFChunkcreateChunk(java.util.Map<java.lang.String,java.lang.String> map)protected voiddoHousekeeping(MVStore mvStore)protected voidfree(long pos, int length)Mark the space as free.protected voidfreeChunkSpace(java.lang.Iterable<SFChunk> chunks)Mark the space occupied by specified chunks as free.intgetFillRate()intgetMovePriority(int block)Calculates relative "priority" for chunk to be moved.java.util.Collection<SFChunk>getRewriteCandidates()protected voidinitializeStoreHeader(long time)booleanisSpaceReused()voidmarkUsed(long pos, int length)Mark the space as in use.protected voidreadStoreHeader(boolean recoveryMode)voidsetReuseSpace(boolean reuseSpace)booleanshouldSaveNow(int unsavedMemory, int autoCommitMemory)Decision about autocommit is delegated to storeprotected voidshrinkStoreIfPossible(int minPercent)Shrink the store if possible, and if at least a given percentage can be saved.protected abstract voidtruncate(long size)protected booleanvalidateFileLength(java.lang.String msg)protected voidwriteChunk(SFChunk chunk, WriteBuffer buffer)Write buffer associated with chunk into store at chunk's allocated positionprotected voidwriteCleanShutdownMark()Performs final preparation before store is closed normally-
Methods inherited from class org.h2.mvstore.FileStore
accountForRemovedPage, backup, bind, close, compact, compactStore, deregisterMapRoot, discoverChunk, dropUnusedChunks, executeFileStoreOperation, findLastChunkWithCompleteValidChunkSet, getAutoCommitDelay, getAutoCompactFillRate, getCacheHitRatio, getCacheSize, getCacheSizeUsed, getChunks, getChunksFillRate, getChunksFromLayoutMap, getCreationTime, getDefaultRetentionTime, getFileName, getLayoutMap, getMaxPageSize, getMetaMapId, getMvStore, getReadBytes, getReadCount, getRetentionTime, getRootPos, getStoreHeader, getTocCacheHitRatio, getWriteBuffer, getWriteCount, hasChangesSince, hasPersistentData, init, initializeCommonHeaderAttributes, isIdle, isKnownVersion, isReadOnly, isRegularMap, lastChunkVersion, open, open, populateInfo, processCommonHeaderAttributes, readChunkFooter, readChunkHeaderAndFooter, readChunkHeaderOptionally, readChunkHeaderOptionally, readFully, readFully, registerDeadChunk, releaseWriteBuffer, rewriteChunks, rollbackTo, saveChunkMetadataChanges, setAutoCommitDelay, setCacheSize, setLastChunk, setRetentionTime, setSize, size, start, stop, store, submitOrRun, sync, writeCleanShutdown, writeFully
-
-
-
-
Field Detail
-
freeSpace
protected final FreeSpaceBitSet freeSpace
The free spaces between the chunks. The first block to use is block 2 (the first two blocks are the store header). Access to this object is protected byFileStore.saveChunkLock
-
-
Method Detail
-
createChunk
protected final SFChunk createChunk(int newChunkId)
- Specified by:
createChunkin classFileStore<SFChunk>
-
createChunk
public SFChunk createChunk(java.lang.String s)
Description copied from class:FileStoreBuild a Chunk from the given string.- Specified by:
createChunkin classFileStore<SFChunk>- Parameters:
s- the string- Returns:
- the Chunk created
-
createChunk
protected SFChunk createChunk(java.util.Map<java.lang.String,java.lang.String> map)
- Specified by:
createChunkin classFileStore<SFChunk>
-
markUsed
public void markUsed(long pos, int length)Mark the space as in use.
-
shouldSaveNow
public boolean shouldSaveNow(int unsavedMemory, int autoCommitMemory)Description copied from class:FileStoreDecision about autocommit is delegated to store- Specified by:
shouldSaveNowin classFileStore<SFChunk>- Parameters:
unsavedMemory- amount of unsaved memory, so farautoCommitMemory- configured limit on amount of unsaved memory- Returns:
- true if commit should happen now
-
isSpaceReused
public boolean isSpaceReused()
- Overrides:
isSpaceReusedin classFileStore<SFChunk>
-
setReuseSpace
public void setReuseSpace(boolean reuseSpace)
- Overrides:
setReuseSpacein classFileStore<SFChunk>
-
freeChunkSpace
protected void freeChunkSpace(java.lang.Iterable<SFChunk> chunks)
Description copied from class:FileStoreMark the space occupied by specified chunks as free.- Specified by:
freeChunkSpacein classFileStore<SFChunk>- Parameters:
chunks- chunks to be processed
-
free
protected void free(long pos, int length)Mark the space as free.- Parameters:
pos- the position in byteslength- the number of bytes
-
getFillRate
public int getFillRate()
- Specified by:
getFillRatein classFileStore<SFChunk>
-
validateFileLength
protected final boolean validateFileLength(java.lang.String msg)
- Specified by:
validateFileLengthin classFileStore<SFChunk>
-
readStoreHeader
protected void readStoreHeader(boolean recoveryMode)
- Specified by:
readStoreHeaderin classFileStore<SFChunk>
-
initializeStoreHeader
protected void initializeStoreHeader(long time)
- Specified by:
initializeStoreHeaderin classFileStore<SFChunk>
-
allocateChunkSpace
protected final void allocateChunkSpace(SFChunk chunk, WriteBuffer buff)
Description copied from class:FileStoreAllocate logical space and assign position of the buffer within the store.- Specified by:
allocateChunkSpacein classFileStore<SFChunk>- Parameters:
chunk- to allocate space forbuff- to allocate space for
-
writeChunk
protected final void writeChunk(SFChunk chunk, WriteBuffer buffer)
Description copied from class:FileStoreWrite buffer associated with chunk into store at chunk's allocated position- Specified by:
writeChunkin classFileStore<SFChunk>- Parameters:
chunk- chunk to writebuffer- to write
-
writeCleanShutdownMark
protected final void writeCleanShutdownMark()
Description copied from class:FileStorePerforms final preparation before store is closed normally- Specified by:
writeCleanShutdownMarkin classFileStore<SFChunk>
-
adjustStoreToLastChunk
protected final void adjustStoreToLastChunk()
Description copied from class:FileStoreMake persistent changes after lastChunk was reset- Specified by:
adjustStoreToLastChunkin classFileStore<SFChunk>
-
compactStore
protected void compactStore(int thresholdFillRate, long maxCompactTime, int maxWriteSize, MVStore mvStore)Compact store file, that is, compact blocks that have a low fill rate, and move chunks next to each other. This will typically shrink the file. Changes are flushed to the file, and old chunks are overwritten.- Specified by:
compactStorein classFileStore<SFChunk>- Parameters:
thresholdFillRate- do not compact if store fill rate above this value (0-100)maxCompactTime- the maximum time in milliseconds to compactmaxWriteSize- the maximum amount of data to be written as part of this callmvStore- that owns this FileStore
-
compactMoveChunks
public void compactMoveChunks(int targetFillRate, long moveSize, MVStore mvStore)Compact the store by moving all chunks next to each other, if there is free space between chunks. This might temporarily increase the file size. Chunks are overwritten irrespective of the current retention time. Before overwriting chunks and before resizing the file, syncFile() is called.- Parameters:
targetFillRate- do nothing if the file store fill rate is higher than thismoveSize- the number of bytes to movemvStore- owner of this store
-
shrinkStoreIfPossible
protected void shrinkStoreIfPossible(int minPercent)
Shrink the store if possible, and if at least a given percentage can be saved.- Specified by:
shrinkStoreIfPossiblein classFileStore<SFChunk>- Parameters:
minPercent- the minimum percentage to save
-
doHousekeeping
protected void doHousekeeping(MVStore mvStore) throws java.lang.InterruptedException
- Specified by:
doHousekeepingin classFileStore<SFChunk>- Throws:
java.lang.InterruptedException
-
truncate
protected abstract void truncate(long size)
-
getMovePriority
public int getMovePriority(int block)
Calculates relative "priority" for chunk to be moved.- Parameters:
block- where chunk starts- Returns:
- priority, bigger number indicate that chunk need to be moved sooner
-
getRewriteCandidates
public java.util.Collection<SFChunk> getRewriteCandidates()
- Overrides:
getRewriteCandidatesin classFileStore<SFChunk>
-
-