Class FreeSpaceBitSet

java.lang.Object
org.h2.mvstore.FreeSpaceBitSet

public class FreeSpaceBitSet extends Object
A free space bit set.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final int
    The block size in bytes.
    private static final boolean
     
    private int
    Left-shifting register, which holds outcomes of recent allocations.
    private final int
    The first usable block.
    private final BitSet
    The bit set.
  • Constructor Summary

    Constructors
    Constructor
    Description
    FreeSpaceBitSet(int firstFreeBlock, int blockSize)
    Create a new free space map.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    allocate(int length)
    Allocate a number of blocks and mark them as used.
    private int
    allocate(int blocks, int reservedLow, int reservedHigh, boolean allocate)
     
    (package private) long
    allocate(int length, long reservedLow, long reservedHigh)
    Allocate a number of blocks and mark them as used.
    void
    Reset the list.
    void
    free(long pos, int length)
    Mark the space as free.
    (package private) int
    Get the index of the first block after last occupied one.
    private int
    getBlock(long pos)
     
    private int
    getBlockCount(int length)
     
    (package private) int
    Get the fill rate of the space in percent.
    (package private) long
    Get the position of the first free space.
    (package private) long
    Get the position of the last (infinite) free space.
    (package private) int
    getMovePriority(int block)
    Calculates relative "priority" for chunk to be moved.
    private long
    getPos(int block)
     
    (package private) int
    getProjectedFillRate(int vacatedBlocks)
    Calculates a prospective fill rate, which store would have after rewrite of sparsely populated chunk(s) and evacuation of still live data into a new chunk.
    (package private) boolean
     
    boolean
    isFree(long pos, int length)
    Check whether one of the blocks is free.
    boolean
    isUsed(long pos, int length)
    Check whether one of the blocks is in use.
    void
    markUsed(long pos, int length)
    Mark the space as in use.
    (package private) long
    predictAllocation(int blocks, long reservedLow, long reservedHigh)
    Calculate starting position of the prospective allocation.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • DETAILED_INFO

      private static final boolean DETAILED_INFO
      See Also:
    • firstFreeBlock

      private final int firstFreeBlock
      The first usable block.
    • blockSize

      private final int blockSize
      The block size in bytes.
    • set

      private final BitSet set
      The bit set.
    • failureFlags

      private int failureFlags
      Left-shifting register, which holds outcomes of recent allocations. Only allocations done in "reuseSpace" mode are recorded here. For example, rightmost bit set to 1 means that last allocation failed to find a hole big enough, and next bit set to 0 means that previous allocation request have found one.
  • Constructor Details

    • FreeSpaceBitSet

      public FreeSpaceBitSet(int firstFreeBlock, int blockSize)
      Create a new free space map.
      Parameters:
      firstFreeBlock - the first free block
      blockSize - the block size
  • Method Details

    • clear

      public void clear()
      Reset the list.
    • isUsed

      public boolean isUsed(long pos, int length)
      Check whether one of the blocks is in use.
      Parameters:
      pos - the position in bytes
      length - the number of bytes
      Returns:
      true if a block is in use
    • isFree

      public boolean isFree(long pos, int length)
      Check whether one of the blocks is free.
      Parameters:
      pos - the position in bytes
      length - the number of bytes
      Returns:
      true if a block is free
    • allocate

      public long allocate(int length)
      Allocate a number of blocks and mark them as used.
      Parameters:
      length - the number of bytes to allocate
      Returns:
      the start position in bytes
    • allocate

      long allocate(int length, long reservedLow, long reservedHigh)
      Allocate a number of blocks and mark them as used.
      Parameters:
      length - the number of bytes to allocate
      reservedLow - start block index of the reserved area (inclusive)
      reservedHigh - end block index of the reserved area (exclusive), special value -1 means beginning of the infinite free area
      Returns:
      the start position in bytes
    • predictAllocation

      long predictAllocation(int blocks, long reservedLow, long reservedHigh)
      Calculate starting position of the prospective allocation.
      Parameters:
      blocks - the number of blocks to allocate
      reservedLow - start block index of the reserved area (inclusive)
      reservedHigh - end block index of the reserved area (exclusive), special value -1 means beginning of the infinite free area
      Returns:
      the starting block index
    • isFragmented

      boolean isFragmented()
    • allocate

      private int allocate(int blocks, int reservedLow, int reservedHigh, boolean allocate)
    • markUsed

      public void markUsed(long pos, int length)
      Mark the space as in use.
      Parameters:
      pos - the position in bytes
      length - the number of bytes
    • free

      public void free(long pos, int length)
      Mark the space as free.
      Parameters:
      pos - the position in bytes
      length - the number of bytes
    • getPos

      private long getPos(int block)
    • getBlock

      private int getBlock(long pos)
    • getBlockCount

      private int getBlockCount(int length)
    • getFillRate

      int getFillRate()
      Get the fill rate of the space in percent. The value 0 means the space is completely free, and 100 means it is completely full.
      Returns:
      the fill rate (0 - 100)
    • getProjectedFillRate

      int getProjectedFillRate(int vacatedBlocks)
      Calculates a prospective fill rate, which store would have after rewrite of sparsely populated chunk(s) and evacuation of still live data into a new chunk.
      Parameters:
      vacatedBlocks - number of blocks vacated as a result of live data evacuation less number of blocks in prospective chunk with evacuated live data
      Returns:
      prospective fill rate (0 - 100)
    • getFirstFree

      long getFirstFree()
      Get the position of the first free space.
      Returns:
      the position.
    • getLastFree

      long getLastFree()
      Get the position of the last (infinite) free space.
      Returns:
      the position.
    • getAfterLastBlock

      int getAfterLastBlock()
      Get the index of the first block after last occupied one. It marks the beginning of the last (infinite) free space.
      Returns:
      block index
    • getMovePriority

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

      public String toString()
      Overrides:
      toString in class Object