Class BlockAllocator
- All Implemented Interfaces:
AutoCloseable
,Closeable
There are two types of the allocators: root and secondary.
Root one allocates and frees on the storage level and used to manage all the blocks in the storage, where as the secondary can be created to manage some groups of blocks. All the blocks allocated over the secondary one can be freed easily.
-
Method Summary
Modifier and TypeMethodDescriptionlong
Allocate one blockAllocates a given number of blocks.void
close()
Closes this entity and all related blocksvoid
free
(long blockIndex) Marks the provided block as freevoid
free
(CatalogBlockIndices indices) Marks all the blocks in the provided index as freeProvides information about block allocation within this block allocatorlong
getMedia()
Provides parent mediagetName()
Used to identify the allocator, e.g.long
Provides the first block index of the allocator itselfProvides a status of this entityvoid
remove()
Frees all the blocks managed by the allocator.static BlockAllocator
wrap
(BlockAllocatorInternal blockAllocatorInternal) WrapsBlockAllocatorInternal
to create an allocator.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.rostore.v2.media.Closeable
checkOpened
-
Method Details
-
getName
Used to identify the allocator, e.g. in logs. It has no any further meaning as naming this entity. -
wrap
WrapsBlockAllocatorInternal
to create an allocator.The internal version is the one that exposes for each function a rebalance flag, which is needed to cover the allocation peculiarities, described in
BlockSequence.rebalance()
The internal version implements the heavy-lifting operation, and this class is only hides the rebablancing flag, as all external calls should be executed with rebalance=true flag.
- Parameters:
blockAllocatorInternal
- the internal entity that implements allocator's logic- Returns:
- the newly created block allocator
-
getBlockAllocation
Provides information about block allocation within this block allocator- Returns:
- the block allocation
-
getBlockAllocatorInternal
-
getFreeBlocks
public long getFreeBlocks() -
allocate
Allocates a given number of blocks.The call is executed on the best effort basis. If quotas are reached an exception can be thrown.
- Parameters:
blockType
- the block typeblockNumber
- the number of blocks to allocate- Returns:
- a set of blocks that has been allocated
-
allocate
Allocate one block- Parameters:
blockType
- the type of the block- Returns:
- the block index of the block
-
free
public void free(long blockIndex) Marks the provided block as free- Parameters:
blockIndex
- the block index
-
free
Marks all the blocks in the provided index as free- Parameters:
indices
- a set of block indices to free
-
close
public void close()Closes this entity and all related blocks- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
getStatus
Provides a status of this entity -
getStartIndex
public long getStartIndex()Provides the first block index of the allocator itselfCan be used to persist and restore the block allocator.
- Returns:
- the block index
-
remove
public void remove()Frees all the blocks managed by the allocator.Only useful for secondary allocator. Root would not do anything as a reaction to this call.
-
getMedia
Provides parent media- Returns:
- the hosting object
-