Google.Cloud.Spanner.Data - Class TimestampBound (5.0.0-beta03)

public sealed class TimestampBound : IEquatable<TimestampBound>

Reference documentation and code samples for the Google.Cloud.Spanner.Data class 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
Type Description
TimestampBoundMode

ReturnReadTimestamp

public bool ReturnReadTimestamp { get; }

If true, the read timestamp is included in the Google.Cloud.Spanner.V1.Transaction message that describes the transaction.

Property Value
Type Description
bool

Staleness

public TimeSpan Staleness { get; }

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

Property Value
Type Description
TimeSpan

Strong

public static TimestampBound Strong { get; }

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

Property Value
Type Description
TimestampBound

Timestamp

public DateTime Timestamp { get; }

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

Property Value
Type Description
DateTime

Methods

FromBase64String(string)

public static TimestampBound FromBase64String(string base64String)

Creates an instance of TimestampBound given its Base64 encoded string.

Parameter
Name Description
base64String string

The string provided by ToBase64String().

Returns
Type Description
TimestampBound

A new instance of TimestampBound.

GetHashCode()

public override int GetHashCode()

Serves as the default hash function.

Returns
Type Description
int

A hash code for the current object.

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
Name Description
duration TimeSpan

The exact staleness to use. Must not be negative.

Returns
Type Description
TimestampBound

A created TimestampBound.

OfMaxStaleness(TimeSpan)

public static TimestampBound OfMaxStaleness(TimeSpan duration)

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.

Parameter
Name Description
duration TimeSpan

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

Returns
Type Description
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
Name Description
minReadTimestamp DateTime

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

Returns
Type Description
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
Name Description
timestamp DateTime

The timestamp to read from. Must be in UTC.

Returns
Type Description
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
Type Description
string

The base64 encoded string.

WithReturnReadTimestamp(bool)

public TimestampBound WithReturnReadTimestamp(bool returnReadTimestamp)

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

Parameter
Name Description
returnReadTimestamp bool

Whether to return a read timestamp.

Returns
Type Description
TimestampBound

A created TimestampBound.