public class HeapPage extends java.lang.Object implements Page
HeapFile
,
BufferPool
Modifier and Type | Field and Description |
---|---|
(package private) byte[] |
header |
(package private) int |
numSlots |
(package private) byte[] |
oldData |
private java.lang.Byte |
oldDataLock |
(package private) HeapPageId |
pid |
(package private) TupleDesc |
td |
(package private) Tuple[] |
tuples |
Constructor and Description |
---|
HeapPage(HeapPageId id,
byte[] data)
Create a HeapPage from a set of bytes of data read from disk.
|
Modifier and Type | Method and Description |
---|---|
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 |
isSlotUsed(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() |
final HeapPageId pid
final TupleDesc td
final byte[] header
final Tuple[] tuples
final int numSlots
byte[] oldData
private final java.lang.Byte oldDataLock
public HeapPage(HeapPageId id, byte[] data) throws java.io.IOException
floor((BufferPool.getPageSize()*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.getPageSize()
private int getNumTuples()
private int getHeaderSize()
public HeapPage getBeforeImage()
getBeforeImage
in interface Page
public void setBeforeImage()
setBeforeImage
in interface Page
public HeapPageId getId()
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 deleteDbException
- 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)
public TransactionId isDirty()
public int getNumEmptySlots()
public boolean isSlotUsed(int i)
private void markSlotUsed(int i, boolean value)
public java.util.Iterator<Tuple> iterator()