|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.gillius.realdb.model.pool.DefaultBlockPool
public class DefaultBlockPool
This implementation always chooses reclaimable blocks before unused blocks, and always chooses
the lowest number block in getFreeBlock()
.
format()
.
Constructor Summary | |
---|---|
DefaultBlockPool(TransactionLog log,
int numDataBlocks)
Creates a DefaultBlockPool. |
Method Summary | |
---|---|
void |
addBlock(BlockTransaction tx,
int lastBlock,
int destination,
int seqNum)
Adds a block obtained from BlockPool.getFreeBlock() or BlockPool.removeBlock(int, int, int, long) . |
void |
flush()
|
void |
format()
Formats the underlying data storage for this object to represent an "initial" (usually means "empty" state). |
int |
getDataBlocksUsed()
Returns the number of data blocks in use. |
BlockTransaction |
getFreeBlock()
If BlockPool.hasFreeBlocks() , then returns a new transaction with the free block. |
TransactionLog |
getLog()
|
int |
getNextUnusedBlock()
|
int |
getNumDataBlocks()
Returns the total number of data blocks managed by this pool. |
java.util.Set<java.lang.Integer> |
getReclaimableBlocks()
Returns a set of blocks that were used at one point but no longer and will be reclaimed first when getting free blocks. |
boolean |
hasFreeBlocks()
Returns true if there are any free blocks in the pool. |
boolean |
isOpened()
|
void |
open()
Opens the TransactionLog given when this object was constructed. |
BlockTransaction |
removeBlock(int block,
int sourceIndex,
int seqNum,
long secondBlockStartTime)
Signals an intention to remove the indicated block from the indicated index immediately after calling this method. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DefaultBlockPool(TransactionLog log, int numDataBlocks)
format()
.
log
- non-null TransactionLognumDataBlocks
- the number of data blocks in the poolMethod Detail |
---|
public void open() throws java.io.IOException, BadFileException
BlockPool
Formattable.format()
.
open
in interface BlockPool
java.io.IOException
BadFileException
public TransactionLog getLog()
getLog
in interface BlockPool
public int getNumDataBlocks()
BlockPool
getNumDataBlocks
in interface BlockPool
public int getDataBlocksUsed()
BlockPool
getDataBlocksUsed
in interface BlockPool
public int getNextUnusedBlock()
public java.util.Set<java.lang.Integer> getReclaimableBlocks()
public boolean isOpened()
public boolean hasFreeBlocks()
BlockPool
hasFreeBlocks
in interface BlockPool
public BlockTransaction getFreeBlock() throws java.io.IOException
BlockPool
BlockPool.hasFreeBlocks()
, then returns a new transaction with the free block.
getFreeBlock
in interface BlockPool
java.io.IOException
- if there is an implicit log flush and it fails.public BlockTransaction removeBlock(int block, int sourceIndex, int seqNum, long secondBlockStartTime) throws java.io.IOException
BlockPool
removeBlock
in interface BlockPool
block
- block number to removesourceIndex
- source index IDseqNum
- index's head sequence number (used in recovery to verify action)secondBlockStartTime
- start time of the second block in the index that will be passed to
DataIndex.removeFirstBlock(long, org.gillius.realdb.model.Transaction)
; needed for replay.
java.io.IOException
- if there is an implicit log flush and it fails.public void addBlock(BlockTransaction tx, int lastBlock, int destination, int seqNum) throws java.io.IOException
BlockPool
BlockPool.getFreeBlock()
or BlockPool.removeBlock(int, int, int, long)
. This method must be
called after writing the data block to the new state and before adding the block to the index.
This method finalizes the transaction; the only operation remaining is to commit it.
addBlock
in interface BlockPool
tx
- transaction returned from BlockPool.getFreeBlock()
or BlockPool.removeBlock(int, int, int, long)
lastBlock
- current last block in the index, used only for extra verification in
recovery, or -1 if the index is empty.destination
- index destination IDseqNum
- index tail sequence number on disk (needed for recovery)
java.io.IOException
public void flush() throws java.io.IOException
flush
in interface java.io.Flushable
java.io.IOException
public void format() throws java.io.IOException
Formattable
format
in interface Formattable
java.io.IOException
- if an error occurs writing to the data storage
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |