|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsimpledb.HeapPage
public class HeapPage
Each instance of HeapPage stores data for one page of HeapFiles and implements the Page interface that is used by BufferPool.
HeapFile
,
BufferPool
Field Summary | |
---|---|
(package private) byte[] |
header
|
(package private) int |
numSlots
|
(package private) byte[] |
oldData
|
(package private) HeapPageId |
pid
|
(package private) TupleDesc |
td
|
(package private) Tuple[] |
tuples
|
Constructor Summary | |
---|---|
HeapPage(HeapPageId id,
byte[] data)
Create a HeapPage from a set of bytes of data read from disk. |
Method Summary | |
---|---|
static byte[] |
createEmptyPageData()
Static method to generate a byte array corresponding to an empty HeapPage. |
void |
deleteTuple(Tuple t)
Delete the specified tuple from the page; the tuple should be updated to reflect that it is no longer stored on any page. |
HeapPage |
getBeforeImage()
Return a view of this page before it was modified -- used by recovery |
private int |
getHeaderSize()
Computes the number of bytes in the header of a page in a HeapFile with each tuple occupying tupleSize bytes |
HeapPageId |
getId()
Return the id of this page. |
int |
getNumEmptySlots()
Returns the number of empty slots on this page. |
private int |
getNumTuples()
Retrieve the number of tuples on this page. |
byte[] |
getPageData()
Generates a byte array representing the contents of this page. |
void |
insertTuple(Tuple t)
Adds the specified tuple to the page; the tuple should be updated to reflect that it is now stored on this page. |
TransactionId |
isDirty()
Returns the tid of the transaction that last dirtied this page, or null if the page is not dirty |
boolean |
isSlotFree(int i)
Returns true if associated slot on this page is filled. |
java.util.Iterator<Tuple> |
iterator()
|
void |
markDirty(boolean dirty,
TransactionId tid)
Marks this page as dirty/not dirty and record that transaction that did the dirtying |
private void |
markSlotUsed(int i,
boolean value)
Abstraction to fill or clear a slot on this page. |
private Tuple |
readNextTuple(java.io.DataInputStream dis,
int slotId)
Suck up tuples from the source file. |
void |
setBeforeImage()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
HeapPageId pid
TupleDesc td
byte[] header
Tuple[] tuples
int numSlots
byte[] oldData
Constructor Detail |
---|
public HeapPage(HeapPageId id, byte[] data) throws java.io.IOException
floor((BufferPool.PAGE_SIZE*8) / (tuple size * 8 + 1))
where tuple size is the size of tuples in this
database table, which can be determined via Catalog.getTupleDesc(int)
.
The number of 8-bit header words is equal to:
ceiling(no. tuple slots / 8)
java.io.IOException
Database.getCatalog()
,
Catalog.getTupleDesc(int)
,
BufferPool.PAGE_SIZE
Method Detail |
---|
private int getNumTuples()
private int getHeaderSize()
public HeapPage getBeforeImage()
getBeforeImage
in interface Page
public void setBeforeImage()
setBeforeImage
in interface Page
public HeapPageId getId()
Page
getId
in interface Page
private Tuple readNextTuple(java.io.DataInputStream dis, int slotId) throws java.util.NoSuchElementException
java.util.NoSuchElementException
public byte[] getPageData()
The invariant here is that it should be possible to pass the byte array generated by getPageData to the HeapPage constructor and have it produce an identical HeapPage object.
getPageData
in interface Page
HeapPage(simpledb.HeapPageId, byte[])
public static byte[] createEmptyPageData()
public void deleteTuple(Tuple t) throws DbException
t
- The tuple to delete
DbException
- if this tuple is not on this page, or tuple slot is
already empty.public void insertTuple(Tuple t) throws DbException
t
- The tuple to add.
DbException
- if the page is full (no empty slots) or tupledesc
is mismatch.public void markDirty(boolean dirty, TransactionId tid)
markDirty
in interface Page
public TransactionId isDirty()
isDirty
in interface Page
public int getNumEmptySlots()
public boolean isSlotFree(int i)
private void markSlotUsed(int i, boolean value)
public java.util.Iterator<Tuple> iterator()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |