public class BufferPool
extends java.lang.Object
The BufferPool is also responsible for locking; when a transaction fetches a page, BufferPool checks that the transaction has the appropriate locks to read/write the page.
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_PAGES
Default number of pages passed to the constructor.
|
private static int |
PAGE_SIZE
Bytes per page, including header.
|
private static int |
pageSize |
Constructor and Description |
---|
BufferPool(int numPages)
Creates a BufferPool that caches up to numPages pages.
|
Modifier and Type | Method and Description |
---|---|
void |
deleteTuple(TransactionId tid,
Tuple t)
Remove the specified tuple from the buffer pool.
|
void |
discardPage(PageId pid)
Remove the specific page id from the buffer pool.
|
private void |
evictPage()
Discards a page from the buffer pool.
|
void |
flushAllPages()
Flush all dirty pages to disk.
|
private void |
flushPage(PageId pid)
Flushes a certain page to disk
|
void |
flushPages(TransactionId tid)
Write all pages of the specified transaction to disk.
|
Page |
getPage(TransactionId tid,
PageId pid,
Permissions perm)
Retrieve the specified page with the associated permissions.
|
static int |
getPageSize() |
boolean |
holdsLock(TransactionId tid,
PageId p)
Return true if the specified transaction has a lock on the specified page
|
void |
insertTuple(TransactionId tid,
int tableId,
Tuple t)
Add a tuple to the specified table on behalf of transaction tid.
|
void |
releasePage(TransactionId tid,
PageId pid)
Releases the lock on a page.
|
static void |
resetPageSize() |
static void |
setPageSize(int pageSize) |
void |
transactionComplete(TransactionId tid)
Release all locks associated with a given transaction.
|
void |
transactionComplete(TransactionId tid,
boolean commit)
Commit or abort a given transaction; release all locks associated to
the transaction.
|
private static final int PAGE_SIZE
private static int pageSize
public static final int DEFAULT_PAGES
public BufferPool(int numPages)
numPages
- maximum number of pages in this buffer pool.public static int getPageSize()
public static void setPageSize(int pageSize)
public static void resetPageSize()
public Page getPage(TransactionId tid, PageId pid, Permissions perm) throws TransactionAbortedException, DbException
The retrieved page should be looked up in the buffer pool. If it is present, it should be returned. If it is not present, it should be added to the buffer pool and returned. If there is insufficient space in the buffer pool, an page should be evicted and the new page should be added in its place.
tid
- the ID of the transaction requesting the pagepid
- the ID of the requested pageperm
- the requested permissions on the pageTransactionAbortedException
DbException
public void releasePage(TransactionId tid, PageId pid)
tid
- the ID of the transaction requesting the unlockpid
- the ID of the page to unlockpublic void transactionComplete(TransactionId tid) throws java.io.IOException
tid
- the ID of the transaction requesting the unlockjava.io.IOException
public boolean holdsLock(TransactionId tid, PageId p)
public void transactionComplete(TransactionId tid, boolean commit) throws java.io.IOException
tid
- the ID of the transaction requesting the unlockcommit
- a flag indicating whether we should commit or abortjava.io.IOException
public void insertTuple(TransactionId tid, int tableId, Tuple t) throws DbException, java.io.IOException, TransactionAbortedException
tid
- the transaction adding the tupletableId
- the table to add the tuple tot
- the tuple to addDbException
java.io.IOException
TransactionAbortedException
public void deleteTuple(TransactionId tid, Tuple t) throws DbException, java.io.IOException, TransactionAbortedException
tid
- the transaction deleting the tuple.t
- the tuple to deleteDbException
java.io.IOException
TransactionAbortedException
public void flushAllPages() throws java.io.IOException
java.io.IOException
public void discardPage(PageId pid)
private void flushPage(PageId pid) throws java.io.IOException
pid
- an ID indicating the page to flushjava.io.IOException
public void flushPages(TransactionId tid) throws java.io.IOException
java.io.IOException
private void evictPage() throws DbException
DbException