|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectsimpledb.BufferPool
public class BufferPool
BufferPool manages the reading and writing of pages into memory from disk. Access methods call into it to retrieve pages, and it fetches pages from the appropriate location.
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.
| Field Summary | |
|---|---|
static int |
DEFAULT_PAGES
Default number of pages passed to the constructor. |
static int |
PAGE_SIZE
Bytes per page, including header. |
| Constructor Summary | |
|---|---|
BufferPool(int numPages)
Creates a BufferPool that caches up to numPages pages. |
|
| Method Summary | |
|---|---|
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. |
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 behalf of transaction tid. |
void |
releasePage(TransactionId tid,
PageId pid)
Releases the lock on a page. |
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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int PAGE_SIZE
public static final int DEFAULT_PAGES
| Constructor Detail |
|---|
public BufferPool(int numPages)
numPages - maximum number of pages in this buffer pool.| Method Detail |
|---|
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 page
TransactionAbortedException
DbException
public void releasePage(TransactionId tid,
PageId pid)
tid - the ID of the transaction requesting the unlockpid - the ID of the page to unlock
public void transactionComplete(TransactionId tid)
throws java.io.IOException
tid - the ID of the transaction requesting the unlock
java.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 abort
java.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 add
DbException
java.io.IOException
TransactionAbortedException
public void deleteTuple(TransactionId tid,
Tuple t)
throws DbException,
TransactionAbortedException
tid - the transaction adding the tuple.t - the tuple to add
DbException
TransactionAbortedException
public void flushAllPages()
throws java.io.IOException
java.io.IOExceptionpublic void discardPage(PageId pid)
private void flushPage(PageId pid)
throws java.io.IOException
pid - an ID indicating the page to flush
java.io.IOException
public void flushPages(TransactionId tid)
throws java.io.IOException
java.io.IOException
private void evictPage()
throws DbException
DbException
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||