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 final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    TransactionalKVSImpl(KeyValueStorage primaryKVS, Database database, String name)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Remove all element from index
    clone(int newSegment)
    Create clone of current index with new segmentId
    cloneHeader(int newSegment)
    Clone only header of current index with new segmentId
    void
    Close index (sync and clear caches)
    void
    Commit changes from last merge operation
    boolean
    contains(long key)
    Test if index contain specified key
    boolean
    Test if index contain specified key
    void
    Drop all cache without store write cache to disk
    Get entry set from index
    void
    Advice to XMDB (put all data from caches to files, but no sync fdatasync call).
    byte[]
    get(long key)
    Get value by long key
    byte[]
    get(String key)
    Get value by String key
    Get internal index cache (same as database cache)
    int
    Get merge rebuild border.
    Get base index
    int
    Get segment id of index
    Set<? extends Object>
    Get keys set (clone all keys from index into new set)
    void
    Merge updates into base index If updates contain entry with empty (=null) value - key will be removed from base index
    void
    merge(KeyValueStorage<K,byte[]> s1, Map<K,byte[]> s2)
    Merge KVS and Map into current index (first can be this index)
    void
    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 index
    void
    Merge&commit updates - fastest, but less integrity safe method to bulk update index
    void
    mergeCommit(Map<K,V> updates)
    merge&commit updates - fastest, but less integrity safe method to bulk update index
    void
    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 type
    byte[]
    remove(long key)
    Remove long key from index
    byte[]
    Remove String key from index
    void
    Rollback changes from last uncommited merge operation
    Serialize index header
    void
    setMergeRebuildBorder(int mergeRebuildBorder)
    Set merge rebuild border (see getMergeRebuildBorder)
    int
    Get index size in elements
    void
    Sync index state with internal store (to file).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MERGE_REBUILD_BORDER_DEF

      public static final int MERGE_REBUILD_BORDER_DEF
      See Also:
  • Constructor Details

  • Method Details

    • size

      public int size()
      Description copied from interface: KeyValueStorage
      Get index size in elements
      Specified by:
      size in interface KeyValueStorage<K,V>
      Returns:
      size
    • clear

      public void clear()
      Description copied from interface: KeyValueStorage
      Remove all element from index
      Specified by:
      clear in interface KeyValueStorage<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 interface KeyValueStorage<K,V>
    • close

      public void close()
      Description copied from interface: KeyValueStorage
      Close index (sync and clear caches)
      Specified by:
      close in interface KeyValueStorage<K,V>
    • get

      public byte[] get(long key)
      Description copied from interface: KeyValueStorage
      Get value by long key
      Specified by:
      get in interface KeyValueStorage<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 interface KeyValueStorage<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 interface KeyValueStorage<K,V>
      Parameters:
      key - key to put
      value - 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 interface KeyValueStorage<K,V>
      Parameters:
      key - key to put
      value - value to put
    • entrySet

      public BTreeMap.EntrySet entrySet()
      Description copied from interface: KeyValueStorage
      Get entry set from index
      Specified by:
      entrySet in interface KeyValueStorage<K,V>
      Returns:
      entry<Key,Value> set
    • setMergeRebuildBorder

      public void setMergeRebuildBorder(int mergeRebuildBorder)
      Description copied from interface: TransactionalKVS
      Set merge rebuild border (see getMergeRebuildBorder)
      Specified by:
      setMergeRebuildBorder in interface TransactionalKVS<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 interface TransactionalKVS<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 interface TransactionalKVS<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 interface TransactionalKVS<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 interface TransactionalKVS<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 interface KeyValueStorage<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 interface KeyValueStorage<K,V>
      Parameters:
      s1 - first KVS, base
      s2 - second KVS, updates
    • remove

      public byte[] remove(long key)
      Description copied from interface: KeyValueStorage
      Remove long key from index
      Specified by:
      remove in interface KeyValueStorage<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 interface KeyValueStorage<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 interface TransactionalKVS<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 interface TransactionalKVS<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 interface KeyValueStorage<K,V>
    • serialize

      public ByteBuffer serialize()
      Description copied from interface: KeyValueStorage
      Serialize index header
      Specified by:
      serialize in interface KeyValueStorage<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 interface KeyValueStorage<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 interface KeyValueStorage<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 interface KeyValueStorage<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 interface KeyValueStorage<K,V>
      Parameters:
      key - long hash key of raw value
      rawValue - raw (complex) value
    • contains

      public boolean contains(long key)
      Description copied from interface: KeyValueStorage
      Test if index contain specified key
      Specified by:
      contains in interface KeyValueStorage<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 interface KeyValueStorage<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 interface KeyValueStorage<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 interface KeyValueStorage<K,V>
      Parameters:
      s1 - fist KVS, base
      s2 - 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 interface TransactionalKVS<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 interface TransactionalKVS<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 interface KeyValueStorage<K,V>
      Returns:
      keys set