Class TimestampBound
Indicates how Spanner will choose a timestamp at which to read the data for read-only transactions.
Implements
Namespace: Google.Cloud.Spanner.Data
Assembly: Google.Cloud.Spanner.Data.dll
Syntax
public sealed class TimestampBound : IEquatable<TimestampBound>
Properties
Mode
Indicates how to choose the timestamp at which to read the data for Cloud Spanner read-only transactions. If your application can tolerate some staleness when reading data, you can use a stale read, which can execute much faster when compared to reading the latest data. The types of timestamp bounds are: Strong (the default): read the latest data. Bounded staleness: read a version of the data that's no staler than a bound. Exact staleness: read the version of the data at an exact timestamp.
Declaration
public TimestampBoundMode Mode { get; }
Property Value
Type | Description |
---|---|
TimestampBoundMode |
ReturnReadTimestamp
If true, the read timestamp is included in the
Google.Cloud.Spanner.V1.Transaction message that describes the transaction.
Declaration
public bool ReturnReadTimestamp { get; }
Property Value
Type | Description |
---|---|
bool |
Staleness
If Mode is ExactStaleness or MaxStaleness, this indicates the duration of time for the staleness.
Declaration
public TimeSpan Staleness { get; }
Property Value
Type | Description |
---|---|
TimeSpan |
Strong
Read at a timestamp where all previously committed transactions are visible.
Declaration
public static TimestampBound Strong { get; }
Property Value
Type | Description |
---|---|
TimestampBound |
Timestamp
If Mode is ReadTimestamp or MinReadTimestamp, this indicates the timestamp to use.
Declaration
public DateTime Timestamp { get; }
Property Value
Type | Description |
---|---|
DateTime |
Methods
FromBase64String(string)
Creates an instance of TimestampBound given its Base64 encoded string.
Declaration
public static TimestampBound FromBase64String(string base64String)
Parameters
Type | Name | Description |
---|---|---|
string | base64String | The string provided by ToBase64String(). |
Returns
Type | Description |
---|---|
TimestampBound | A new instance of TimestampBound. |
GetHashCode()
Serves as the default hash function.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int | A hash code for the current object. |
Overrides
OfExactStaleness(TimeSpan)
Executes all reads at a timestamp that is duration
old. The timestamp is chosen soon after the read is started.
Guarantees that all writes that have committed more than the specified number of seconds ago are visible. Because Cloud Spanner chooses the exact timestamp, this mode works even if the client's local clock is substantially skewed from Cloud Spanner commit timestamps.
Useful for reading at nearby replicas without the distributed timestamp negotiation overhead of OfMaxStaleness(TimeSpan).
Declaration
public static TimestampBound OfExactStaleness(TimeSpan duration)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | duration | The exact staleness to use. Must not be negative. |
Returns
Type | Description |
---|---|
TimestampBound | A created TimestampBound. |
OfMaxStaleness(TimeSpan)
Read data at a timestamp >= NOW - <code class="paramref">duration</code>
. Guarantees that all
writes that have committed more than the specified number of seconds ago are
visible.
Because Cloud Spanner chooses the exact timestamp, this mode works even if
the client's local clock is substantially skewed from Cloud Spanner
commit timestamps.
Useful for reading the freshest data available at a nearby replica, while bounding the possible staleness if the local replica has fallen behind.
Note that this option can only be used in single-use transactions.
Declaration
public static TimestampBound OfMaxStaleness(TimeSpan duration)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | duration | The maximum duration of staleness to use. Must not be negative. |
Returns
Type | Description |
---|---|
TimestampBound | A created TimestampBound. |
OfMinReadTimestamp(DateTime)
Executes all reads at a timestamp >= minReadTimestamp
.
This is useful for requesting fresher data than some previous read, or data that is fresh enough to observe the effects of some previously committed transaction whose timestamp is known.
Note that this option can only be used in single-use transactions
Declaration
public static TimestampBound OfMinReadTimestamp(DateTime minReadTimestamp)
Parameters
Type | Name | Description |
---|---|---|
DateTime | minReadTimestamp | The earliest timestamp to read from. Must be in UTC. |
Returns
Type | Description |
---|---|
TimestampBound | A created TimestampBound. |
OfReadTimestamp(DateTime)
Executes all reads at the given timestamp. Unlike other modes, reads at a specific timestamp are repeatable; the same read at the same timestamp always returns the same data. If the timestamp is in the future, the read will block until the specified timestamp, modulo the read's deadline.
Useful for large scale consistent reads such as mapreduces, or for coordinating many reads against a consistent snapshot of the data.
Declaration
public static TimestampBound OfReadTimestamp(DateTime timestamp)
Parameters
Type | Name | Description |
---|---|---|
DateTime | timestamp | The timestamp to read from. Must be in UTC. |
Returns
Type | Description |
---|---|
TimestampBound | A created TimestampBound. |
ToBase64String()
Returns a Base64 encoded string that can later be serialized back into a TimestampBound using FromBase64String(string)
Declaration
public string ToBase64String()
Returns
Type | Description |
---|---|
string | The base64 encoded string. |
WithReturnReadTimestamp(bool)
Creates a TimestampBound with the given value on whether to return a read timestamp.
Declaration
public TimestampBound WithReturnReadTimestamp(bool returnReadTimestamp)
Parameters
Type | Name | Description |
---|---|---|
bool | returnReadTimestamp | Whether to return a read timestamp. |
Returns
Type | Description |
---|---|
TimestampBound | A created TimestampBound. |