Package org.h2.mvstore

# Class RandomAccessStore

java.lang.Object
org.h2.mvstore.FileStore<org.h2.mvstore.SFChunk>
org.h2.mvstore.RandomAccessStore

Direct Known Subclasses:
  `OffHeapStore`, `SingleFileStore`

public abstract class RandomAccessStore extends FileStore<org.h2.mvstore.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 final FreeSpaceBitSet`
`freeSpace`
The 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(Map<String,Object> config)`

## Method Summary

Modifier and Type
Method
Description
`protected final void`
`adjustStoreToLastChunk()`
Make persistent changes after lastChunk was reset
`protected final void`
`allocateChunkSpace(org.h2.mvstore.SFChunk chunk, WriteBuffer buff)`
Allocate logical space and assign position of the buffer within the store.
`void`
`clear()`
Mark the file as empty.
`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.
`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.
`protected final org.h2.mvstore.SFChunk`
`createChunk(int newChunkId)`
`org.h2.mvstore.SFChunk`
`createChunk(String s)`
Build a Chunk from the given string.
`protected org.h2.mvstore.SFChunk`
`createChunk(Map<String,String> map)`
`protected void`
`doHousekeeping(MVStore mvStore)`
`protected void`
`free(long pos, int length)`
Mark the space as free.
`protected void`
`freeChunkSpace(Iterable<org.h2.mvstore.SFChunk> chunks)`
Mark the space occupied by specified chunks as free.
`protected long`
`getAfterLastBlock_()`
`int`
`getFillRate()`
`int`
`getMovePriority(int block)`
Calculates relative "priority" for chunk to be moved.
`Collection<org.h2.mvstore.SFChunk>`
`getRewriteCandidates()`
`protected void`
`initializeStoreHeader(long time)`
`boolean`
`isSpaceReused()`
`void`
`markUsed(long pos, int length)`
Mark the space as in use.
`protected void`
`readStoreHeader(boolean recoveryMode)`
`void`
`setReuseSpace(boolean reuseSpace)`
`boolean`
`shouldSaveNow(int unsavedMemory, int autoCommitMemory)`
Decision about autocommit is delegated to store
`protected void`
`shrinkStoreIfPossible(int minPercent)`
Shrink the store if possible, and if at least a given percentage can be saved.
`protected abstract void`
`truncate(long size)`
`protected final boolean`
`validateFileLength(String msg)`
`protected final void`
`writeChunk(org.h2.mvstore.SFChunk chunk, WriteBuffer buffer)`
Write buffer associated with chunk into store at chunk's allocated position
`protected final void`
`writeCleanShutdownMark()`
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, sync, writeCleanShutdown, writeFully`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### 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).

## Constructor Details

### RandomAccessStore

public RandomAccessStore(Map<String,Object> config)

## Method Details

### createChunk

protected final org.h2.mvstore.SFChunk createChunk(int newChunkId)

Specified by:
  `createChunk` in class `FileStore<org.h2.mvstore.SFChunk>`

### createChunk

public org.h2.mvstore.SFChunk createChunk(String s)
Description copied from class: `FileStore`
Build a Chunk from the given string.

Specified by:
  `createChunk` in class `FileStore<org.h2.mvstore.SFChunk>`
Parameters:
  `s` - the string
Returns:
  the Chunk created

### createChunk

protected org.h2.mvstore.SFChunk createChunk(Map<String,String> map)

Specified by:
  `createChunk` in class `FileStore<org.h2.mvstore.SFChunk>`

### markUsed

public void markUsed(long pos, int length)
Mark the space as in use.

Specified by:
  `markUsed` in class `FileStore<org.h2.mvstore.SFChunk>`
Parameters:
  `pos` - the position in bytes
  `length` - the number of bytes

### shouldSaveNow

public boolean shouldSaveNow(int unsavedMemory, int autoCommitMemory)
Description copied from class: `FileStore`
Decision about autocommit is delegated to store

Specified by:
  `shouldSaveNow` in class `FileStore<org.h2.mvstore.SFChunk>`
Parameters:
  `unsavedMemory` - amount of unsaved memory, so far
  `autoCommitMemory` - configured limit on amount of unsaved memory
Returns:
  true if commit should happen now

### isSpaceReused

public boolean isSpaceReused()

Overrides:
  `isSpaceReused` in class `FileStore<org.h2.mvstore.SFChunk>`

### setReuseSpace

public void setReuseSpace(boolean reuseSpace)

Overrides:
  `setReuseSpace` in class `FileStore<org.h2.mvstore.SFChunk>`

### freeChunkSpace

protected void freeChunkSpace(Iterable<org.h2.mvstore.SFChunk> chunks)
Description copied from class: `FileStore`
Mark the space occupied by specified chunks as free.

Specified by:
  `freeChunkSpace` in class `FileStore<org.h2.mvstore.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 bytes
  `length` - the number of bytes

