Package org.nustaq.offheap
Class FSTBinaryOffheapMap
java.lang.Object
org.nustaq.offheap.FSTBinaryOffheapMap
- Direct Known Subclasses:
FSTCodedOffheapMap
public class FSTBinaryOffheapMap
extends java.lang.Object
Baseclass of offheap maps.
FST OffHeap Maps enable to store key/value pairs in offheap memory. Additionally it provides
and iterator interface for all values. In order to also iterate keys, add each key to its value object,
as this OffHeap map does not support iteration of keys out of the box.
See subclasses for directly applicable classes (E.g. FSTStringOffheapMap)
The base is a generic bytesource to bytesource map. Note that key should be as short as possible (4-20 bytes) and
should have their most modified digit at the last character of their value.
e.g. [0,0,0,0,123,44] where '44' changes with each new key. Else on-heap memory consumption will grow.
Performance of lookup degrades with growing key size.
In case entries are updated frequently with values of different size, avoid fragementation
by adding extra space to each entry. Override getEntryLengthForContentLength for this.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceFSTBinaryOffheapMap.KeyValIter -
Field Summary
Fields Modifier and Type Field Description protected MallocBytezAllocatorallocprotected longbytezOffsetstatic intCORE_HEADER_LENstatic intCUSTOM_FILEHEADER_LENprotected BytezcustomHeaderstatic intFILE_HEADER_LENprotected FreeListfreeListstatic longGBprotected OffHeapByteTreeindexstatic intKEY_OFFSET_IN_HEADERprotected intkeyLenprotected java.lang.StringmappedFilestatic longMBprotected Bytezmemoryprotected intmutationCountprotected intnumElem -
Constructor Summary
Constructors Constructor Description FSTBinaryOffheapMap(int keyLen, long sizeMemBytes, int numberOfElems)FSTBinaryOffheapMap(java.lang.String mappedFile, int keyLen, long sizeMemBytes, int numberOfElems) -
Method Summary
Modifier and Type Method Description protected longaddEntry(ByteSource key, ByteSource value)protected voidaddToFreeList(long offset)FSTBinaryOffheapMap.KeyValIterbinaryKeys()java.util.Iterator<ByteSource>binaryValues()protected voiddecElems()voiddumpIndexStats()protected voidfinalize()voidfree()BytezByteSourcegetBinary(ByteSource key)get an entry. the returned ByteSource must be processed immediately as it will be reused internally on next get Warning: Concurrent Modification (e.g. add remove elements during iteration) is NOT SUPPORTED and NOT CHECKED.intgetCapacityMB()protected intgetContentLenFromHeader(long off)BytezgetCustomFileHeader()protected intgetEntryLengthForContentLength(long lengthOfEntry)called upon add, allows to reserve extra space for later growth per entryjava.lang.StringgetFileName()longgetFreeMem()protected intgetHeaderLen()protected intgetLenFromHeader(long off)intgetSize()longgetUsedMem()protected voidincElems()protected voidinit(int keyLen, long sizeMemBytes, int numberOfElems)protected voidinitFromFile(java.lang.String file, int keyLen, long sizeMemBytes, int numberOfElems)static voidmain(java.lang.String[] args)java.lang.StringprintBinaryKey(ByteSource key)voidputBinary(ByteSource key, ByteSource value)voidremoveBinary(ByteSource key)remove the key from the binary mapprotected voidremoveEntry(long offset)voidresizeStore(long required, long maxgrowbytes)PRIVILEGED method.protected voidsetEntry(long off, int entryLen, ByteSource value)protected voidwriteEntryHeader(long offset, int entryLen, int contentLen, boolean removed)
-
Field Details
-
MB
public static final long MB- See Also:
- Constant Field Values
-
GB
public static final long GB- See Also:
- Constant Field Values
-
CUSTOM_FILEHEADER_LEN
public static final int CUSTOM_FILEHEADER_LEN- See Also:
- Constant Field Values
-
CORE_HEADER_LEN
public static final int CORE_HEADER_LEN- See Also:
- Constant Field Values
-
FILE_HEADER_LEN
public static final int FILE_HEADER_LEN- See Also:
- Constant Field Values
-
KEY_OFFSET_IN_HEADER
public static final int KEY_OFFSET_IN_HEADER- See Also:
- Constant Field Values
-
index
-
memory
-
customHeader
-
alloc
-
numElem
protected int numElem -
keyLen
protected int keyLen -
bytezOffset
protected long bytezOffset -
freeList
-
mappedFile
protected java.lang.String mappedFile -
mutationCount
protected int mutationCount
-
-
Constructor Details
-
FSTBinaryOffheapMap
public FSTBinaryOffheapMap(java.lang.String mappedFile, int keyLen, long sizeMemBytes, int numberOfElems) throws java.lang.Exception- Throws:
java.lang.Exception
-
FSTBinaryOffheapMap
public FSTBinaryOffheapMap(int keyLen, long sizeMemBytes, int numberOfElems)
-
-
Method Details
-
getCustomFileHeader
-
initFromFile
protected void initFromFile(java.lang.String file, int keyLen, long sizeMemBytes, int numberOfElems) throws java.lang.Exception- Throws:
java.lang.Exception
-
init
protected void init(int keyLen, long sizeMemBytes, int numberOfElems) -
finalize
protected void finalize() throws java.lang.Throwable- Overrides:
finalizein classjava.lang.Object- Throws:
java.lang.Throwable
-
free
public void free() -
putBinary
-
removeEntry
protected void removeEntry(long offset) -
addToFreeList
protected void addToFreeList(long offset) -
setEntry
-
addEntry
-
resizeStore
public void resizeStore(long required, long maxgrowbytes)PRIVILEGED method. You gotta know what your doing here .. currently a very expensive operation .. frees everything, resize file and remap. Remapping involves rebuild of index.- Parameters:
required-
-
getBinary
get an entry. the returned ByteSource must be processed immediately as it will be reused internally on next get Warning: Concurrent Modification (e.g. add remove elements during iteration) is NOT SUPPORTED and NOT CHECKED. Collect keys to change inside iteration and perform changes after iteration is finished.- Parameters:
key-- Returns:
-
removeBinary
remove the key from the binary map- Parameters:
key-
-
decElems
protected void decElems() -
incElems
protected void incElems() -
getEntryLengthForContentLength
protected int getEntryLengthForContentLength(long lengthOfEntry)called upon add, allows to reserve extra space for later growth per entry- Parameters:
lengthOfEntry-- Returns:
-
writeEntryHeader
protected void writeEntryHeader(long offset, int entryLen, int contentLen, boolean removed) -
getHeaderLen
protected int getHeaderLen() -
getLenFromHeader
protected int getLenFromHeader(long off) -
getContentLenFromHeader
protected int getContentLenFromHeader(long off) -
binaryValues
-
printBinaryKey
-
binaryKeys
-
getFreeMem
public long getFreeMem() -
getUsedMem
public long getUsedMem() -
getCapacityMB
public int getCapacityMB() -
getSize
public int getSize() -
dumpIndexStats
public void dumpIndexStats() -
getFileName
public java.lang.String getFileName() -
main
public static void main(java.lang.String[] args) throws java.lang.Exception- Throws:
java.lang.Exception
-