All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class bufmgr.BufMgr

java.lang.Object
   |
   +----bufmgr.BufMgr

public class BufMgr
extends Object
implements GlobalConst
The buffer manager class, it allocates new pages for the buffer pool, pins and unpins the frame, frees the frame page, and uses the replacement algorithm to replace the page.


Constructor Index

 o BufMgr(int, String)
Create a buffer manager object.

Method Index

 o flushAllPages()
Flushes all pages of the buffer pool to disk
 o flushPage(PageId)
Added to flush a particular page of the buffer pool to disk
 o frameTable()
A few routines currently need direct access to the FrameTable.
 o freePage(PageId)
User should call this method if she needs to delete a page.
 o getNumBuffers()
Gets the total number of buffers.
 o getNumUnpinnedBuffers()
Gets the total number of unpinned buffer frames.
 o newPage(Page, int)
Call DB object to allocate a run of new pages and find a frame in the buffer pool for the first page and pin it.
 o pinPage(PageId, Page, boolean)
Check if this page is in buffer pool, otherwise find a frame for this page, read in and pin it.
 o unpinPage(PageId, boolean)
To unpin a page specified by a pageId.

Constructors

 o BufMgr
 public BufMgr(int numbufs,
               String replacerArg)
Create a buffer manager object.

Parameters:
numbufs - number of buffers in the buffer pool.
replacerArg - name of the buffer replacement policy.

Methods

 o pinPage
 public void pinPage(PageId pin_pgid,
                     Page page,
                     boolean emptyPage) throws ReplacerException, HashOperationException, PageUnpinnedException, InvalidFrameNumberException, PageNotReadException, BufferPoolExceededException, PagePinnedException, BufMgrException, IOException
Check if this page is in buffer pool, otherwise find a frame for this page, read in and pin it. Also write out the old page if it's dirty before reading if emptyPage==TRUE, then actually no read is done to bring the page in.

Parameters:
Page_Id_in_a_DB - page number in the minibase.
page - the pointer poit to the page.
emptyPage - true (empty page); false (non-empty page)
Throws: ReplacerException
if there is a replacer error.
Throws: HashOperationException
if there is a hashtable error.
Throws: PageUnpinnedException
if there is a page that is already unpinned.
Throws: InvalidFrameNumberException
if there is an invalid frame number .
Throws: PageNotReadException
if a page cannot be read.
Throws: BufferPoolExceededException
if the buffer pool is full.
Throws: PagePinnedException
if a page is left pinned .
Throws: BufMgrException
other error occured in bufmgr layer
Throws: IOException
if there is other kinds of I/O error.
 o unpinPage
 public void unpinPage(PageId PageId_in_a_DB,
                       boolean dirty) throws ReplacerException, PageUnpinnedException, HashEntryNotFoundException, InvalidFrameNumberException
To unpin a page specified by a pageId. If pincount>0, decrement it and if it becomes zero, put it in a group of replacement candidates. if pincount=0 before this call, return error.

Parameters:
globalPageId_in_a_DB - page number in the minibase.
dirty - the dirty bit of the frame
Throws: ReplacerException
if there is a replacer error.
Throws: PageUnpinnedException
if there is a page that is already unpinned.
Throws: InvalidFrameNumberException
if there is an invalid frame number .
Throws: HashEntryNotFoundException
if there is no entry of page in the hash table.
 o newPage
 public PageId newPage(Page firstpage,
                       int howmany) throws BufferPoolExceededException, HashOperationException, ReplacerException, HashEntryNotFoundException, InvalidFrameNumberException, PagePinnedException, PageUnpinnedException, PageNotReadException, BufMgrException, DiskMgrException, IOException
Call DB object to allocate a run of new pages and find a frame in the buffer pool for the first page and pin it. If buffer is full, ask DB to deallocate all these pages and return error (null if error).

Parameters:
firstpage - the address of the first page.
howmany - total number of allocated new pages.
Returns:
the first page id of the new pages.
Throws: BufferPoolExceededException
if the buffer pool is full.
Throws: HashOperationException
if there is a hashtable error.
Throws: ReplacerException
if there is a replacer error.
Throws: HashEntryNotFoundException
if there is no entry of page in the hash table.
Throws: InvalidFrameNumberException
if there is an invalid frame number.
Throws: PageUnpinnedException
if there is a page that is already unpinned.
Throws: PagePinnedException
if a page is left pinned.
Throws: PageNotReadException
if a page cannot be read.
Throws: IOException
if there is other kinds of I/O error.
Throws: BufMgrException
other error occured in bufmgr layer
Throws: DiskMgrException
other error occured in diskmgr layer
 o freePage
 public void freePage(PageId globalPageId) throws InvalidBufferException, ReplacerException, HashOperationException, InvalidFrameNumberException, PageNotReadException, BufferPoolExceededException, PagePinnedException, PageUnpinnedException, HashEntryNotFoundException, BufMgrException, DiskMgrException, IOException
User should call this method if she needs to delete a page. this routine will call DB to deallocate the page.

Parameters:
globalPageId - the page number in the data base.
Throws: InvalidBufferException
if buffer pool corrupted.
Throws: ReplacerException
if there is a replacer error.
Throws: HashOperationException
if there is a hash table error.
Throws: InvalidFrameNumberException
if there is an invalid frame number.
Throws: PageNotReadException
if a page cannot be read.
Throws: BufferPoolExceededException
if the buffer pool is already full.
Throws: PagePinnedException
if a page is left pinned.
Throws: PageUnpinnedException
if there is a page that is already unpinned.
Throws: HashEntryNotFoundException
if there is no entry of page in the hash table.
Throws: IOException
if there is other kinds of I/O error.
Throws: BufMgrException
other error occured in bufmgr layer
Throws: DiskMgrException
other error occured in diskmgr layer
 o flushPage
 public void flushPage(PageId pageid) throws HashOperationException, PageUnpinnedException, PagePinnedException, PageNotFoundException, BufMgrException, IOException
Added to flush a particular page of the buffer pool to disk

Parameters:
pageid - the page number in the database.
Throws: HashOperationException
if there is a hashtable error.
Throws: PageUnpinnedException
if there is a page that is already unpinned.
Throws: PagePinnedException
if a page is left pinned.
Throws: PageNotFoundException
if a page is not found.
Throws: BufMgrException
other error occured in bufmgr layer
Throws: IOException
if there is other kinds of I/O error.
 o flushAllPages
 public void flushAllPages() throws HashOperationException, PageUnpinnedException, PagePinnedException, PageNotFoundException, BufMgrException, IOException
Flushes all pages of the buffer pool to disk

Throws: HashOperationException
if there is a hashtable error.
Throws: PageUnpinnedException
if there is a page that is already unpinned.
Throws: PagePinnedException
if a page is left pinned.
Throws: PageNotFoundException
if a page is not found.
Throws: BufMgrException
other error occured in bufmgr layer
Throws: IOException
if there is other kinds of I/O error.
 o getNumBuffers
 public int getNumBuffers()
Gets the total number of buffers.

Returns:
total number of buffer frames.
 o getNumUnpinnedBuffers
 public int getNumUnpinnedBuffers()
Gets the total number of unpinned buffer frames.

Returns:
total number of unpinned buffer frames.
 o frameTable
 public FrameDesc[] frameTable()
A few routines currently need direct access to the FrameTable.


All Packages  Class Hierarchy  This Package  Previous  Next  Index