SwapManager Class Reference

This class manages a number of consecutive RowBlocks held either in memory or on disk. More...

List of all members.

Public Member Functions

bool AllocateBlocks (simba_uint32 blocksAllocated, bool needCacheBlock)
 Allocate the given number of RowBlocks into m_blockPool.
bool AllocateToMinimumNumberOfOwnedBlocks ()
 Allocate new blocks until the number of owned blocks is at least the minimum number of owned blocks set for this SwapManager.
Simba::DSI::RowBlockAppendRow ()
 Increment the number of rows held by the SwapManager.
void CloseBlockForWrite (Simba::DSI::RowBlock *in_block)
 Close the input block for write. This swap manager will still accept more writes, but not in the current block.
void FreePool ()
 Free as much as possible blocks from the pool only (no block in use is freed).
simba_uint64 GetBlockCount () const
 Retrieve the total number of allocated blocks, both in memory and on disk.
ILoggerGetDriverLog ()
simba_size_t GetMinimumNumberOwnedBlocks ()
 Get the current value of the minimum number of blocks this SwapManager should have.
simba_uint64 GetOwnedBlockCount ()
 Return the total number of data block objects owned by this SwapManager.
simba_uint64 GetResidentBlockCount () const
 Retrieve the number of resident blocks.
simba_uint64 GetRowCount () const
 Retrieve the total number of rows in memory and on disk.
void MarkFinishAppending ()
 Inform the swap manager the user has finished appending rows on the RowBlock on which the last AppendRow() was performed.
void MarkFinishedWriting (bool in_releaseCache=true)
 Call-back method to indicate that writing to the table is finished. Not required, but if there is a cache block for writing to, it will be freed in this case.
void MarkFinishRetrieving (Simba::DSI::RowBlock *in_block=NULL)
 Inform the swap manager the user has finished retrieving data on the given RowBlock.
bool MoveToRow (Simba::DSI::RowBlock *&io_block, simba_uint64 in_rowNumber, bool in_finishedOnNewBlock=true)
 Move to the given row.
void Reset ()
 Clear any RowBlocks in memory and on disk.
void SetMinimumNumberOwnedBlocks (simba_size_t in_minimumNumberOwnedBlocks)
 Set the current value of the minimum number of blocks this SwapManager should have.
 SwapManager (SwapManager &in_swapManager, simba_size_t in_minimumNumberOwnedBlocks)
 Copy Constructor.
 SwapManager (const IMemoryContext &in_memoryContext, simba_size_t in_hintBlockSize, Simba::DSI::IColumns *in_columns, Simba::DSI::IColumn *in_bmColumn, simba_uint32 in_maxCachedLOBSize, simba_size_t in_minimumNumberOwnedBlocks, ISwapAssistant *in_swapAssistant, bool in_useCompression)
 Constructor.
bool TransferBlock (SwapManager &io_dest)
 Transfer one block from this SwapManager instance to the given SwapManager instance.
bool TransferBlocksUntilDestinationReachesNumber (SwapManager &io_dest, simba_uint64 in_targetNumber)
 Detached blocks from the current SwapManager and transfer them to the given SwapManager until this latter reaches the given number of blocks or no more block can be transferred (see comments on TransferBlock() method). No block is transferred if the destination SwapManager has initially more blocks than the given number.
 ~SwapManager ()
 Destructor.

Protected Member Functions

void * GetRowBlockBuffer (RowBlock &in_block, simba_int64 in_length)
 Get the buffer from with in the requested row block/.
void SerializeRowBlock (Simba::DSI::RowBlock &io_rowBlock, void *&out_buffer, simba_int64 &out_length)
 Fill a buffer with the raw data from the input row block and output it to the caller.

Friends

class SwapDevice

Detailed Description

This class manages a number of consecutive RowBlocks held either in memory or on disk.

Its main design goal is to make RowBlocks held on disk transparent to the user of this class. In other words, it "virtualizes" the limited amount of physical memory that it can employ.

The main responsibilities of this class are the following,

SwapManager is not responsible for deciding whether a new RowBlock can be created. It is not responsible for deciding when a resident block can be and should be swapped either. These decisions are left to ISwapAssistant. See ISwapAssistant for more details.


Constructor & Destructor Documentation

