Package com._1c.g5.v8.xmdb.impl
Class TransactionalKVSImpl<K,V>
- java.lang.Object
-
- com._1c.g5.v8.xmdb.impl.TransactionalKVSImpl<K,V>
-
- All Implemented Interfaces:
KeyValueStorage<K,V>
,TransactionalKVS<K,V>
public class TransactionalKVSImpl<K,V> extends Object implements TransactionalKVS<K,V>
-
-
Field Summary
Fields Modifier and Type Field Description static int
MERGE_REBUILD_BORDER_DEF
-
Constructor Summary
Constructors Constructor Description TransactionalKVSImpl(KeyValueStorage primaryKVS, Database database, String name)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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 segmentIdvoid
close()
Close index (sync and clear caches)void
commit()
Commit changes from last merge operationboolean
contains(long key)
Test if index contain specified keyboolean
contains(String key)
Test if index contain specified keyvoid
dropCaches()
Drop all cache without store write cache to diskBTreeMap.EntrySet
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)int
getMergeRebuildBorder()
Get merge rebuild border.KeyValueStorage
getPrimaryStorage()
Get base indexint
getSegment()
Get segment id of indexSet<? extends Object>
keySet()
Get keys set (clone all keys from index into new set)void
merge(KeyValueStorage updates)
Merge updates into base index If updates contain entry with empty (=null) value - key will be removed from base indexvoid
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)void
merge(Map<K,V> updates)
Merge updates into base index If updates contain entry with empty (=null) value - key will be removed from base indexvoid
mergeCommit(KeyValueStorage updates)
Merge&commit updates - fastest, but less integrity safe method to bulk update indexvoid
mergeCommit(Map<K,V> updates)
merge&commit updates - fastest, but less integrity safe method to bulk update indexvoid
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 indexvoid
rollback()
Rollback changes from last uncommited merge operationByteBuffer
serialize()
Serialize index headervoid
setMergeRebuildBorder(int mergeRebuildBorder)
Set merge rebuild border (see getMergeRebuildBorder)int
size()
Get index size in elementsvoid
sync()
Sync index state with internal store (to file).
-
-
-
Field Detail
-
MERGE_REBUILD_BORDER_DEF
public static final int MERGE_REBUILD_BORDER_DEF
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TransactionalKVSImpl
public TransactionalKVSImpl(KeyValueStorage primaryKVS, Database database, String name)
-
-
Method Detail
-
size
public int size()
Description copied from interface:KeyValueStorage
Get index size in elements- Specified by:
size
in interfaceKeyValueStorage<K,V>
- Returns:
- size
-
clear
public void clear()
Description copied from interface:KeyValueStorage
Remove all element from index- Specified by:
clear
in interfaceKeyValueStorage<K,V>
-
sync
public void sync()
Description copied from interface:KeyValueStorage
Sync index state with internal store (to file). Force write cache to store to engine;- Specified by:
sync
in interfaceKeyValueStorage<K,V>
-
close
public void close()
Description copied from interface:KeyValueStorage
Close index (sync and clear caches)- Specified by:
close
in interfaceKeyValueStorage<K,V>
-
get
public byte[] get(long key)
Description copied from interface:KeyValueStorage
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)
Description copied from interface:KeyValueStorage
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)
-
put
public void put(long key, byte[] value)
Description copied from interface:KeyValueStorage
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)
Description copied from interface:KeyValueStorage
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
-
entrySet
public BTreeMap.EntrySet entrySet()
Description copied from interface:KeyValueStorage
Get entry set from index- Specified by:
entrySet
in interfaceKeyValueStorage<K,V>
- Returns:
- entry
set
-
setMergeRebuildBorder
public void setMergeRebuildBorder(int mergeRebuildBorder)
Description copied from interface:TransactionalKVS
Set merge rebuild border (see getMergeRebuildBorder)- Specified by:
setMergeRebuildBorder
in interfaceTransactionalKVS<K,V>
- Parameters:
mergeRebuildBorder
- merge rebuild border
-
mergeCommit
public void mergeCommit(KeyValueStorage updates)
Description copied from interface:TransactionalKVS
Merge&commit updates - fastest, but less integrity safe method to bulk update index- Specified by:
mergeCommit
in interfaceTransactionalKVS<K,V>
- Parameters:
updates
- updates
-
merge
public void merge(KeyValueStorage updates)
Description copied from interface:TransactionalKVS
Merge updates into base index If updates contain entry with empty (=null) value - key will be removed from base index- Specified by:
merge
in interfaceTransactionalKVS<K,V>
- Parameters:
updates
- updates to merge
-
rollback
public void rollback() throws DBException
Description copied from interface:TransactionalKVS
Rollback changes from last uncommited merge operation- Specified by:
rollback
in interfaceTransactionalKVS<K,V>
- Throws:
DBException
-
commit
public void commit() throws DBException
Description copied from interface:TransactionalKVS
Commit changes from last merge operation- Specified by:
commit
in interfaceTransactionalKVS<K,V>
- Throws:
DBException
-
getCache
public ITreeCache getCache()
Description copied from interface:KeyValueStorage
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)
Description copied from interface:KeyValueStorage
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
-
remove
public byte[] remove(long key)
Description copied from interface:KeyValueStorage
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)
Description copied from interface:KeyValueStorage
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)
-
getPrimaryStorage
public KeyValueStorage getPrimaryStorage()
Description copied from interface:TransactionalKVS
Get base index- Specified by:
getPrimaryStorage
in interfaceTransactionalKVS<K,V>
- Returns:
- KeyValueStorage
-
getMergeRebuildBorder
public int getMergeRebuildBorder()
Description copied from interface:TransactionalKVS
Get merge rebuild border. Value (in percent) show how many updates need to full rebuild of base index. If updates have less size - it will be merge by simple put into base index (on mergeCommit method) or base index clone (on merge method)- Specified by:
getMergeRebuildBorder
in interfaceTransactionalKVS<K,V>
- Returns:
- merge rebuld border
-
dropCaches
public void dropCaches()
Description copied from interface:KeyValueStorage
Drop all cache without store write cache to disk- Specified by:
dropCaches
in interfaceKeyValueStorage<K,V>
-
serialize
public ByteBuffer serialize()
Description copied from interface:KeyValueStorage
Serialize index header- Specified by:
serialize
in interfaceKeyValueStorage<K,V>
- Returns:
- index header byte[] representation
-
getSegment
public int getSegment()
Description copied from interface:KeyValueStorage
Get segment id of index- Specified by:
getSegment
in interfaceKeyValueStorage<K,V>
- Returns:
- segment id
-
clone
public KeyValueStorage clone(int newSegment)
Description copied from interface:KeyValueStorage
Create clone of current index with new segmentId- Specified by:
clone
in interfaceKeyValueStorage<K,V>
- Parameters:
newSegment
- new segment id- Returns:
- new index
-
cloneHeader
public KeyValueStorage cloneHeader(int newSegment)
Description copied from interface:KeyValueStorage
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)
-
putRAW
public void putRAW(long key, byte[] rawValue)
Description copied from interface:KeyValueStorage
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
-
contains
public boolean contains(long key)
Description copied from interface:KeyValueStorage
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)
Description copied from interface:KeyValueStorage
Test if index contain specified key- Specified by:
contains
in interfaceKeyValueStorage<K,V>
- Parameters:
key
- key to test- Returns:
- "key exist in index" flag
-
evict
public void evict()
Description copied from interface:KeyValueStorage
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>
-
merge
public void merge(KeyValueStorage<K,byte[]> s1, Map<K,byte[]> s2)
Description copied from interface:KeyValueStorage
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
-
merge
public void merge(Map<K,V> updates)
Description copied from interface:TransactionalKVS
Merge updates into base index If updates contain entry with empty (=null) value - key will be removed from base index- Specified by:
merge
in interfaceTransactionalKVS<K,V>
- Parameters:
updates
- updates to merge
-
mergeCommit
public void mergeCommit(Map<K,V> updates)
Description copied from interface:TransactionalKVS
merge&commit updates - fastest, but less integrity safe method to bulk update index- Specified by:
mergeCommit
in interfaceTransactionalKVS<K,V>
- Parameters:
updates
- updates
-
keySet
public Set<? extends Object> keySet()
Description copied from interface:KeyValueStorage
Get keys set (clone all keys from index into new set)- Specified by:
keySet
in interfaceKeyValueStorage<K,V>
- Returns:
- keys set
-
-