BufferPool Class Reference

Buffer pool manager. More...

#include <BufferPool.h>

List of all members.

Public Member Functions

ReturnCode allocateBlock (char **buffer)
 Allocates a scratch block from the buffer pool.
ReturnCode disposeBlock (char *buffer)
 Returns a scratch block to the buffer pool.
ReturnCode lookupBlock (PageFileHandle *fileHandle, int pageNo, char **data)
 Retrieves a page block by its file handle and page number.
ReturnCode setBlockDirty (PageFileHandle *fileHandle, int pageNo, bool isDirty)
 Sets the dirty bit for a page block.
ReturnCode getBlockDirty (PageFileHandle *fileHandle, int pageNo, bool *isDirty)
 Retrieves the dirty bit for a page block.
ReturnCode allocateBlock (PageFileHandle *fileHandle, int pageNo, char **data)
 Allocates a block in the buffer pool.
ReturnCode disposeBlock (PageFileHandle *fileHandle, int pageNo)
 Disposes a block from the buffer pool.
ReturnCode disposeAllBlocks (PageFileHandle *fileHandle)
 Disposes all blocks associated with fileHandle from the pool.
ReturnCode unpinBlock (PageFileHandle *fileHandle, int pageNo)
 Unpins a block in the buffer pool.
ReturnCode getDirtyPageNumber (PageFileHandle *fileHandle, int *pageNo)
 Gets the page number of some dirty block associated with file handle.
ReturnCode getPinCount (PageFileHandle *fileHandle, int pageNo, int *pinCount)
 Gets the pin count for a given block.

Static Public Member Functions

static BufferPoolgetInstance ()
 Gets the singleton instance of this class.


Detailed Description

Buffer pool manager.

Buffer pool is a bottom-most component of DavisDB, and manages the in- memory buffer pool of pages. The buffer pool consists of PF_BUFFER_SIZE blocks of memory, each of size PF_PAGE_SIZE. This pool can be be used for "scratch" pages, allocated and freed via allocateBlock and disposeBlock, and also for pages associated with FileHandle objects. For the latter kind of pages, a pin count is maintained, and the page is not considered free unless its pin count is zero. When a new page is requested from the pool, space is freed up as necessary by flushing free pages to disk using an LRU replacement policy. The actual flushing is performed by the FileHandle object associated with the page to be flushed. This is a singleton class.


Member Function Documentation

ReturnCode BufferPool::allocateBlock ( char **  buffer  ) 

Allocates a scratch block from the buffer pool.

Parameters:
buffer Out parameter for the scratch block.
Allocates a scratch block of size PF_PAGE_SIZE from the buffer pool, and returns a pointer to the block in buffer. Returns RC_OK on success, and RC_OUT_OF_BUFFER if there are no free blocks in the buffer pool. The scratch block must eventually be de-allocated using disposeBlock.

ReturnCode BufferPool::disposeBlock ( char *  buffer  ) 

Returns a scratch block to the buffer pool.

Parameters:
buffer The pointer to the scratch block.
Frees the specified scratch block allocated previously using allocateBlock. Returns RC_PAGE_NOT_FOUND if the buffer does not correspond to a buffer pool block, and RC_PAGE_FREE if the buffer pool block is already free.

ReturnCode BufferPool::lookupBlock ( PageFileHandle fileHandle,
int  pageNo,
char **  data 
)

Retrieves a page block by its file handle and page number.

Parameters:
fileHandle The file handle associated with the block.
pageNo The page number associated with the block.
data Out parameter for the block.
Retrieves a page block by its file handle and page number, and pins the block. Returns RC_PAGE_NOT_FOUND if the block is not found in the buffer pool. The retrieved block must eventually be unpinned using unpinBlock. This method is intended to be used only by FileHandle.

ReturnCode BufferPool::setBlockDirty ( PageFileHandle fileHandle,
int  pageNo,
bool  isDirty 
)

Sets the dirty bit for a page block.

