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 class
BTreeMap.EntryIterator
Iterator throught BTreeMap.entriesclass
BTreeMap.EntrySet
BTreeMap entry set implementationclass
BTreeMap.MapEntry
BTreeMap entry implementation
-
Field Summary
Fields Modifier and Type Field Description int
preallocMergeLeftFS
int
preallocSplitLeftFS
static int
SERIALIZED_SIZE
int
splitSeparator
int
t
int
t2
-
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 void
attachStorage()
Reattach temporary detached storagevoid
clear()
Remove all element from indexKeyValueStorage
clone(int newSegment)
Create clone of current index with new segmentIdKeyValueStorage
cloneHeader(int newSegment)
Clone only header of current index with new segmentIdlong
cloneNode(BDirNode node, int level, int newSegment)
void
close()
Close index (sync and clear caches)boolean
contains(long key)
Test if index contain specified keyboolean
contains(String key)
Test if index contain specified keyvoid
detachStorage()
Temporary detach storagevoid
dropCaches()
Drop all cache without store write cache to diskSet
entrySet()
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(String key)
Get value by String keyITreeCache
getCache()
Get internal index cache (same as database cache)byte[]
getInt(long key)
byte[]
getInt(String key)
int
getMergeSeparator()
int
getPreallocFreeSpace()
Get preallocated free space amountint
getSegment()
Get segment id of indexint
getSplitSeparator()
int
getT()
boolean
getValInLeaf()
Get store values in leaf nodes flagbyte
getValueType()
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)
boolean
isDirNodeFull(BDirNode node)
Test: if speficied dir node is fullboolean
isLeafNodeFull(BLeafNode node)
Test: if speficied leaf node is fullboolean
isNodeFull(BNode node)
Test: if specified node is fullboolean
isThreadSafe()
Set<? extends Object>
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)BDirNode
newDirNode()
Construct new dir node, compatible with current treeBLeafNode
newLeafNode()
Construct new leaf node, compatible with current treevoid
put(long key, byte[] value)
Put new key/value pair in index (by long key)void
put(String key, byte[] value)
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)
Remove String key from indexprotected byte[]
removeInt(long key)
protected byte[]
removeInt(String key)
ByteBuffer
serialize()
Serialize index headerint
size()
Get index size in elementsvoid
sync()
Sync index state with internal store (to file).String
toString()
-
-
-
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:
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
public void put(String key, byte[] value)
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
public final boolean isNodeFull(BNode node)
Test: if specified node is full- Parameters:
node
- the node to test- Returns:
- value
true
if node is fullfalse
otherwise
-
isDirNodeFull
public final boolean isDirNodeFull(BDirNode node)
Test: if speficied dir node is full- Parameters:
node
- the dir node to test- Returns:
- value
true
if node is fullfalse
otherwise
-
isLeafNodeFull
public final boolean isLeafNodeFull(BLeafNode node)
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
public byte[] get(String key)
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
public Set<? extends Object> keySet()
Get keys set (clone all keys from index into new set)- Specified by:
keySet
in interfaceKeyValueStorage<K,V>
- Returns:
- keys set
-
merge
public void merge(KeyValueStorage map)
-
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>
-
entrySet
public Set entrySet()
Get entry set from index- Specified by:
entrySet
in interfaceKeyValueStorage<K,V>
- Returns:
- entry
set
-
getCache
public ITreeCache getCache()
Get internal index cache (same as database cache)- Specified by:
getCache
in 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:
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
public byte[] remove(String key)
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
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:
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
public ByteBuffer 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
public KeyValueStorage clone(int newSegment)
Create clone of current index with new segmentId- Specified by:
clone
in 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:
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
public boolean contains(String 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
-
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:
merge
in interfaceKeyValueStorage<K,V>
- Parameters:
s1
- fist KVS, bases2
- second Map, updates
-
-