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

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