Package com._1c.g5.v8.xmdb.impl
Class BTreeMap<K,V>
- java.lang.Object
-
- com._1c.g5.v8.xmdb.impl.BTreeMap<K,V>
-
- All Implemented Interfaces:
KeyValueStorage<K,V>
public class BTreeMap<K,V> extends Object implements KeyValueStorage<K,V>
B*Tree (values store only in leaf nodes)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classBTreeMap.EntryIteratorIterator throught BTreeMap.entriesclassBTreeMap.EntrySetBTreeMap entry set implementationclassBTreeMap.MapEntryBTreeMap entry implementation
-
Field Summary
Fields Modifier and Type Field Description intpreallocMergeLeftFSintpreallocSplitLeftFSstatic intSERIALIZED_SIZEintsplitSeparatorinttintt2
-
Constructor Summary
Constructors Constructor Description BTreeMap(ITreeCache cache, byte valueType, int t, int splitSeparator, int mergeSeparator, boolean threadSafe, boolean valInLeaf, int preallocFreeSpace, int segment, long rootCLink, int size, int nodeCount, int height)BTree constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidattachStorage()Reattach temporary detached storagevoidclear()Remove all element from indexKeyValueStorageclone(int newSegment)Create clone of current index with new segmentIdKeyValueStoragecloneHeader(int newSegment)Clone only header of current index with new segmentIdlongcloneNode(BDirNode node, int level, int newSegment)voidclose()Close index (sync and clear caches)booleancontains(long key)Test if index contain specified keybooleancontains(String key)Test if index contain specified keyvoiddetachStorage()Temporary detach storagevoiddropCaches()Drop all cache without store write cache to diskSetentrySet()Get entry set from indexvoidevict()Advice to XMDB (put all data from caches to files, but no sync fdatasync call).byte[]get(long key)Get value by long keybyte[]get(String key)Get value by String keyITreeCachegetCache()Get internal index cache (same as database cache)byte[]getInt(long key)byte[]getInt(String key)intgetMergeSeparator()intgetPreallocFreeSpace()Get preallocated free space amountintgetSegment()Get segment id of indexintgetSplitSeparator()intgetT()booleangetValInLeaf()Get store values in leaf nodes flagbytegetValueType()voidinit(ITreeCache cache, byte valueType, int t, int splitSeparator, int mergeSeparator, boolean threadSafe, boolean valInLeaf, int preallocFreeSpace, int segment, long rootCLink, int size, int nodeCount, int height)booleanisDirNodeFull(BDirNode node)Test: if speficied dir node is fullbooleanisLeafNodeFull(BLeafNode node)Test: if speficied leaf node is fullbooleanisNodeFull(BNode node)Test: if specified node is fullbooleanisThreadSafe()Set<? extends Object>keySet()Get keys set (clone all keys from index into new set)voidmerge(KeyValueStorage map)voidmerge(KeyValueStorage<K,byte[]> s1, Map<K,byte[]> s2)Merge KVS and Map into current index (first can be this index)voidmerge(KeyValueStorage s1, KeyValueStorage s2)Merge two KVS into current index (first can be this index)BDirNodenewDirNode()Construct new dir node, compatible with current treeBLeafNodenewLeafNode()Construct new leaf node, compatible with current treevoidput(long key, byte[] value)Put new key/value pair in index (by long key)voidput(String key, byte[] value)Put new key/value pair in index (by String key)voidputRAW(long key, byte[] rawValue)Put raw (complex) value to index with complex value typebyte[]remove(long key)Remove long key from indexbyte[]remove(String key)Remove String key from indexprotected byte[]removeInt(long key)protected byte[]removeInt(String key)ByteBufferserialize()Serialize index headerintsize()Get index size in elementsvoidsync()Sync index state with internal store (to file).StringtoString()
-
-
-
Field Detail
-
SERIALIZED_SIZE
public static final int SERIALIZED_SIZE
- See Also:
- Constant Field Values
-
t
public int t
-
t2
public int t2
-
splitSeparator
public int splitSeparator
-
preallocSplitLeftFS
public int preallocSplitLeftFS
-
preallocMergeLeftFS
public int preallocMergeLeftFS
-
-
Constructor Detail
-
BTreeMap
public BTreeMap(ITreeCache cache, byte valueType, int t, int splitSeparator, int mergeSeparator, boolean threadSafe, boolean valInLeaf, int preallocFreeSpace, int segment, long rootCLink, int size, int nodeCount, int height)
BTree constructor- Parameters:
cache- the global cache to usevalueType- the valut type to storet- the half of width of three nodessplitSeparator- number of values in left node after splitingmergeSeparator- number of values in left node after merging treesthreadSafe- is current three should be a thread safevalInLeaf- is leaf node should store values innnerpreallocFreeSpace- number of bytes to allocate in leaf node for future values (if values stored in it)segment- the segment to use in global cacherootCLink- the compact link to root of tree (if new = EMPTY_LINK)size- number of elements, stored in threenodeCount- number of nodes in threeheight- height of three
-
-
Method Detail
-
newDirNode
public BDirNode newDirNode()
Construct new dir node, compatible with current tree- Returns:
- new dir node
-
newLeafNode
public BLeafNode newLeafNode()
Construct new leaf node, compatible with current tree- Returns:
- new leaf node
-
init
public void init(ITreeCache cache, byte valueType, int t, int splitSeparator, int mergeSeparator, boolean threadSafe, boolean valInLeaf, int preallocFreeSpace, int segment, long rootCLink, int size, int nodeCount, int height)
-
clear
public void clear()
Remove all element from index- Specified by:
clearin interfaceKeyValueStorage<K,V>
-
put
public void put(long key, byte[] value)Put new key/value pair in index (by long key)- Specified by:
putin interfaceKeyValueStorage<K,V>- Parameters:
key- key to putvalue- value to put
-
put
public void put(String key, byte[] value)
Put new key/value pair in index (by String key)- Specified by:
putin interfaceKeyValueStorage<K,V>- Parameters:
key- key to putvalue- value to put
-
isNodeFull
public final boolean isNodeFull(BNode node)
Test: if specified node is full- Parameters:
node- the node to test- Returns:
- value
trueif node is fullfalseotherwise
-
isDirNodeFull
public final boolean isDirNodeFull(BDirNode node)
Test: if speficied dir node is full- Parameters:
node- the dir node to test- Returns:
- value
trueif node is fullfalseotherwise
-
isLeafNodeFull
public final boolean isLeafNodeFull(BLeafNode node)
Test: if speficied leaf node is full- Parameters:
node- the leaf node to test- Returns:
- value
trueif node is fullfalseotherwise
-
get
public byte[] get(long key)
Get value by long key- Specified by:
getin interfaceKeyValueStorage<K,V>- Parameters:
key- key- Returns:
- value or null (if key doesn;t exist in index)
-
get
public byte[] get(String key)
Get value by String key- Specified by:
getin interfaceKeyValueStorage<K,V>- Parameters:
key- key- Returns:
- value or null (if key doesn;t exist in index)
-
keySet
public Set<? extends Object> keySet()
Get keys set (clone all keys from index into new set)- Specified by:
keySetin interfaceKeyValueStorage<K,V>- Returns:
- keys set
-
merge
public void merge(KeyValueStorage map)
-
size
public int size()
Get index size in elements- Specified by:
sizein interfaceKeyValueStorage<K,V>- Returns:
- size
-
sync
public void sync()
Sync index state with internal store (to file). Force write cache to store to engine;- Specified by:
syncin interfaceKeyValueStorage<K,V>
-
evict
public void evict()
Advice to XMDB (put all data from caches to files, but no sync fdatasync call). Not mandatory, just safe RAM & speedup another threads- Specified by:
evictin interfaceKeyValueStorage<K,V>
-
close
public void close()
Close index (sync and clear caches)- Specified by:
closein interfaceKeyValueStorage<K,V>
-
entrySet
public Set entrySet()
Get entry set from index- Specified by:
entrySetin interfaceKeyValueStorage<K,V>- Returns:
- entry
set
-
getCache
public ITreeCache getCache()
Get internal index cache (same as database cache)- Specified by:
getCachein interfaceKeyValueStorage<K,V>- Returns:
- index cache
-
merge
public void merge(KeyValueStorage s1, KeyValueStorage s2)
Merge two KVS into current index (first can be this index)- Specified by:
mergein interfaceKeyValueStorage<K,V>- Parameters:
s1- first KVS, bases2- second KVS, updates
-
putRAW
public void putRAW(long key, byte[] rawValue)Put raw (complex) value to index with complex value type- Specified by:
putRAWin interfaceKeyValueStorage<K,V>- Parameters:
key- long hash key of raw valuerawValue- raw (complex) value
-
remove
public byte[] remove(long key)
Remove long key from index- Specified by:
removein interfaceKeyValueStorage<K,V>- Parameters:
key- key to remove- Returns:
- old value (or null if key doesn;t exist in index)
-
remove
public byte[] remove(String key)
Remove String key from index- Specified by:
removein interfaceKeyValueStorage<K,V>- Parameters:
key- key to remove- Returns:
- old value (or null if key doesn;t exist in index)
-
getInt
public byte[] getInt(String key)
-
getInt
public byte[] getInt(long key)
-
removeInt
protected byte[] removeInt(long key)
-
removeInt
protected byte[] removeInt(String key)
-
getT
public int getT()
-
getSplitSeparator
public int getSplitSeparator()
-
getMergeSeparator
public int getMergeSeparator()
-
getValueType
public byte getValueType()
-
isThreadSafe
public boolean isThreadSafe()
-
detachStorage
public void detachStorage()
Temporary detach storage
-
attachStorage
public void attachStorage()
Reattach temporary detached storage
-
dropCaches
public void dropCaches()
Drop all cache without store write cache to disk- Specified by:
dropCachesin interfaceKeyValueStorage<K,V>
-
getValInLeaf
public boolean getValInLeaf()
Get store values in leaf nodes flag- Returns:
- value
trueif values stored in leaf nodefalseotherwise
-
getPreallocFreeSpace
public int getPreallocFreeSpace()
Get preallocated free space amount- Returns:
- preallocated free space (in bytes)
-
serialize
public ByteBuffer serialize()
Serialize index header- Specified by:
serializein interfaceKeyValueStorage<K,V>- Returns:
- index header byte[] representation
-
getSegment
public int getSegment()
Get segment id of index- Specified by:
getSegmentin interfaceKeyValueStorage<K,V>- Returns:
- segment id
-
clone
public KeyValueStorage clone(int newSegment)
Create clone of current index with new segmentId- Specified by:
clonein interfaceKeyValueStorage<K,V>- Parameters:
newSegment- new segment id- Returns:
- new index
-
cloneNode
public long cloneNode(BDirNode node, int level, int newSegment)
-
cloneHeader
public KeyValueStorage cloneHeader(int newSegment)
Clone only header of current index with new segmentId- Specified by:
cloneHeaderin interfaceKeyValueStorage<K,V>- Parameters:
newSegment- new segment id- Returns:
- new index (same as old, but with new index header and segment)
-
contains
public boolean contains(long key)
Test if index contain specified key- Specified by:
containsin interfaceKeyValueStorage<K,V>- Parameters:
key- key to test- Returns:
- "key exist in index" flag
-
contains
public boolean contains(String key)
Test if index contain specified key- Specified by:
containsin interfaceKeyValueStorage<K,V>- Parameters:
key- key to test- Returns:
- "key exist in index" flag
-
merge
public void merge(KeyValueStorage<K,byte[]> s1, Map<K,byte[]> s2)
Merge KVS and Map into current index (first can be this index)- Specified by:
mergein interfaceKeyValueStorage<K,V>- Parameters:
s1- fist KVS, bases2- second Map, updates
-
-