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 intMERGE_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 voidclear()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 segmentIdvoidclose()Close index (sync and clear caches)voidcommit()Commit changes from last merge operationbooleancontains(long key)Test if index contain specified keybooleancontains(String key)Test if index contain specified keyvoiddropCaches()Drop all cache without store write cache to diskBTreeMap.EntrySetentrySet()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)intgetMergeRebuildBorder()Get merge rebuild border.KeyValueStoragegetPrimaryStorage()Get base indexintgetSegment()Get segment id of indexSet<? extends Object>keySet()Get keys set (clone all keys from index into new set)voidmerge(KeyValueStorage updates)Merge updates into base index If updates contain entry with empty (=null) value - key will be removed from base indexvoidmerge(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)voidmerge(Map<K,V> updates)Merge updates into base index If updates contain entry with empty (=null) value - key will be removed from base indexvoidmergeCommit(KeyValueStorage updates)Merge&commit updates - fastest, but less integrity safe method to bulk update indexvoidmergeCommit(Map<K,V> updates)merge&commit updates - fastest, but less integrity safe method to bulk update indexvoidput(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 indexvoidrollback()Rollback changes from last uncommited merge operationByteBufferserialize()Serialize index headervoidsetMergeRebuildBorder(int mergeRebuildBorder)Set merge rebuild border (see getMergeRebuildBorder)intsize()Get index size in elementsvoidsync()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:KeyValueStorageGet index size in elements- Specified by:
sizein interfaceKeyValueStorage<K,V>- Returns:
- size
-
clear
public void clear()
Description copied from interface:KeyValueStorageRemove all element from index- Specified by:
clearin interfaceKeyValueStorage<K,V>
-
sync
public void sync()
Description copied from interface:KeyValueStorageSync index state with internal store (to file). Force write cache to store to engine;- Specified by:
syncin interfaceKeyValueStorage<K,V>
-
close
public void close()
Description copied from interface:KeyValueStorageClose index (sync and clear caches)- Specified by:
closein interfaceKeyValueStorage<K,V>
-
get
public byte[] get(long key)
Description copied from interface:KeyValueStorageGet 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)
Description copied from interface:KeyValueStorageGet value by String key- Specified by:
getin 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:KeyValueStoragePut 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)
Description copied from interface:KeyValueStoragePut new key/value pair in index (by String key)- Specified by:
putin interfaceKeyValueStorage<K,V>- Parameters:
key- key to putvalue- value to put
-
entrySet
public BTreeMap.EntrySet entrySet()
Description copied from interface:KeyValueStorageGet entry set from index- Specified by:
entrySetin interfaceKeyValueStorage<K,V>- Returns:
- entry
set
-
setMergeRebuildBorder
public void setMergeRebuildBorder(int mergeRebuildBorder)
Description copied from interface:TransactionalKVSSet merge rebuild border (see getMergeRebuildBorder)- Specified by:
setMergeRebuildBorderin interfaceTransactionalKVS<K,V>- Parameters:
mergeRebuildBorder- merge rebuild border
-
mergeCommit
public void mergeCommit(KeyValueStorage updates)
Description copied from interface:TransactionalKVSMerge&commit updates - fastest, but less integrity safe method to bulk update index- Specified by:
mergeCommitin interfaceTransactionalKVS<K,V>- Parameters:
updates- updates
-
merge
public void merge(KeyValueStorage updates)
Description copied from interface:TransactionalKVSMerge updates into base index If updates contain entry with empty (=null) value - key will be removed from base index- Specified by:
mergein interfaceTransactionalKVS<K,V>- Parameters:
updates- updates to merge
-
rollback
public void rollback() throws DBExceptionDescription copied from interface:TransactionalKVSRollback changes from last uncommited merge operation- Specified by:
rollbackin interfaceTransactionalKVS<K,V>- Throws:
DBException
-
commit
public void commit() throws DBExceptionDescription copied from interface:TransactionalKVSCommit changes from last merge operation- Specified by:
commitin interfaceTransactionalKVS<K,V>- Throws:
DBException
-
getCache
public ITreeCache getCache()
Description copied from interface:KeyValueStorageGet internal index cache (same as database cache)- Specified by:
getCachein interfaceKeyValueStorage<K,V>- Returns:
- index cache
-
merge
public void merge(KeyValueStorage s1, KeyValueStorage s2)
Description copied from interface:KeyValueStorageMerge two KVS into current index (first can be this index)- Specified by:
mergein interfaceKeyValueStorage<K,V>- Parameters:
s1- first KVS, bases2- second KVS, updates
-
remove
public byte[] remove(long key)
Description copied from interface:KeyValueStorageRemove 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)
Description copied from interface:KeyValueStorageRemove 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)
-
getPrimaryStorage
public KeyValueStorage getPrimaryStorage()
Description copied from interface:TransactionalKVSGet base index- Specified by:
getPrimaryStoragein interfaceTransactionalKVS<K,V>- Returns:
- KeyValueStorage
-
getMergeRebuildBorder
public int getMergeRebuildBorder()
Description copied from interface:TransactionalKVSGet 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:
getMergeRebuildBorderin interfaceTransactionalKVS<K,V>- Returns:
- merge rebuld border
-
dropCaches
public void dropCaches()
Description copied from interface:KeyValueStorageDrop all cache without store write cache to disk- Specified by:
dropCachesin interfaceKeyValueStorage<K,V>
-
serialize
public ByteBuffer serialize()
Description copied from interface:KeyValueStorageSerialize index header- Specified by:
serializein interfaceKeyValueStorage<K,V>- Returns:
- index header byte[] representation
-
getSegment
public int getSegment()
Description copied from interface:KeyValueStorageGet segment id of index- Specified by:
getSegmentin interfaceKeyValueStorage<K,V>- Returns:
- segment id
-
clone
public KeyValueStorage clone(int newSegment)
Description copied from interface:KeyValueStorageCreate clone of current index with new segmentId- Specified by:
clonein interfaceKeyValueStorage<K,V>- Parameters:
newSegment- new segment id- Returns:
- new index
-
cloneHeader
public KeyValueStorage cloneHeader(int newSegment)
Description copied from interface:KeyValueStorageClone 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)
-
putRAW
public void putRAW(long key, byte[] rawValue)Description copied from interface:KeyValueStoragePut 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
-
contains
public boolean contains(long key)
Description copied from interface:KeyValueStorageTest 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)
Description copied from interface:KeyValueStorageTest if index contain specified key- Specified by:
containsin interfaceKeyValueStorage<K,V>- Parameters:
key- key to test- Returns:
- "key exist in index" flag
-
evict
public void evict()
Description copied from interface:KeyValueStorageAdvice 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>
-
merge
public void merge(KeyValueStorage<K,byte[]> s1, Map<K,byte[]> s2)
Description copied from interface:KeyValueStorageMerge 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
-
merge
public void merge(Map<K,V> updates)
Description copied from interface:TransactionalKVSMerge updates into base index If updates contain entry with empty (=null) value - key will be removed from base index- Specified by:
mergein interfaceTransactionalKVS<K,V>- Parameters:
updates- updates to merge
-
mergeCommit
public void mergeCommit(Map<K,V> updates)
Description copied from interface:TransactionalKVSmerge&commit updates - fastest, but less integrity safe method to bulk update index- Specified by:
mergeCommitin interfaceTransactionalKVS<K,V>- Parameters:
updates- updates
-
keySet
public Set<? extends Object> keySet()
Description copied from interface:KeyValueStorageGet keys set (clone all keys from index into new set)- Specified by:
keySetin interfaceKeyValueStorage<K,V>- Returns:
- keys set
-
-