Class RandomAccessStore

    • 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 by FileStore.saveChunkLock
    • Constructor Detail

      • RandomAccessStore

        public RandomAccessStore​(java.util.Map<java.lang.String,​java.lang.Object> config)
    • Method Detail

      • createChunk

        public SFChunk createChunk​(java.lang.String s)
        Description copied from class: FileStore
        Build a Chunk from the given string.
        Specified by:
        createChunk in class FileStore<SFChunk>
        Parameters:
        s - the string
        Returns:
        the Chunk created
      • markUsed

        public void markUsed​(long pos,
                             int length)
        Mark the space as in use.
        Specified by:
        markUsed in class FileStore<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<SFChunk>
        Parameters:
        unsavedMemory - amount of unsaved memory, so far
        autoCommitMemory - configured limit on amount of unsaved memory
        Returns:
        true if commit should happen now
      • freeChunkSpace

        protected void freeChunkSpace​(java.lang.Iterable<SFChunk> chunks)
        Description copied from class: FileStore
        Mark the space occupied by specified chunks as free.
        Specified by:
        freeChunkSpace in class FileStore<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
      • allocateChunkSpace

        protected final void allocateChunkSpace​(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<SFChunk>
        Parameters:
        chunk - to allocate space for
        buff - to allocate space for
      • writeChunk

        protected final void writeChunk​(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<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<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<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<SFChunk>
        Parameters:
        minPercent - the minimum percentage to save
      • doHousekeeping

        protected void doHousekeeping​(MVStore mvStore)
                               throws java.lang.InterruptedException
        Specified by:
        doHousekeeping in class FileStore<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