PageFileManager Class Reference

Page file and buffer pool manager. More...

#include <PageFileManager.h>

List of all members.

Public Member Functions

ReturnCode createFile (const char *fileName)
 Creates a new page file.
ReturnCode removeFile (const char *fileName)
 Removes (i.e., deletes) a page file.
ReturnCode openFile (const char *fileName, FileHandle **fileHandle)
 Opens a page file.
ReturnCode closeFile (FileHandle *fileHandle)
 Closes the file and deletes its file handle.
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 (FileHandle *fileHandle, int pageNo, char **data)
 Retrieves a page block by its file handle and page number.
ReturnCode setBlockDirty (FileHandle *fileHandle, int pageNo, bool isDirty)
 Sets the dirty bit for a page block.
ReturnCode getBlockDirty (FileHandle *fileHandle, int pageNo, bool *isDirty)
 Retrieves the dirty bit for a page block.
ReturnCode allocateBlock (FileHandle *fileHandle, int pageNo, char **data)
 Allocates a block in the buffer pool.
ReturnCode disposeBlock (FileHandle *fileHandle, int pageNo)
 Disposes a block from the buffer pool.
ReturnCode unpinBlock (FileHandle *fileHandle, int pageNo)
 Unpins a block in the buffer pool.
ReturnCode getDirtyPageNumber (FileHandle *fileHandle, int *pageNo)
 Gets the page number of some dirty block associated with file handle.
ReturnCode getPinCount (FileHandle *fileHandle, int pageNo, int *pinCount)
 Gets the pin count for a given block.

Static Public Member Functions

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

Detailed Description

Page file and buffer pool manager.

PageFileManager is the bottom-most component of DavisDB, and performs two main functions: managing the creation and destruction of paged files, and managing the in-memory buffer pool of pages. Manipulation of the contents of paged files is done through FileHandle objects that are opened and closed via the methods of this class. 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. Your program should create exactly one instance of PageFileManager, and all page file management requests should be directed to that instance.


Member Function Documentation

ReturnCode PageFileManager::allocateBlock ( FileHandle 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 PageFileManager::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 PageFileManager::closeFile ( FileHandle fileHandle  ) 

Closes the file and deletes its file handle.

Parameters:
fileHandle The file handle to be closed.

Closes the file associated with the specified file handle, and deletes the file handle object. The function fails with return code RC_PAGE_PINNED if the file handle has any pages pinned in the buffer pool. It fails with RC_FILE_NOT_FOUND if the file handle does not correspond to any currently open file.

ReturnCode PageFileManager::createFile ( const char *  fileName  ) 

Creates a new page file.

Parameters:
fileName The name of the file to create.

Creates a new page file. The file must not exist, else the function returns RC_FILE_ALREADY_EXISTS.

ReturnCode PageFileManager::disposeBlock ( FileHandle 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 PageFileManager::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 PageFileManager::getBlockDirty ( FileHandle 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 PageFileManager::getDirtyPageNumber ( FileHandle 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.

PageFileManager * PageFileManager::getInstance (  )  [static]

Gets the singleton instance of this class.

Gets the static singleton instance of this class.

ReturnCode PageFileManager::getPinCount ( FileHandle 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.

ReturnCode PageFileManager::lookupBlock ( FileHandle 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 PageFileManager::openFile ( const char *  fileName,
FileHandle **  fileHandle 
)

Opens a page file.

Parameters:
fileName The file to open.
fileHandle Out parameter for the file handle.

Opens the specified file, returning a newly allocated FileHandle object in fileHandle. The file must already have been created using createFile (otherwise openFile returns RC_FILE_NOT_FOUND). The file must eventually be closed using closeFile.

ReturnCode PageFileManager::removeFile ( const char *  fileName  ) 

Removes (i.e., deletes) a page file.

Parameters:
fileName The file to remove.

Removes (deletes) the specified file. Returns RC_FILE_NOT_FOUND if the file does not exist. Note, this function does not check whether the file is currently open.

ReturnCode PageFileManager::setBlockDirty ( FileHandle 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 PageFileManager::unpinBlock ( FileHandle 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.


The documentation for this class was generated from the following files:
Generated on Sun May 16 23:18:41 2010 for DavisDB by  doxygen 1.6.3