BufferManager Class Reference

#include <BufferManager.h>

List of all members.


Detailed Description

Buffer manager.

Manages a memory-based buffer pool of pages.

Author:
Dave Musicant, with considerable material reused from the UW-Madison Minibase project


Public Member Functions

 BufferManager (int poolSize)
 Creates a buffer manager with the specified size.
 ~BufferManager ()
 Destructor.
int getPoolSize ()
 Returns the pool size.
Page * pinPage (int pinPageId, string fileName, bool emptyPage)
 Checks if this page is in buffer pool.
void unpinPage (int unpinPageId, string fileName, bool dirty)
 If the pin count for this page is greater than 0, it is decremented.
int newPage (int numPages, string fileName, Page *&firstPage)
 Requests a run of pages from the underlying database, then finds a frame in the buffer pool for the first page and pins it.
void freePage (int pageId, string fileName)
 Deallocates a page from the underlying database.
void flushPage (int pageId, string fileName)
 Flushes page from the buffer pool to the underlying database if it is dirty.
void flushAllPages ()
 Flushes all dirty pages from the buffer pool to the underlying databases.
int findFrame (int pageId, string fileName)
 Returns buffer pool location for a particular pageId.

Static Public Attributes

static const int INVALID_PAGE = -1
 Value to use for an invalid page id.

Classes

class  FrameDescriptor


Constructor & Destructor Documentation

BufferManager::BufferManager ( int  poolSize  ) 

Creates a buffer manager with the specified size.

Parameters:
poolSize the number of pages that the buffer pool can hold.


Member Function Documentation

int BufferManager::findFrame ( int  pageId,
string  fileName 
)

Returns buffer pool location for a particular pageId.

This method is just used for testing purposes: it probably doesn't serve a real purpose in an actual database system.

Parameters:
pageId the page id to be looked up.
fileName the file name to be looked up.
Returns:
the frame location for the page of interested. Returns -1 if the page is not in the pool.

void BufferManager::flushAllPages (  ) 

Flushes all dirty pages from the buffer pool to the underlying databases.

If page is not dirty, it is not flushed, especially since an undirty page may hang around even after the underlying database has been erased.

void BufferManager::flushPage ( int  pageId,
string  fileName 
)

Flushes page from the buffer pool to the underlying database if it is dirty.

If page is not dirty, it is not flushed, especially since an undirty page may hang around even after the underlying database has been erased. If the page is not in the buffer pool, do nothing, since the page is effectively flushed already.

Parameters:
pageId the page id to be flushed.
fileName the name of the database from where the page is to be deallocated.

void BufferManager::freePage ( int  pageId,
string  fileName 
)

Deallocates a page from the underlying database.

Verifies that page is not pinned.

Parameters:
pageId the page id to be deallocated.
fileName the name of the database from where the page is to be deallocated.
Exceptions:
PagePinnedException if the page is pinned

int BufferManager::getPoolSize (  ) 

Returns the pool size.

Returns:
the pool size.

int BufferManager::newPage ( int  numPages,
string  fileName,
Page *&  firstPage 
)

Requests a run of pages from the underlying database, then finds a frame in the buffer pool for the first page and pins it.

If the buffer pool is full, no new pages are allocated from the database.

Parameters:
numPages the number of pages in the run to be allocated.
fileName the name of the database from where pages are to be allocated.
firstPage a pointer to a page which will be replaced with a pointer to the actual page in the buffer pool.
Returns:
the first page id of the run. Returns INVALID_PAGE if there is not enough space in the buffer pool for the requested run.
Exceptions:
FileFullException if there are not enough free pages (passed through from DBFile).

Page* BufferManager::pinPage ( int  pinPageId,
string  fileName,
bool  emptyPage 
)

Checks if this page is in buffer pool.

If it is, returns a pointer to it. Otherwise, it finds an available frame for this page, reads the page, and pins it. Writes out the old page, if it is dirty, before reading.

Parameters:
pinPageId the page id for the page to be pinned
fileName the name of the database that contains the page to be pinned
emptyPage determines if the page is known to be empty. If true, then the page is not actually read from disk since it is assumed to be empty.
Returns:
a pointer to the page in the buffer pool. If the buffer pool is full, NULL is returned.

void BufferManager::unpinPage ( int  unpinPageId,
string  fileName,
bool  dirty 
)

If the pin count for this page is greater than 0, it is decremented.

If the pin count becomes zero, it is appropriately included in a group of replacement candidates.

Parameters:
unpinPageId the page id for the page to be unpinned
fileName the name of the database that contains the page to be unpinned
dirty if false, then the page does not actually need to be written back to disk.
Exceptions:
InvalidPageException if unpinPageNum is not valid.
PageNotPinnedException if the page is not pinned, or if the page id is invalid in some other way.


Generated on Wed Aug 29 07:32:08 2007 for Minibase by  doxygen 1.4.7