SwapManager ( const IMemoryContext in_memoryContext,
simba_size_t  in_hintBlockSize,
Simba::DSI::IColumns in_columns,
Simba::DSI::IColumn in_bmColumn,
simba_uint32  in_maxCachedLOBSize,
simba_size_t  in_minimumNumberOwnedBlocks,
ISwapAssistant in_swapAssistant,
bool  in_useCompression 
)

Constructor.

Note that this constructor does NOT allocate memory, it reserves memory for later allocation during use.

Parameters:
in_memoryContext The executor's memory context to be passed around
in_hintBlockSize The hint for the size in bytes of each block. This will be adjusted to ensure at least one row is held in a block, and also to ensure excess memory is not allocated after the end of a block.
in_columns The columns that will be stored in each row of a RowBlock. Cannot be NULL. (NOT OWN)
in_bmColumn The optional bookmark column. Can be NULL. (NOT OWN)
in_maxCachedLOBSize The maximum length for Large Object (LOB).
in_minimumNumberOwnedBlocks The minimum number of blocks this SwapManager needs to own at all time, so the processing it is involved in can be successful even if the MemoryManager has run out of free memory.
in_swapAssistant Decides when a block is swapped if needed. Cannot be NULL. (OWN)
in_useCompression Flag to indicate if compression should be used by this SwapManager.
SwapManager ( SwapManager in_swapManager,
simba_size_t  in_minimumNumberOwnedBlocks 
)

Copy Constructor.

Note that this operator does not copy data. It only copies parameters so this manager will be similar to the given manager when it was constructed.

Parameters:
in_swapManager The SwapManager to copy.
in_minimumNumberOwnedBlocks The minimum number of blocks this SwapManager needs to own at all time, so the processing it is involved in can be successful even if the MemoryManager has run out of free memory.
~SwapManager (  ) 

Destructor.


Member Function Documentation

bool AllocateBlocks ( simba_uint32  blocksAllocated,
bool  needCacheBlock 
)

Allocate the given number of RowBlocks into m_blockPool.

Parameters:
blocksAllocated The number of blocks allocated from the memory manager (and thus the number of RowBlock object to create)
needCacheBlock Whether a cache block should be allocated.

Note: Has the strong exception guarantee: All allocated RowBlock objects are destroyed in case of exception.

bool AllocateToMinimumNumberOfOwnedBlocks (  ) 

Allocate new blocks until the number of owned blocks is at least the minimum number of owned blocks set for this SwapManager.

Returns:
true if it was possible to allocate all necessary blocks. false if none or only a few of the necessary blocks could be allocated.
Simba::DSI::RowBlock* AppendRow (  ) 

Increment the number of rows held by the SwapManager.

The returned RowBlock is ready for writing. That is, the user can call WriteData() on the returned block immediately.

Returns:
the RowBlock that had a row appended to it.
void CloseBlockForWrite ( Simba::DSI::RowBlock in_block  ) 

Close the input block for write. This swap manager will still accept more writes, but not in the current block.

void FreePool (  ) 

Free as much as possible blocks from the pool only (no block in use is freed).

simba_uint64 GetBlockCount (  )  const

Retrieve the total number of allocated blocks, both in memory and on disk.

Returns:
the total number of allocated blocks.
ILogger* GetDriverLog (  ) 
simba_size_t GetMinimumNumberOwnedBlocks (  )  [inline]

Get the current value of the minimum number of blocks this SwapManager should have.

Returns:
The current minimum number of blocks.
simba_uint64 GetOwnedBlockCount (  ) 

Return the total number of data block objects owned by this SwapManager.

It is possible for this swap manager to own more memory than it reports through this method. It might do this in the case where it has reserved memory for its own internal operations. It accurately reports the number of blocks that it owns in terms of how many RowBlocks containing data it can hold in memory without swapping.

Returns:
the total number of data block objects owned by this SwapManager.
simba_uint64 GetResidentBlockCount (  )  const

Retrieve the number of resident blocks.

Returns:
the number of resident blocks.
void* GetRowBlockBuffer ( RowBlock in_block,
simba_int64  in_length 
) [protected]

Get the buffer from with in the requested row block/.

Parameters:
in_length The length in bytes that the buffer must be.
in_block The block that the buffer is needed for.
Returns:
the requested buffer. (NOT OWN)
simba_uint64 GetRowCount (  )  const

Retrieve the total number of rows in memory and on disk.

Returns:
the total number of rows.
void MarkFinishAppending (  ) 

