Class TimestampBound (3.10.0)

public sealed class TimestampBound : IEquatable<TimestampBound>

Indicates how Spanner will choose a timestamp at which to read the data for read-only transactions.

Inheritance

Object > TimestampBound

Namespace

Google.Cloud.Spanner.Data

Assembly

Google.Cloud.Spanner.Data.dll

Properties

Mode

public TimestampBoundMode Mode { get; }

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.

Property Value
TypeDescription
TimestampBoundMode

ReturnReadTimestamp

public bool ReturnReadTimestamp { get; }

If true, the read timestamp is included in the Transaction message that describes the transaction.

Property Value
TypeDescription
Boolean

Staleness

public TimeSpan Staleness { get; }

If Mode is ExactStaleness or MaxStaleness, this indicates the duration of time for the staleness.

Property Value
TypeDescription
TimeSpan

Strong

public static TimestampBound Strong { get; }

Read at a timestamp where all previously committed transactions are visible.

Property Value
TypeDescription
TimestampBound

Timestamp

public DateTime Timestamp { get; }

If Mode is ReadTimestamp or MinReadTimestamp, this indicates the timestamp to use.

Property Value
TypeDescription
DateTime

Methods

FromBase64String(String)

public static TimestampBound FromBase64String(string base64String)

Creates an instance of TimestampBound given its Base64 encoded string.

Parameter
NameDescription
base64StringString

The string provided by ToBase64String().

Returns
TypeDescription
TimestampBound

A new instance of TimestampBound.

GetHashCode()

public override int GetHashCode()
Returns
TypeDescription
Int32
Overrides

OfExactStaleness(TimeSpan)

public static TimestampBound OfExactStaleness(TimeSpan duration)

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).

Parameter
NameDescription
durationTimeSpan

The exact staleness to use. Must not be negative.

Returns
TypeDescription
TimestampBound

A created TimestampBound.

OfMaxStaleness(TimeSpan)

public static TimestampBound OfMaxStaleness(TimeSpan duration)

Read data at a timestamp >= NOW - <code data-dev-comment-type="paramref" 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.

Parameter
NameDescription
durationTimeSpan

The maximum duration of staleness to use. Must not be negative.

Returns
TypeDescription
TimestampBound

A created TimestampBound.

OfMinReadTimestamp(DateTime)

public static TimestampBound OfMinReadTimestamp(DateTime minReadTimestamp)

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

Parameter
NameDescription
minReadTimestampDateTime

The earliest timestamp to read from. Must be in UTC.

Returns
TypeDescription
TimestampBound

A created TimestampBound.

OfReadTimestamp(DateTime)

public static TimestampBound OfReadTimestamp(DateTime timestamp)

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.

Parameter
NameDescription
timestampDateTime

The timestamp to read from. Must be in UTC.

Returns
TypeDescription
TimestampBound

A created TimestampBound.

ToBase64String()

public string ToBase64String()

Returns a Base64 encoded string that can later be serialized back into a TimestampBound using FromBase64String(String)

Returns
TypeDescription
String

The base64 encoded string.

WithReturnReadTimestamp(Boolean)

public TimestampBound WithReturnReadTimestamp(bool returnReadTimestamp)

Creates a TimestampBound with the given value on whether to return a read timestamp.

Parameter
NameDescription
returnReadTimestampBoolean

Whether to return a read timestamp.

Returns
TypeDescription
TimestampBound

A created TimestampBound.