Class ReadWriteSpannerView

All Implemented Interfaces:
CloseableKVStore, KVStore, DeltaKVStore, Closeable, AutoCloseable, Cloneable

public class ReadWriteSpannerView extends MutableView implements CloseableKVStore
Provides a mutable KVStore view of a ReadContext.

For best performance, supply an ExecutorService for asynchronous batch loading.

Use bufferMutations() to transfer outstanding mutations into a TransactionContext.

See Also:
  • Field Details

    • log

      protected final Logger log
    • tableName

      protected final String tableName
    • exceptionMapper

      protected final Function<? super com.google.cloud.spanner.SpannerException,RuntimeException> exceptionMapper
  • Constructor Details

    • ReadWriteSpannerView

      public ReadWriteSpannerView(String tableName, com.google.cloud.spanner.ReadContext context, Function<? super com.google.cloud.spanner.SpannerException,RuntimeException> exceptionMapper)
      Constructor for when no batching is desired.
      Parameters:
      tableName - name of the Spanner database table
      context - read context
      exceptionMapper - mapper for any thrown SpannerExceptions, or null for none
      Throws:
      IllegalArgumentException - if tableName or context is null
    • ReadWriteSpannerView

      public ReadWriteSpannerView(String tableName, com.google.cloud.spanner.ReadContext context, Function<? super com.google.cloud.spanner.SpannerException,RuntimeException> exceptionMapper, ExecutorService executor, long rttEstimate)
      Constructor for when batching is desired.
      Parameters:
      tableName - name of the Spanner database table
      context - read context
      exceptionMapper - mapper for any thrown SpannerExceptions, or null for none
      executor - asynchronous load task executor
      rttEstimate - initial RTT estimate in nanoseconds
      Throws:
      IllegalArgumentException - if tableName, context or executor is null
      IllegalArgumentException - if rttEstimate is negative
  • Method Details

    • getRttEstimate

      public double getRttEstimate()
      Get the current RTT estimate.
      Returns:
      current RTT estimate in nanoseconds
    • bufferMutations

      public void bufferMutations(com.google.cloud.spanner.TransactionContext context)
      Atomically transfer all of the outstanding mutations associated with this instance into the given transaction context, and then clear them.
      Parameters:
      context - transaction context
      Throws:
      IllegalArgumentException - if context is null
    • clone

      public ReadWriteSpannerView clone()
      Description copied from class: MutableView
      Clone this instance.

      The clone will have the same underlying KVStore, but its own Reads and Writes, which will themselves be cloned from this instance's copies.

      Overrides:
      clone in class MutableView
      Returns:
      clone of this instance
    • close

      public void close()
      Close the associated ReadContext.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface CloseableKVStore