Inform the swap manager the user has finished appending rows on the RowBlock on which the last AppendRow() was performed.

void MarkFinishedWriting ( bool  in_releaseCache = true  ) 

Call-back method to indicate that writing to the table is finished. Not required, but if there is a cache block for writing to, it will be freed in this case.

Parameters:
in_releaseCache If the cache should be released.
void MarkFinishRetrieving ( Simba::DSI::RowBlock in_block = NULL  ) 

Inform the swap manager the user has finished retrieving data on the given RowBlock.

Parameters:
in_block The block that user has finished retrieving data. If NULL, the last retrieved RowBlock is marked finishing retrieval.
bool MoveToRow ( Simba::DSI::RowBlock *&  io_block,
simba_uint64  in_rowNumber,
bool  in_finishedOnNewBlock = true 
)

Move to the given row.

It tries to move to the given row on the given block first if the block is not NULL. If failed, the block that contains the row will be retrieved and io_block will be updated to point to it. When io_block is update, this method returns true. Otherwise, it returns false.

The block that his returned can be read, but not written to.

Parameters:
io_block The input and output block. Can point to NULL.
in_rowNumber The row to move to.
in_finishedOnNewBlock Flag to indicate that the input block is finished reading if it is not NULL and does not contain the input row number. For most uses this will be true. If False, it is the responsibility of the caller to call MarkFinishRetrieving when they are done with the block.
Exceptions:
DSIException if the row requested is invalid.
Returns:
true if io_block is updated, false otherwise.
void Reset (  ) 

Clear any RowBlocks in memory and on disk.

That is, reset the SwapManager to the state as if it was just created. This method is designed so that the SwapManager can be efficiently reused after it has been used to manage data.

void SerializeRowBlock ( Simba::DSI::RowBlock io_rowBlock,
void *&  out_buffer,
simba_int64 &  out_length 
) [protected]

Fill a buffer with the raw data from the input row block and output it to the caller.

After this method has returned, the input block will no longer own it's data and the data container will be returned to the pool.

Parameters:
io_rowBlock The row block to get the data from.
out_buffer Output the filled buffer.
out_length Output the length in bytes of the data in the buffer.
void SetMinimumNumberOwnedBlocks ( simba_size_t  in_minimumNumberOwnedBlocks  )  [inline]

Set the current value of the minimum number of blocks this SwapManager should have.

NOTE: This method does not allocate more blocks in case the new value is above the old one. The method FillToMinimumNumberOfOwnedBlocks() can be called afterwards if it is necessary to own immediately the new minimum number of blocks. It also does not free any blocks in case the new value is below the old one.

Parameters:
in_minimumNumberOwnedBlocks The new minimum value.
bool TransferBlock ( SwapManager io_dest  ) 

Transfer one block from this SwapManager instance to the given SwapManager instance.

A block can be transferred only if:

  • The current instance has either at least a block in its pool or one of its resident block can be swapped out.
  • Transferring one block does not bring the current instance below its minimum number of blocks.

NOTE: This method can only be used between SwapManager that have identical columns (typically a SwapManager and one of its clone). Using this method between two SwapManager with different columns can lead to unexpected behavior.

Parameters:
io_dest The SwapManager that will receive the transferred block.
in_blockForPool If the block should be added to the pool. If this is false, the caller must decide what to do with the block.
Returns:
true if one block was successfully transferred. false otherwise.
bool TransferBlocksUntilDestinationReachesNumber ( SwapManager io_dest,
simba_uint64  in_targetNumber 
)

Detached blocks from the current SwapManager and transfer them to the given SwapManager until this latter reaches the given number of blocks or no more block can be transferred (see comments on TransferBlock() method). No block is transferred if the destination SwapManager has initially more blocks than the given number.

NOTE: This method can only be used between SwapManager that have identical columns (typically a SwapManager and one of its clone). Using this method between two SwapManager with different columns can lead to unexpected behavior.

Parameters:
io_dest The SwapManager that will receive the blocks.
in_targetNumber The number of blocks that the given
Returns:
true if enough blocks could be transferred to reach the given number of blocks or the target SwapManager has already enough blocks, else false.

Friends And Related Function Documentation

friend class SwapDevice [friend]

The documentation for this class was generated from the following file:

Generated on Wed May 17 14:21:16 2017 for SimbaEngine 10.1.3.1011 by simba