java.lang.Object
net.metanotion.util.skiplist.SkipSpan<K,V>
net.metanotion.io.block.index.BSkipSpan<K,V>
- Type Parameters:
K- type of keys maintained by this skip spanV- type of values stored in this skip span
- All Implemented Interfaces:
Flushable
- Direct Known Subclasses:
IBSkipSpan
SkipList span implementation with in-memory key-value storage.
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)
Field Summary
Modifier and TypeFieldDescriptionprotected final BlockFileReference to the BlockFileReference to the BSkipListstatic final intContinuation page header length in bytesprotected static final intFixed header length in bytesprotected booleanWhether this span has been killed/deletedprotected Serializer<K> Key serializerprotected static final intMagic number for span pages ("Span")protected intNext page numberprotected intOverflow page numberprotected intPage number of this spanprotected intPrevious page numberprotected intNumber of keys this span can holdprotected Serializer<V> Value serializerConstructor Summary
Method Summary
Modifier and TypeMethodDescriptionprivate voidfflush()I2P - avoid super.flush()voidflush()Flush this span to disk.private intfreeContinuationPages(int curPage) Free a chain of continuation pagesstatic voidInitialize a new span page on disk.voidMark this span instance as killed and free its resources.private static <X extends Comparable<? super X>, Y>
voidload(BSkipSpan<X, Y> bss, BlockFile bf, BSkipList<X, Y> bsl, int spanPage, Serializer<X> key, Serializer<Y> val) Load a BSkipSpan from disk.protected voidloadData()Load the span's keys and values into memory (second half of load()).protected voidloadData(boolean flushOnError) Load the span's keys and values into memory.protected static <X extends Comparable<? super X>, Y>
voidloadInit(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 voidlostEntries(int firstBadEntry, int lastGoodPage) Attempt to recover from corrupt data in this span.newInstance(SkipList<K, V> sl) Create a new instance of this span type.toString()Get a string representation of this span.Methods inherited from class SkipSpan
firstKey, get, getEnd, getSpan, print, put, removeModifier and TypeMethodDescriptionfirstKey()Get the first key in this span.Get the value associated with the given key.getEnd()Get the end span of this chain.Get the span containing the given key.print()Dump all data from this span to the end.Put a key-value pair into this span.Object[]Remove a key-value pair from this span.
Field Details
MAGIC
HEADER_LEN
CONT_HEADER_LEN
public static final int CONT_HEADER_LENContinuation page header length in bytes- See Also:
bf
Reference to the BlockFilebsl
Reference to the BSkipListpage
protected int pagePage number of this spanoverflowPage
protected int overflowPageOverflow page numberprevPage
protected int prevPagePrevious page numbernextPage
protected int nextPageNext page numberkeySer
Key serializervalSer
Value serializerspanSize
protected int spanSizeNumber of keys this span can holdisKilled
protected boolean isKilledWhether this span has been killed/deleted
Constructor Details
BSkipSpan
BSkipSpan
public BSkipSpan(BlockFile bf, BSkipList<K, V> bsl, int spanPage, Serializer<K> key, Serializer<V> val) throws IOExceptionCreate a BSkipSpan and load its data from disk.- Parameters:
bf- the BlockFile this span is stored inbsl- the BSkipList this span belongs tospanPage- the page number of this spankey- the key serializerval- the value serializer- Throws:
IOException- if an I/O error occurs
Method Details
init
Initialize a new span page on disk.- Parameters:
bf- the BlockFile to write topage- the page number to initializespanSize- the size of the span- Throws:
IOException- if an I/O error occurs
newInstance
killInstance
public void killInstance()Mark this span instance as killed and free its resources.- Overrides:
killInstancein classSkipSpan<K extends Comparable<? super K>, V>
freeContinuationPages
Free a chain of continuation pages- Parameters:
curPage- the first page to be freed, if 0 this does nothing.- Returns:
- the number of pages freed
- Throws:
IOException- if a page read or free fails, or a continuation page has a bad magic number
flush
fflush
private void fflush()I2P - avoid super.flush()load
private static <X extends Comparable<? super X>, Y>void load(BSkipSpan<X, Y> bss, BlockFile bf, BSkipList<X, throws IOExceptionY> bsl, int spanPage, Serializer<X> key, Serializer<Y> val) Load a BSkipSpan from disk.- Type Parameters:
X- the key typeY- the value type- Parameters:
bss- the BSkipSpan to load intobf- the BlockFile this span is stored inbsl- the BSkipList this span belongs tospanPage- the page numberkey- the key serializerval- the value serializer- Throws:
IOException- if an I/O error occurs
loadInit
protected static <X extends Comparable<? super X>, Y>void loadInit(BSkipSpan<X, Y> bss, BlockFile bf, BSkipList<X, throws IOExceptionY> bsl, int spanPage, Serializer<X> key, Serializer<Y> val) Load the span headers from disk (first half of load()). Only reads the span headers.- Type Parameters:
X- the key typeY- the value type- Parameters:
bss- the BSkipSpan to load intobf- the BlockFile this span is stored inbsl- the BSkipList this span belongs tospanPage- the page numberkey- the key serializerval- the value serializer- Throws:
IOException- if an I/O error occurs
loadData
Load the span's keys and values into memory (second half of load()).- Throws:
IOException- if an I/O error occurs
loadData
Load the span's keys and values into memory.- Parameters:
flushOnError- set to false if you are going to flush anyway- Throws:
IOException- if an I/O error occurs
lostEntries
protected void lostEntries(int firstBadEntry, int lastGoodPage) Attempt to recover from corrupt data in this span. All entries starting with firstBadEntry are lost. Zero out the overflow page on lastGoodPage, and correct the number of entries in the first page. We don't attempt to free the lost continuation pages.- Parameters:
firstBadEntry- the first entry index that is corruptedlastGoodPage- the last good page number
toString