Class MVStoreAtomicKVStore

All Implemented Interfaces:
KVStore, AtomicKVStore

@ThreadSafe public class MVStoreAtomicKVStore extends MVMapKVStore implements AtomicKVStore
An AtomicKVStore implementation based on an MVMap in an MVStore.
See Also:
  • Field Details

    • MAP_BUILDER

      public static final org.h2.mvstore.MVMap.Builder<byte[],byte[]> MAP_BUILDER
      The MVMap.Builder used by this class.

      Note this builder is configured with MVMap.Builder.singleWriter.

    • log

      protected final Logger log
  • Constructor Details

    • MVStoreAtomicKVStore

      public MVStoreAtomicKVStore()
  • Method Details

    • getMVMap

      public org.h2.mvstore.MVMap<byte[],byte[]> getMVMap()
      Get the underlying MVMap associated with this instance.
      Returns:
      the associated underlying MVMap
    • doOpen

      protected void doOpen()
    • doClose

      protected void doClose()
    • doCloseImmediately

      protected void doCloseImmediately()
    • put

      public void put(byte[] key, byte[] value)
      Description copied from interface: KVStore
      Set the value associated with the given key.
      Specified by:
      put in interface KVStore
      Overrides:
      put in class MVMapKVStore
      Parameters:
      key - key
      value - value
    • remove

      public void remove(byte[] key)
      Description copied from interface: KVStore
      Remove the key/value pair with the given key, if it exists.
      Specified by:
      remove in interface KVStore
      Overrides:
      remove in class MVMapKVStore
      Parameters:
      key - key
    • removeRange

      public void removeRange(byte[] minKey, byte[] maxKey)
      Description copied from interface: KVStore
      Remove all key/value pairs whose keys are in a given range.

      The minKey must be less than or equal to maxKey; if they equal (and not null) then nothing happens; if they are both null then all entries are deleted.

      If keys starting with 0xff are not supported by this instance, then:

      • If minKey starts with 0xff, then no change occurs
      • If maxKey starts with 0xff, then this method behaves as if maxKey were null
      Specified by:
      removeRange in interface KVStore
      Overrides:
      removeRange in class AbstractKVStore
      Parameters:
      minKey - minimum key (inclusive), or null for no minimum
      maxKey - maximum key (exclusive), or null for no maximum
    • readOnlySnapshot

      public MVMapSnapshot readOnlySnapshot()
      Description copied from interface: AtomicKVStore
      Create a read-only "snapshot" view of this instance equal to its current state.

      The returned CloseableKVStore should be treated as read-only. It may not actually be read-only, but if it's not, then any changes should have no effect on this instance. The returned CloseableKVStore must be completely independent from this instance (subsequent changes to either one do not affect the other).

      The returned CloseableKVStore should be promply close()'d when no longer needed to release any underlying resources.

      Specified by:
      readOnlySnapshot in interface AtomicKVStore
      Returns:
      read-only, snapshot view of this instance
    • apply

      public void apply(Mutations mutations, boolean sync)
      Description copied from interface: AtomicKVStore
      Apply a set of mutations to this instance atomically.

      If this method returns normally, all of the given mutations will have been applied. If this method returns abnormally, then none of the given mutations will have been applied.

      In any case, other threads observing this instance will never see a partial application of the given mutations.

      This method is required to apply the mutations in this order: removes, puts, adjusts.

      If sync is true, the implementation must durably persist the changes before returning.

      Specified by:
      apply in interface AtomicKVStore
      Parameters:
      mutations - the mutations to apply
      sync - if true, caller requires that the changes be durably persisted
    • commitOrRollback

      protected void commitOrRollback()
      Commit outstanding changes, unless there is an exception when doing so, in which case rollback changes.
    • setBuilder

      public void setBuilder(org.h2.mvstore.MVStore.Builder builder)
      Configure the MVStore.Builder that will be used to construct the MVStore when start() is invoked.
      Parameters:
      builder - builder for the MVStore, or null to use a default builder
      Throws:
      IllegalStateException - if this instance is already start()ed
    • setBuilderConfig

      public void setBuilderConfig(String builderConfig)
      Configure the MVStore.Builder that will be used to construct the MVStore when start() is invoked using the specified configuration string.
      Parameters:
      builderConfig - MVStore.Builder configuration string, or null to use a default builder
      Throws:
      IllegalStateException - if this instance is already start()ed
      See Also:
      • MVStore.Builder.fromString(java.lang.String)
    • setMapName

      public void setMapName(String mapName)
      Configure the name of the MVMap to use.

      Default value is MVStoreKVImplementation.DEFAULT_MAP_NAME.

      Parameters:
      mapName - map name, or null to use MVStoreKVImplementation.DEFAULT_MAP_NAME
      Throws:
      IllegalStateException - if this instance is already start()ed
    • getMVStore

      public org.h2.mvstore.MVStore getMVStore()
      Get the underlying MVStore associated with this instance.
      Returns:
      the associated underlying MVStore
      Throws:
      IllegalStateException - if this instance is not start()ed
    • start

      @PostConstruct public void start()
      Start this instance.
    • stop

      @PreDestroy public void stop()
      Stop this instance.
    • finalize

      protected void finalize() throws Throwable
      Finalize this instance. Invokes stop() to close any unclosed iterators.
      Overrides:
      finalize in class Object
      Throws:
      Throwable
    • toString

      public String toString()
      Overrides:
      toString in class MVMapKVStore