Package org.h2.mvstore
Class FreeSpaceBitSet
- java.lang.Object
-
- org.h2.mvstore.FreeSpaceBitSet
-
public class FreeSpaceBitSet extends java.lang.Object
A free space bit set.
-
-
Field Summary
Fields Modifier and Type Field Description private int
blockSize
The block size in bytes.private static boolean
DETAILED_INFO
private int
failureFlags
Left-shifting register, which holds outcomes of recent allocations.private int
firstFreeBlock
The first usable block.private java.util.BitSet
set
The bit set.
-
Constructor Summary
Constructors Constructor Description FreeSpaceBitSet(int firstFreeBlock, int blockSize)
Create a new free space map.
-
Method Summary
All Methods Instance Methods Concrete Methods 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
clear()
Reset the list.void
free(long pos, int length)
Mark the space as free.(package private) int
getAfterLastBlock()
Get the index of the first block after last occupied one.private int
getBlock(long pos)
private int
getBlockCount(int length)
(package private) int
getFillRate()
Get the fill rate of the space in percent.(package private) long
getFirstFree()
Get the position of the first free space.(package private) long
getLastFree()
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
isFragmented()
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.java.lang.String
toString()
-
-
-
Field Detail
-
DETAILED_INFO
private static final boolean DETAILED_INFO
- See Also:
- Constant Field Values
-
firstFreeBlock
private final int firstFreeBlock
The first usable block.
-
blockSize
private final int blockSize
The block size in bytes.
-
set
private final java.util.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.
-
-
Method Detail
-
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 byteslength
- 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 byteslength
- 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 allocatereservedLow
- 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 allocatereservedLow
- 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 byteslength
- the number of bytes
-
free
public void free(long pos, int length)
Mark the space as free.- Parameters:
pos
- the position in byteslength
- 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 java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-