Package org.h2.mvstore
Class RandomAccessStore
- Direct Known Subclasses:
OffHeapStore,SingleFileStore
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
FieldsModifier and TypeFieldDescriptionprotected final FreeSpaceBitSetThe 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 -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidMake persistent changes after lastChunk was resetprotected final 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 final SFChunkcreateChunk(int newChunkId) Build a Chunk from the given string.protected SFChunkcreateChunk(Map<String, String> map) protected voiddoHousekeeping(MVStore mvStore) protected voidfree(long pos, int length) Mark the space as free.protected voidfreeChunkSpace(Iterable<SFChunk> chunks) Mark the space occupied by specified chunks as free.protected longintintgetMovePriority(int block) Calculates relative "priority" for chunk to be moved.protected voidinitializeStoreHeader(long time) booleanvoidmarkUsed(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 final booleanvalidateFileLength(String msg) protected final voidwriteChunk(SFChunk chunk, WriteBuffer buffer) Write buffer associated with chunk into store at chunk's allocated positionprotected final voidPerforms final preparation before store is closed normallyMethods 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, sync, writeCleanShutdown, writeFully
-
Field Details
-
freeSpace
The free spaces between the chunks. The first block to use is block 2 (the first two blocks are the store header).
-
-
Constructor Details
-
RandomAccessStore
-
-
Method Details
-
createChunk
- Specified by:
createChunkin classFileStore<SFChunk>
-
createChunk
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
- 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
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
- 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
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
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
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
- Specified by:
doHousekeepingin classFileStore<SFChunk>- Throws:
InterruptedException
-
truncate
protected abstract void truncate(long size) -
clear
public void clear()Mark the file as empty. -
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
-
getAfterLastBlock_
protected long getAfterLastBlock_() -
getRewriteCandidates
- Overrides:
getRewriteCandidatesin classFileStore<SFChunk>
-