Parameters:
fileHandle The file handle associated with the block.
pageNo The page number associated with the block.
isDirty true means "dirty", false means "not dirty."
Sets the dirty bit for a page block identified by its associated file handle and page number. Returns RC_PAGE_NOT_FOUND if the specified page block is not found in the pool. This method is intended to be used only by FileHandle.

ReturnCode BufferPool::getBlockDirty ( PageFileHandle fileHandle,
int  pageNo,
bool *  isDirty 
)

Retrieves the dirty bit for a page block.

Parameters:
fileHandle The file handle associated with the block.
pageNo The page number associated with the block.
isDirty Out parameter for the dirty bit.
Retrieves the dirty bit for a page block identified by its associated file handle and page number. Returns RC_PAGE_NOT_FOUND if the specified page block is not found in the pool. This method is intended to be used only by FileHandle.

ReturnCode BufferPool::allocateBlock ( PageFileHandle fileHandle,
int  pageNo,
char **  data 
)

Allocates a block in the buffer pool.

Parameters:
fileHandle The file handle to associate with the block.
pageNo The page number to associate with the block.
data Out parameter for the allocated block.
Allocates a block of size PF_PAGE_SIZE from the buffer pool, associates it with the given file handle and page number, and sets its pin count to one. The block must eventually be unpinned with a call to unpinBlock. Returns RC_OK on success, or RC_OUT_OF_BUFFER if no free blocks are available. This method is intended to be used only by FileHandle.

ReturnCode BufferPool::disposeBlock ( PageFileHandle fileHandle,
int  pageNo 
)

Disposes a block from the buffer pool.

Parameters:
fileHandle The file handle associated with the block
pageNo The page number associated with the block
Diposes the specified block from the buffer pool. This is used, e.g., when the underlying page in the page file is disposed. Returns RC_OK on success, RC_PAGE_NOT_FOUND if the specified page block is not found in the pool, and RC_PAGE_PINNED if the page block is pinned and cannot be disposed.

ReturnCode BufferPool::disposeAllBlocks ( PageFileHandle fileHandle  ) 

Disposes all blocks associated with fileHandle from the pool.

Parameters:
fileHandle The file handle

ReturnCode BufferPool::unpinBlock ( PageFileHandle fileHandle,
int  pageNo 
)

Unpins a block in the buffer pool.

Parameters:
fileHandle The file handle associated with the block.
pageNo The page number associated with the block.
Unpins a block in the buffer pool, i.e., decrements the block's pin count. Returns RC_OK on success, RC_PAGE_NOT_FOUND if no block is associated with the file handle and page number, and RC_PAGE_UNPINNED if the block already has a pin count of zero. This method is intended to be used only by FileHandle.

ReturnCode BufferPool::getDirtyPageNumber ( PageFileHandle fileHandle,
int *  pageNo 
)

Gets the page number of some dirty block associated with file handle.

Parameters:
fileHandle The file handle whose pages are of interest.
pageNo Out parameter for the page number.
Gets the page number of an arbitrary dirty block associated with the specified file handle. Returns RC_OK on success, or RC_EOF if no dirty blocks are associated with that file handle. This method is used by FileHandle to find blocks that should be flushed to disk in response to a call to FileHandle::forceAllPages.

ReturnCode BufferPool::getPinCount ( PageFileHandle fileHandle,
int  pageNo,
int *  pinCount 
)

Gets the pin count for a given block.

Parameters:
fileHandle The file handle associated with the block.
pageNo The page number associated with the block.
pinCount Out parameter for the pin count.
Gets the pin count for the block in the buffer pool associated with the specified file handle and page number. Returns RC_OK on success, or RC_PAGE_NOT_FOUND if no such block is found in the buffer pool. This method is intended to be used only by FileHandle.

BufferPool * BufferPool::getInstance (  )  [static]

Gets the singleton instance of this class.

Gets the static singleton instance of this class.


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

Generated on Mon May 16 17:05:06 2011 by  doxygen 1.5.6