global
Class AbstractBufMgr

java.lang.Object
  extended byglobal.AbstractBufMgr
All Implemented Interfaces:
GlobalConst
Direct Known Subclasses:
BufMgr, DummyBufMgr

public abstract class AbstractBufMgr
extends java.lang.Object
implements GlobalConst


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
AbstractBufMgr()
           
 
Method Summary
abstract  void flushAllPages()
          Flushes all pages of the buffer pool to disk
abstract  void flushPage(PageId pageid)
          Added to flush a particular page of the buffer pool to disk
abstract  void freePage(PageId globalPageId)
          User should call this method if she needs to delete a page.
abstract  AbstractBufMgrFrameDesc[] getFrameTable()
           
abstract  int getNumBuffers()
          Gets the total number of buffers.
abstract  int getNumUnpinnedBuffers()
          Gets the total number of unpinned buffer frames.
abstract  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.
abstract  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.
abstract  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

AbstractBufMgr

public AbstractBufMgr()
Method Detail

pinPage

public abstract 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.

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 abstract 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:
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 abstract 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).

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 abstract 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.

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 abstract 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

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 abstract void flushAllPages()
                            throws HashOperationException,
                                   PageUnpinnedException,
                                   PagePinnedException,
                                   PageNotFoundException,
                                   BufMgrException,
                                   java.io.IOException
Flushes all pages of the buffer pool to disk

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 abstract int getNumBuffers()
Gets the total number of buffers.

Returns:
total number of buffer frames.

getNumUnpinnedBuffers

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

Returns:
total number of unpinned buffer frames.

getFrameTable

public abstract AbstractBufMgrFrameDesc[] getFrameTable()