### getFillRate

public int getFillRate()

Specified by:
  `getFillRate` in class `FileStore<org.h2.mvstore.SFChunk>`

### validateFileLength

protected final boolean validateFileLength(String msg)

Specified by:
  `validateFileLength` in class `FileStore<org.h2.mvstore.SFChunk>`

### readStoreHeader

protected void readStoreHeader(boolean recoveryMode)

Specified by:
  `readStoreHeader` in class `FileStore<org.h2.mvstore.SFChunk>`

### initializeStoreHeader

protected void initializeStoreHeader(long time)

Specified by:
  `initializeStoreHeader` in class `FileStore<org.h2.mvstore.SFChunk>`

### allocateChunkSpace

protected final void allocateChunkSpace(org.h2.mvstore.SFChunk chunk, WriteBuffer buff)
Description copied from class: `FileStore`
Allocate logical space and assign position of the buffer within the store.

Specified by:
  `allocateChunkSpace` in class `FileStore<org.h2.mvstore.SFChunk>`
Parameters:
  `chunk` - to allocate space for
  `buff` - to allocate space for

### writeChunk

protected final void writeChunk(org.h2.mvstore.SFChunk chunk, WriteBuffer buffer)
Description copied from class: `FileStore`
Write buffer associated with chunk into store at chunk's allocated position

Specified by:
  `writeChunk` in class `FileStore<org.h2.mvstore.SFChunk>`
Parameters:
  `chunk` - chunk to write
  `buffer` - to write

### writeCleanShutdownMark

protected final void writeCleanShutdownMark()
Description copied from class: `FileStore`
Performs final preparation before store is closed normally

Specified by:
  `writeCleanShutdownMark` in class `FileStore<org.h2.mvstore.SFChunk>`

### adjustStoreToLastChunk

protected final void adjustStoreToLastChunk()
Description copied from class: `FileStore`
Make persistent changes after lastChunk was reset

Specified by:
  `adjustStoreToLastChunk` in class `FileStore<org.h2.mvstore.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:
  `compactStore` in class `FileStore<org.h2.mvstore.SFChunk>`
Parameters:
  `thresholdFillRate` - do not compact if store fill rate above this value (0-100)
  `maxCompactTime` - the maximum time in milliseconds to compact
  `maxWriteSize` - the maximum amount of data to be written as part of this call
  `mvStore` - 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 this
  `moveSize` - the number of bytes to move
  `mvStore` - 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:
  `shrinkStoreIfPossible` in class `FileStore<org.h2.mvstore.SFChunk>`
Parameters:
  `minPercent` - the minimum percentage to save

### doHousekeeping

protected void doHousekeeping(MVStore mvStore) throws InterruptedException

Specified by:
  `doHousekeeping` in class `FileStore<org.h2.mvstore.SFChunk>`
Throws:
  `InterruptedException`

### truncate

protected abstract void truncate(long size)

### clear

public void clear()
Mark the file as empty.

Overrides:
  `clear` in class `FileStore<org.h2.mvstore.SFChunk>`

### 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

public Collection<org.h2.mvstore.SFChunk> getRewriteCandidates()

Overrides:
  `getRewriteCandidates` in class `FileStore<org.h2.mvstore.SFChunk>`