bufmgr
Class BufMgr

java.lang.Object
  extended by bufmgr.BufMgr
All Implemented Interfaces:
GlobalConst

public class BufMgr
extends java.lang.Object
implements GlobalConst

Minibase Buffer Manager

The buffer manager reads disk pages into a main memory page as needed. The collection of main memory pages (called frames) used by the buffer manager for this purpose is called the buffer pool. This is just an array of Page objects. The buffer manager is used by access methods, heap files, and relational operators to read, write, allocate, and de-allocate pages.


Field Summary
 
Fields inherited from interface global.GlobalConst
EMPTY_SLOT, FIRST_PAGEID, INVALID_PAGEID, MAX_COLSIZE, MAX_TUPSIZE, NAME_MAXLEN, PAGE_SIZE, PIN_DISKIO, PIN_MEMCPY, UNPIN_CLEAN, UNPIN_DIRTY
 
Constructor Summary
BufMgr(int numbufs)
          Constructs a buffer mamanger with the given settings.
 
Method Summary
 void flushAllPages()
          Immediately writes all dirty pages in the buffer pool to disk.
 void flushPage(PageId pageno)
          Immediately writes a page in the buffer pool to disk, if dirty.
 void freePage(PageId pageno)
          Deallocates a single page from disk, freeing it from the pool if needed.
 int getNumBuffers()
          Gets the total number of buffer frames.
 int getNumUnpinned()
          Gets the total number of unpinned buffer frames.
 PageId newPage(Page firstpg, int run_size)
          Allocates a set of new pages, and pins the first one in an appropriate frame in the buffer pool.
 void pinPage(PageId pageno, Page page, boolean skipRead)
          Pins a disk page into the buffer pool.
 void unpinPage(PageId pageno, boolean dirty)
          Unpins a disk page from the buffer pool, decreasing its pin count.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BufMgr

public BufMgr(int numbufs)
Constructs a buffer mamanger with the given settings.

Parameters:
numbufs - number of buffers in the buffer pool
Method Detail

newPage

public PageId newPage(Page firstpg,
                      int run_size)
Allocates a set of new pages, and pins the first one in an appropriate frame in the buffer pool.

Parameters:
firstpg - holds the contents of the first page
run_size - number of pages to allocate
Returns:
page id of the first new page
Throws:
java.lang.IllegalArgumentException - if PIN_MEMCPY and the page is pinned
java.lang.IllegalStateException - if all pages are pinned (i.e. pool exceeded)

freePage

public void freePage(PageId pageno)
Deallocates a single page from disk, freeing it from the pool if needed.

Parameters:
pageno - identifies the page to remove
Throws:
java.lang.IllegalArgumentException - if the page is pinned

pinPage

public void pinPage(PageId pageno,
                    Page page,
                    boolean skipRead)
Pins a disk page into the buffer pool. If the page is already pinned, this simply increments the pin count. Otherwise, this selects another page in the pool to replace, flushing it to disk if dirty.

Parameters:
pageno - identifies the page to pin
page - holds contents of the page, either an input or output param
skipRead - PIN_MEMCPY (replace in pool); PIN_DISKIO (read the page in)
Throws:
java.lang.IllegalArgumentException - if PIN_MEMCPY and the page is pinned
java.lang.IllegalStateException - if all pages are pinned (i.e. pool exceeded)

unpinPage

public void unpinPage(PageId pageno,
                      boolean dirty)
Unpins a disk page from the buffer pool, decreasing its pin count.

Parameters:
pageno - identifies the page to unpin
dirty - UNPIN_DIRTY if the page was modified, UNPIN_CLEAN otherrwise
Throws:
java.lang.IllegalArgumentException - if the page is not present or not pinned

flushPage

public void flushPage(PageId pageno)
Immediately writes a page in the buffer pool to disk, if dirty.


flushAllPages

public void flushAllPages()
Immediately writes all dirty pages in the buffer pool to disk.


getNumBuffers

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


getNumUnpinned

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