simpledb.buffer
Class BufferMgr

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

public class BufferMgr
extends Object

The publicly-accessible buffer manager. A buffer manager wraps a basic buffer manager, and provides the same methods. The difference is that the methods pin and pinNew will never return null. If no buffers are currently available, then the calling thread will be placed on a waiting list. The waiting threads are removed from the list when a buffer becomes available. If a thread has been waiting for a buffer for an excessive amount of time (currently, 10 seconds) then a BufferAbortException is thrown.

Author:
Edward Sciore

Constructor Summary
BufferMgr(int numbuffers)
          Creates a new buffer manager having the specified number of buffers.
 
Method Summary
 int available()
          Returns the number of available (ie unpinned) buffers.
 void flushAll(int txnum)
          Flushes the dirty buffers modified by the specified transaction.
 Buffer pin(Block blk)
          Pins a buffer to the specified block, potentially waiting until a buffer becomes available.
 Buffer pinNew(String filename, PageFormatter fmtr)
          Pins a buffer to a new block in the specified file, potentially waiting until a buffer becomes available.
 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

BufferMgr

public BufferMgr(int numbuffers)
Creates a new buffer manager having the specified number of buffers. 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:
numbuffers - the number of buffer slots to allocate
Method Detail

pin

public Buffer pin(Block blk)
Pins a buffer to the specified block, potentially waiting until a buffer becomes available. If no buffer becomes available within a fixed time period, then a BufferAbortException is thrown.

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

pinNew

public Buffer pinNew(String filename,
                     PageFormatter fmtr)
Pins a buffer to a new block in the specified file, potentially waiting until a buffer becomes available. If no buffer becomes available within a fixed time period, then a BufferAbortException is thrown.

Parameters:
filename - the name of the file
fmtr - the formatter used to initialize the page
Returns:
the buffer pinned to that block

unpin

public void unpin(Buffer buff)
Unpins the specified buffer. If the buffer's pin count becomes 0, then the threads on the wait list are notified.

Parameters:
buff - the buffer to be unpinned

flushAll

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

Parameters:
txnum - the transaction's id number

available

public int available()
Returns the number of available (ie unpinned) buffers.

Returns:
the number of available buffers


Copyright © 2011. All Rights Reserved.