simpledb.buffer
Class BasicBufferMgr

java.lang.Object
  extended by simpledb.buffer.BasicBufferMgr

 class BasicBufferMgr
extends java.lang.Object

Manages the pinning and unpinning of buffers to blocks.

Author:
Edward Sciore

Constructor Summary
BasicBufferMgr(int numbuffs)
          Creates a buffer manager having the specified number of buffer slots.
 
Method Summary
(package private)  int available()
          Returns the number of available (i.e.
(package private)  void flushAll(int txnum)
          Flushes the dirty buffers modified by the specified transaction.
(package private)  Buffer pin(Block blk)
          Pins a buffer to the specified block.
(package private)  Buffer pinNew(java.lang.String filename, PageFormatter fmtr)
          Allocates a new block in the specified file, and pins a buffer to it.
(package private)  void unpin(Buffer buff)
          Unpins the specified buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicBufferMgr

BasicBufferMgr(int numbuffs)
Creates a buffer manager having the specified number of buffer slots. This constructor depends on both the FileMgr and LogMgr objects that it gets from the class SimpleDB. Those objects are created during system initialization. Thus this constructor cannot be called until SimpleDB.initFileAndLogMgr(String) or is called first.

Parameters:
numbuffs - the number of buffer slots to allocate
Method Detail

flushAll

void flushAll(int txnum)
Flushes the dirty buffers modified by the specified transaction.

Parameters:
txnum - the transaction's id number

pin

Buffer pin(Block blk)
Pins a buffer to the specified block. If there is already a buffer assigned to that block then that buffer is used; otherwise, an unpinned buffer from the pool is chosen. Returns a null value if there are no available buffers.

Parameters:
blk - a reference to a disk block
Returns:
the pinned buffer

pinNew

Buffer pinNew(java.lang.String filename,
              PageFormatter fmtr)
Allocates a new block in the specified file, and pins a buffer to it. Returns null (without allocating the block) if there are no available buffers.

Parameters:
filename - the name of the file
fmtr - a pageformatter object, used to format the new block
Returns:
the pinned buffer

unpin

void unpin(Buffer buff)
Unpins the specified buffer.

Parameters:
buff - the buffer to be unpinned

available

int available()
Returns the number of available (i.e. unpinned) buffers.

Returns:
the number of available buffers