K - type of keys maintained by this skip spanV - type of values stored in this skip spanpublic class BSkipSpan<K extends Comparable<? super K>,V> extends SkipSpan<K,V>
Stores all keys and values in memory for fast access while maintaining disk persistence. Supports overflow to additional pages when capacity is exceeded.
On-disk format:
First Page:
Magic number (int)
overflow page (unsigned int)
previous page (unsigned int)
next page (unsigned int)
max keys (unsigned short)
number of keys (unsigned short)
for each key:
key length (unsigned short)
value length (unsigned short)
key data
value data
Overflow pages:
Magic number (int)
next overflow page (unsigned int)
| Modifier and Type | Field and Description |
|---|---|
protected BlockFile | bfReference to the BlockFile |
static int | CONT_HEADER_LENContinuation page header length in bytes |
protected static int | HEADER_LENFixed header length in bytes |
protected boolean | isKilledWhether this span has been killed/deleted |
protected Serializer<K> | keySerKey serializer |
protected static int | MAGICMagic number for span pages ("Span") |
protected int | nextPageNext page number |
protected int | overflowPageOverflow page number |
protected int | pagePage number of this span |
protected int | prevPagePrevious page number |
protected int | spanSizeNumber of keys this span can hold |
protected Serializer<V> | valSerValue serializer |
| Modifier | Constructor and Description |
|---|---|
protected | BSkipSpan(BlockFile bf,
BSkipList<K,V> bsl)Create a new BSkipSpan with the given BlockFile and BSkipList. |
| BSkipSpan(BlockFile bf,
BSkipList<K,V> bsl,
int spanPage,
Serializer<K> key,
Serializer<V> val)Create a BSkipSpan and load its data from disk. |
| Modifier and Type | Method and Description |
|---|---|
void | flush()Flush this span to disk. |
static void | init(BlockFile bf,
int page,
int spanSize)Initialize a new span page on disk. |
void | killInstance()Mark this span instance as killed and free its resources. |
protected void | loadData()Load the span's keys and values into memory (second half of load()). |
protected void | loadData(boolean flushOnError)Load the span's keys and values into memory. |
protected static <X extends Comparable<? super X>,Y> | loadInit(BSkipSpan<X,Y> bss,
BlockFile bf,
BSkipList<X,Y> bsl,
int spanPage,
Serializer<X> key,
Serializer<Y> val)Load the span headers from disk (first half of load()). |
protected void | lostEntries(int firstBadEntry,
int lastGoodPage)Attempt to recover from corrupt data in this span. |
SkipSpan<K,V> | newInstance(SkipList<K,V> sl)Create a new instance of this span type. |
String | toString()Get a string representation of this span. |
protected final BlockFile bf
public static final int CONT_HEADER_LEN
protected static final int HEADER_LEN
protected boolean isKilled
protected Serializer<K extends Comparable<? super K>> keySer
protected static final int MAGIC
protected int nextPage
protected int overflowPage
protected int page
protected int prevPage
protected int spanSize
protected Serializer<V> valSer
protected BSkipSpan(BlockFile bf, BSkipList<K,V> bsl)
bf - the BlockFilebsl - the BSkipListpublic BSkipSpan(BlockFile bf, BSkipList<K,V> bsl, int spanPage, Serializer<K> key, Serializer<V> val) throws IOException
bf - the BlockFilebsl - the BSkipListspanPage - the page number of this spankey - the keyval - the value serializerIOException - if an I/O error occurspublic void flush()
public static void init(BlockFile bf, int page, int spanSize) throws IOException
bf - the BlockFile to write topage - the page number to initializespanSize - the size of the spanIOException - if an I/O error occurspublic void killInstance()
killInstance in class SkipSpan<K extends Comparable<? super K>,V>protected void loadData()
throws IOExceptionIOException - if an I/O error occursprotected void loadData(boolean flushOnError)
throws IOExceptionflushOnError - set to false if you are going to flush anywayIOException - if an I/O error occursprotected static <X extends Comparable<? super X>,Y> void loadInit(BSkipSpan<X,Y> bss, BlockFile bf, BSkipList<X,Y> bsl, int spanPage, Serializer<X> key, Serializer<Y> val) throws IOException
X - the key typeY - the value typebss - the BSkipSpan to load intobf - the BlockFilebsl - the BSkipListspanPage - the page numberkey - the keyval - the value serializerIOException - if an I/O error occursprotected void lostEntries(int firstBadEntry,
int lastGoodPage)firstBadEntry - the first entry index that is corruptedlastGoodPage - the last good page numberpublic SkipSpan<K,V> newInstance(SkipList<K,V> sl)
newInstance in class SkipSpan<K extends Comparable<? super K>,V>sl - the SkipList to create the span for