|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectneustore.base.DBBuffer
public abstract class DBBuffer
Abstract base class for a buffer manager.
It helps index structures (derived from DBIndex
) manage disk pages.
Usage:
DBBuffer
by providing methods add
,
find
and flush
.
readPage(java.io.RandomAccessFile, int)
and writePage(java.io.RandomAccessFile, int, neustore.base.DBPage)
to read/write a disk page. Here readPage
returns an object of class
DBBufferReturnedElement
. Besides the page itself, the returned element also
specifies the nodeType and whether the node was parsed. If parsed, the returned
object is of class DBPage. Otherwise, the returned object is a byte array and
it's up to the application to generate a DBPage object. Moreover, nodeType=-1 and
0 are reserved (for DBByteArrayPage and DBEmptyPage). The application can explain
the other values. For example, a B+-tree may cast a nodeType=1 node to an index
node.
pin(java.io.RandomAccessFile, int)
or unpin(java.io.RandomAccessFile, int)
a page.
getIOs()
to get statistics, or call clearIOs()
to initialize the counters.
DBIndex
,
DBPage
Field Summary | |
---|---|
protected int |
bufferReadIO
number of read IOs on the buffer |
protected int |
bufferSize
how many pages the buffer has |
protected int |
bufferWriteIO
number of write IOs on the buffer |
protected int |
diskReadIO
number of read IOs on the disk |
protected int |
diskWriteIO
number of write IOs on the disk |
protected int |
pageSize
page size |
Constructor Summary | |
---|---|
DBBuffer(int bufferSize,
int pageSize)
Opens an existing Database file. |
Method Summary | |
---|---|
protected abstract void |
add(neustore.base.DBBuffer.DBBufferStoredElement stored)
Adds a page to the buffer. |
void |
clearIOs()
Resets the four counters bufferReadIO , etc. |
protected abstract neustore.base.DBBuffer.DBBufferStoredElement |
find(java.io.RandomAccessFile file,
int pageID)
Finds a page in buffer. |
protected abstract void |
flush(java.io.RandomAccessFile file)
Flushes the buffer pages corresponding to a give file. |
int[] |
getIOs()
Reports the disk/buffer I/Os. |
protected void |
load(java.io.RandomAccessFile file,
byte[] page,
int pageID)
Loads a page (the byte array) from disk. |
void |
pin(java.io.RandomAccessFile file,
int pageID)
Pins a page. |
DBBufferReturnElement |
readPage(java.io.RandomAccessFile file,
int pageID)
Returns a buffered page. |
protected void |
save(java.io.RandomAccessFile file,
byte[] page,
int pageID)
Saves a page (the byte array) to the disk. |
void |
unpin(java.io.RandomAccessFile file,
int pageID)
Unpins a page. |
void |
writePage(java.io.RandomAccessFile file,
int pageID,
DBPage dbpage)
Writes a DBPage to buffer. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected int bufferReadIO
protected int bufferWriteIO
protected int diskReadIO
protected int diskWriteIO
protected int bufferSize
protected int pageSize
Constructor Detail |
---|
public DBBuffer(int bufferSize, int pageSize)
bufferSize
- total number of buffer pagespageSize
- page sizeMethod Detail |
---|
public int[] getIOs()
protected void load(java.io.RandomAccessFile file, byte[] page, int pageID) throws java.io.IOException
diskReadIO
by one.
file
- the filepage
- the byte array of length pageSizepageID
- the page ID
java.io.IOException
protected void save(java.io.RandomAccessFile file, byte[] page, int pageID) throws java.io.IOException
diskWriteIO
by one.
page
- the byte array of length pageSizepageID
- the page ID
java.io.IOException
public void clearIOs()
bufferReadIO
, etc.
public DBBufferReturnElement readPage(java.io.RandomAccessFile file, int pageID) throws java.io.IOException
bufferReadIO
.
file
- which filepageID
- page ID
java.io.IOException
public void writePage(java.io.RandomAccessFile file, int pageID, DBPage dbpage) throws java.io.IOException
file
- the filepageID
- the page IDdbpage
- the DBPage object
java.io.IOException
public void pin(java.io.RandomAccessFile file, int pageID)
file
- the filepageID
- the page ID of the page to be pinnedpublic void unpin(java.io.RandomAccessFile file, int pageID)
file
- the filepageID
- the page ID of the page to be unpinnedprotected abstract neustore.base.DBBuffer.DBBufferStoredElement find(java.io.RandomAccessFile file, int pageID)
file
- the filepageID
- the page ID
protected abstract void add(neustore.base.DBBuffer.DBBufferStoredElement stored) throws java.io.IOException
stored
- the stored element
java.io.IOException
protected abstract void flush(java.io.RandomAccessFile file) throws java.io.IOException
file
- the file
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |