bufmgr
Class BufMgr

java.lang.Object
  extended byglobal.AbstractBufMgr
      extended bybufmgr.BufMgr
All Implemented Interfaces:
GlobalConst

public class BufMgr
extends AbstractBufMgr

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.


Field Summary
 
Fields inherited from interface global.GlobalConst
INVALID_PAGE, MAX_NAME, MAXATTRNAME, MAXFILENAME, MAXINDEXNAME, MINIBASE_BUFFER_POOL_SIZE, MINIBASE_DB_SIZE, MINIBASE_DEFAULT_SHAREDMEM_SIZE, MINIBASE_MAX_TRANSACTIONS, MINIBASE_MAXARRSIZE, NUMBUF, PAGE_SIZE, PAGESIZE
 
Constructor Summary
BufMgr(int numbufs, java.lang.String replacerArg)
          Create a buffer manager object.
 
Method Summary
 void flushAllPages()
          Flushes all pages of the buffer pool to disk
 void flushPage(PageId pageid)
          Added to flush a particular page of the buffer pool to disk
 void freePage(PageId globalPageId)
          User should call this method if she needs to delete a page.
 AbstractBufMgrFrameDesc[] getFrameTable()
          A few routines currently need direct access to the FrameTable.
 int getNumBuffers()
          Gets the total number of buffers.
 int getNumUnpinnedBuffers()
          Gets the total number of unpinned buffer frames.
 PageId newPage(Page firstpage, int howmany)
          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.
 void pinPage(PageId pin_pgid, Page page, boolean emptyPage)
          Check if this page is in buffer pool, otherwise find a frame for this page, read in and pin it.
 void unpinPage(PageId PageId_in_a_DB, boolean dirty)
          To unpin a page specified by a pageId.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BufMgr

public BufMgr(int numbufs,
              java.lang.String replacerArg)
       throws InvalidReplacerException
Create a buffer manager object.

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

pinPage

public void pinPage(PageId pin_pgid,
                    Page page,
                    boolean emptyPage)
             throws ReplacerException,
                    HashOperationException,
                    PageUnpinnedException,
                    InvalidFrameNumberException,
                    PageNotReadException,
                    BufferPoolExceededException,
                    PagePinnedException,
                    BufMgrException,
                    java.io.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.

Specified by:
pinPage in class AbstractBufMgr
Parameters:
page - the pointer poit to the page.
emptyPage - true (empty page); false (non-empty page)
Throws:
ReplacerException - if there is a replacer error.
HashOperationException - if there is a hashtable error.
PageUnpinnedException - if there is a page that is already unpinned.
InvalidFrameNumberException - if there is an invalid frame number .
PageNotReadException - if a page cannot be read.
BufferPoolExceededException - if the buffer pool is full.
PagePinnedException - if a page is left pinned .
BufMgrException - other error occured in bufmgr layer
java.io.IOException - if there is other kinds of I/O error.

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.

Specified by:
unpinPage in class AbstractBufMgr
Parameters:
dirty - the dirty bit of the frame
Throws:
ReplacerException - if there is a replacer error.
PageUnpinnedException - if there is a page that is already unpinned.
InvalidFrameNumberException - if there is an invalid frame number .
HashEntryNotFoundException - if there is no entry of page in the hash table.

newPage

public PageId newPage(Page firstpage,
                      int howmany)
               throws BufferPoolExceededException,
                      HashOperationException,
                      ReplacerException,
                      HashEntryNotFoundException,
                      InvalidFrameNumberException,
                      PagePinnedException,
                      PageUnpinnedException,
                      PageNotReadException,
                      BufMgrException,
                      DiskMgrException,
                      java.io.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).

Specified by:
newPage in class AbstractBufMgr
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.
HashOperationException - if there is a hashtable error.
ReplacerException - if there is a replacer error.
HashEntryNotFoundException - if there is no entry of page in the hash table.
InvalidFrameNumberException - if there is an invalid frame number.
PageUnpinnedException - if there is a page that is already unpinned.
PagePinnedException - if a page is left pinned.
PageNotReadException - if a page cannot be read.
java.io.IOException - if there is other kinds of I/O error.
BufMgrException - other error occured in bufmgr layer
DiskMgrException - other error occured in diskmgr layer

freePage

public void freePage(PageId globalPageId)
              throws InvalidBufferException,
                     ReplacerException,
                     HashOperationException,
                     InvalidFrameNumberException,
                     PageNotReadException,
                     BufferPoolExceededException,
                     PagePinnedException,
                     PageUnpinnedException,
                     HashEntryNotFoundException,
                     BufMgrException,
                     DiskMgrException,
                     java.io.IOException
User should call this method if she needs to delete a page. this routine will call DB to deallocate the page.

Specified by:
freePage in class AbstractBufMgr
Parameters:
globalPageId - the page number in the data base.
Throws:
InvalidBufferException - if buffer pool corrupted.
ReplacerException - if there is a replacer error.
HashOperationException - if there is a hash table error.
InvalidFrameNumberException - if there is an invalid frame number.
PageNotReadException - if a page cannot be read.
BufferPoolExceededException - if the buffer pool is already full.
PagePinnedException - if a page is left pinned.
PageUnpinnedException - if there is a page that is already unpinned.
HashEntryNotFoundException - if there is no entry of page in the hash table.
java.io.IOException - if there is other kinds of I/O error.
BufMgrException - other error occured in bufmgr layer
DiskMgrException - other error occured in diskmgr layer

flushPage

public void flushPage(PageId pageid)
               throws HashOperationException,
                      PageUnpinnedException,
                      PagePinnedException,
                      PageNotFoundException,
                      BufMgrException,
                      java.io.IOException
Added to flush a particular page of the buffer pool to disk

Specified by:
flushPage in class AbstractBufMgr
Parameters:
pageid - the page number in the database.
Throws:
HashOperationException - if there is a hashtable error.
PageUnpinnedException - if there is a page that is already unpinned.
PagePinnedException - if a page is left pinned.
PageNotFoundException - if a page is not found.
BufMgrException - other error occured in bufmgr layer
java.io.IOException - if there is other kinds of I/O error.

flushAllPages

public void flushAllPages()
                   throws HashOperationException,
                          PageUnpinnedException,
                          PagePinnedException,
                          PageNotFoundException,
                          BufMgrException,
                          java.io.IOException
Flushes all pages of the buffer pool to disk

Specified by:
flushAllPages in class AbstractBufMgr
Throws:
HashOperationException - if there is a hashtable error.
PageUnpinnedException - if there is a page that is already unpinned.
PagePinnedException - if a page is left pinned.
PageNotFoundException - if a page is not found.
BufMgrException - other error occured in bufmgr layer
java.io.IOException - if there is other kinds of I/O error.

getNumBuffers

public int getNumBuffers()
Gets the total number of buffers.

Specified by:
getNumBuffers in class AbstractBufMgr
Returns:
total number of buffer frames.

getNumUnpinnedBuffers

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

Specified by:
getNumUnpinnedBuffers in class AbstractBufMgr
Returns:
total number of unpinned buffer frames.

getFrameTable

public AbstractBufMgrFrameDesc[] getFrameTable()
A few routines currently need direct access to the FrameTable.

Specified by:
getFrameTable in class AbstractBufMgr