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>
B*Tree (values store only in leaf nodes)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
Iterator throught BTreeMap.entriesclass
BTreeMap entry set implementationclass
BTreeMap entry implementation -
Field Summary
FieldsModifier and TypeFieldDescriptionint
int
static final int
int
int
int
-
Constructor Summary
ConstructorsConstructorDescriptionBTreeMap
(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
Modifier and TypeMethodDescriptionvoid
Reattach temporary detached storagevoid
clear()
Remove all element from indexclone
(int newSegment) Create clone of current index with new segmentIdcloneHeader
(int newSegment) Clone only header of current index with new segmentIdlong
void
close()
Close index (sync and clear caches)boolean
contains
(long key) Test if index contain specified keyboolean
Test if index contain specified keyvoid
Temporary detach storagevoid
Drop all cache without store write cache to diskentrySet()
Get entry set from indexvoid
evict()
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 value by String keygetCache()
Get internal index cache (same as database cache)byte[]
getInt
(long key) byte[]
int
int
Get preallocated free space amountint
Get segment id of indexint
int
getT()
boolean
Get store values in leaf nodes flagbyte
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) final boolean
isDirNodeFull
(BDirNode node) Test: if speficied dir node is fullfinal boolean
isLeafNodeFull
(BLeafNode node) Test: if speficied leaf node is fullfinal boolean
isNodeFull
(BNode node) Test: if specified node is fullboolean
keySet()
Get keys set (clone all keys from index into new set)void
merge
(KeyValueStorage map) void
merge
(KeyValueStorage<K, byte[]> s1, Map<K, byte[]> s2) Merge KVS and Map into current index (first can be this index)void
merge
(KeyValueStorage s1, KeyValueStorage s2) Merge two KVS into current index (first can be this index)Construct new dir node, compatible with current treeConstruct new leaf node, compatible with current treevoid
put
(long key, byte[] value) Put new key/value pair in index (by long key)void
Put new key/value pair in index (by String key)void
putRAW
(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 from indexprotected byte[]
removeInt
(long key) protected byte[]
Serialize index headerint
size()
Get index size in elementsvoid
sync()
Sync index state with internal store (to file).toString()
-
Field Details
-
SERIALIZED_SIZE
public static final int SERIALIZED_SIZE- See Also:
-
t
public int t -
t2
public int t2 -
splitSeparator
public int splitSeparator -
preallocSplitLeftFS
public int preallocSplitLeftFS -
preallocMergeLeftFS
public int preallocMergeLeftFS
-
-
Constructor Details
-
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 Details
-
newDirNode
Construct new dir node, compatible with current tree- Returns:
- new dir node
-
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:
clear
in interfaceKeyValueStorage<K,
V>
-
put
public void put(long key, byte[] value) Put new key/value pair in index (by long key)- Specified by:
put
in interfaceKeyValueStorage<K,
V> - Parameters:
key
- key to putvalue
- value to put
-
put
Put new key/value pair in index (by String key)- Specified by:
put
in interfaceKeyValueStorage<K,
V> - Parameters:
key
- key to putvalue
- value to put
-
isNodeFull
Test: if specified node is full- Parameters:
node
- the node to test- Returns:
- value
true
if node is fullfalse
otherwise
-
isDirNodeFull
Test: if speficied dir node is full- Parameters:
node
- the dir node to test- Returns:
- value
true
if node is fullfalse
otherwise
-
isLeafNodeFull
Test: if speficied leaf node is full- Parameters:
node
- the leaf node to test- Returns:
- value
true
if node is fullfalse
otherwise
-
get
public byte[] get(long key) Get value by long key- Specified by:
get
in interfaceKeyValueStorage<K,
V> - Parameters:
key
- key- Returns:
- value or null (if key doesn;t exist in index)
-
get
Get value by String key- Specified by:
get
in interfaceKeyValueStorage<K,
V> - Parameters:
key
- key- Returns:
- value or null (if key doesn;t exist in index)
-
keySet
Get keys set (clone all keys from index into new set)- Specified by:
keySet
in interfaceKeyValueStorage<K,
V> - Returns:
- keys set
-
merge
-
size
public int size()Get index size in elements- Specified by:
size
in 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:
sync
in 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:
evict
in interfaceKeyValueStorage<K,
V>
-
close
public void close()Close index (sync and clear caches)- Specified by:
close
in interfaceKeyValueStorage<K,
V>
-
toString
-
entrySet
Get entry set from index- Specified by:
entrySet
in interfaceKeyValueStorage<K,
V> - Returns:
- entry<Key,Value> set
-
getCache
Get internal index cache (same as database cache)- Specified by:
getCache
in interfaceKeyValueStorage<K,
V> - Returns:
- index cache
-
merge
Merge two KVS into current index (first can be this index)- Specified by:
merge
in 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:
putRAW
in 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:
remove
in interfaceKeyValueStorage<K,
V> - Parameters:
key
- key to remove- Returns:
- old value (or null if key doesn;t exist in index)
-
remove
Remove String key from index- Specified by:
remove
in interfaceKeyValueStorage<K,
V> - Parameters:
key
- key to remove- Returns:
- old value (or null if key doesn;t exist in index)
-
getInt
-
getInt
public byte[] getInt(long key) -
removeInt
protected byte[] removeInt(long key) -
removeInt
-
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:
dropCaches
in interfaceKeyValueStorage<K,
V>
-
getValInLeaf
public boolean getValInLeaf()Get store values in leaf nodes flag- Returns:
- value
true
if values stored in leaf nodefalse
otherwise
-
getPreallocFreeSpace
public int getPreallocFreeSpace()Get preallocated free space amount- Returns:
- preallocated free space (in bytes)
-
serialize
Serialize index header- Specified by:
serialize
in interfaceKeyValueStorage<K,
V> - Returns:
- index header byte[] representation
-
getSegment
public int getSegment()Get segment id of index- Specified by:
getSegment
in interfaceKeyValueStorage<K,
V> - Returns:
- segment id
-
clone
Create clone of current index with new segmentId- Specified by:
clone
in interfaceKeyValueStorage<K,
V> - Parameters:
newSegment
- new segment id- Returns:
- new index
-
cloneNode
-
cloneHeader
Clone only header of current index with new segmentId- Specified by:
cloneHeader
in 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:
contains
in interfaceKeyValueStorage<K,
V> - Parameters:
key
- key to test- Returns:
- "key exist in index" flag
-
contains
Test if index contain specified key- Specified by:
contains
in interfaceKeyValueStorage<K,
V> - Parameters:
key
- key to test- Returns:
- "key exist in index" flag
-
merge
Merge KVS and Map into current index (first can be this index)- Specified by:
merge
in interfaceKeyValueStorage<K,
V> - Parameters:
s1
- fist KVS, bases2
- second Map, updates
-