Package io.permazen.kv.spanner
Class ReadWriteSpannerView
java.lang.Object
io.permazen.kv.AbstractKVStore
io.permazen.kv.mvcc.MutableView
io.permazen.kv.spanner.ReadWriteSpannerView
- All Implemented Interfaces:
CloseableKVStore
,KVStore
,DeltaKVStore
,Closeable
,AutoCloseable
,Cloneable
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 Summary
Modifier and TypeFieldDescriptionprotected final Function<? super com.google.cloud.spanner.SpannerException,
RuntimeException> protected final Logger
protected final String
-
Constructor Summary
ConstructorDescriptionReadWriteSpannerView
(String tableName, com.google.cloud.spanner.ReadContext context, Function<? super com.google.cloud.spanner.SpannerException, RuntimeException> exceptionMapper) Constructor for when no batching is desired.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. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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.clone()
Clone this instance.void
close()
Close the associatedReadContext
.double
Get the current RTT estimate.Methods inherited from class io.permazen.kv.mvcc.MutableView
adjustCounter, apply, decodeCounter, disableReadTracking, encodeCounter, get, getBaseKVStore, getRange, getReads, getWrites, isReadOnly, put, remove, removeRange, setKVStore, setReadOnly, toString, withoutReadTracking
Methods inherited from class io.permazen.kv.AbstractKVStore
getAtLeast, getAtMost
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface io.permazen.kv.KVStore
adjustCounter, apply, decodeCounter, encodeCounter, get, getAtLeast, getAtMost, getRange, getRange, getRange, put, remove, removeRange, removeRange
-
Field Details
-
log
-
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 tablecontext
- read contextexceptionMapper
- mapper for any thrownSpannerException
s, or null for none- Throws:
IllegalArgumentException
- iftableName
orcontext
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 tablecontext
- read contextexceptionMapper
- mapper for any thrownSpannerException
s, or null for noneexecutor
- asynchronous load task executorrttEstimate
- initial RTT estimate in nanoseconds- Throws:
IllegalArgumentException
- iftableName
,context
orexecutor
is nullIllegalArgumentException
- ifrttEstimate
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
- ifcontext
is null
-
clone
Description copied from class:MutableView
Clone this instance.The clone will have the same underlying
KVStore
, but its ownReads
andWrites
, which will themselves be cloned from this instance's copies.- Overrides:
clone
in classMutableView
- Returns:
- clone of this instance
-
close
public void close()Close the associatedReadContext
.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceCloseableKVStore
-