Documentation
¶
Index ¶
- Constants
- func CheckGCWindow(now, rev WithTimestampRevision, gcWindow time.Duration) error
- func HLCKeyLessThanFunc(lhs, rhs HLCRevision) bool
- func TimestampIDKeyFunc(r TimestampRevision) int64
- func TimestampIDKeyLessThanFunc(l, r int64) bool
- func TransactionIDKeyFunc(r TransactionIDRevision) uint64
- func TransactionIDKeyLessThanFunc(l, r uint64) bool
- type CommonDecoder
- type HLCRevision
- func (hlc HLCRevision) AppendSortKey(dst []byte) []byte
- func (hlc HLCRevision) AsDecimal() (decimal.Decimal, error)
- func (hlc HLCRevision) ByteSortable() bool
- func (hlc HLCRevision) ConstructForTimestamp(timestamp int64) WithTimestampRevision
- func (hlc HLCRevision) Equal(rhs datastore.Revision) bool
- func (hlc HLCRevision) GreaterThan(rhs datastore.Revision) bool
- func (hlc HLCRevision) InexactFloat64() float64
- func (hlc HLCRevision) LessThan(rhs datastore.Revision) bool
- func (hlc HLCRevision) String() string
- func (hlc HLCRevision) TimestampNanoSec() int64
- type ParsingFunc
- type RevisionKind
- type TimestampRevision
- func (ir TimestampRevision) AppendSortKey(dst []byte) []byte
- func (ir TimestampRevision) ByteSortable() bool
- func (ir TimestampRevision) ConstructForTimestamp(timestamp int64) WithTimestampRevision
- func (ir TimestampRevision) Equal(rhs datastore.Revision) bool
- func (ir TimestampRevision) GreaterThan(rhs datastore.Revision) bool
- func (ir TimestampRevision) LessThan(rhs datastore.Revision) bool
- func (ir TimestampRevision) String() string
- func (ir TimestampRevision) Time() time.Time
- func (ir TimestampRevision) TimestampNanoSec() int64
- func (ir TimestampRevision) WithInexactFloat64() float64
- type TransactionIDRevision
- func (ir TransactionIDRevision) AppendSortKey(dst []byte) []byte
- func (ir TransactionIDRevision) ByteSortable() bool
- func (ir TransactionIDRevision) Equal(rhs datastore.Revision) bool
- func (ir TransactionIDRevision) GreaterThan(rhs datastore.Revision) bool
- func (ir TransactionIDRevision) LessThan(rhs datastore.Revision) bool
- func (ir TransactionIDRevision) String() string
- func (ir TransactionIDRevision) TransactionID() uint64
- func (ir TransactionIDRevision) WithInexactFloat64() float64
- type WithInexactFloat64
- type WithTimestampRevision
Constants ¶
const ( // Timestamp is a revision that is a timestamp. Timestamp RevisionKind = "timestamp" // TransactionID is a revision that is a transaction ID. TransactionID = "txid" // HybridLogicalClock is a revision that is a hybrid logical clock. HybridLogicalClock = "hlc" )
Variables ¶
This section is empty.
Functions ¶
func CheckGCWindow ¶ added in v1.57.0
func CheckGCWindow(now, rev WithTimestampRevision, gcWindow time.Duration) error
CheckGCWindow verifies that the given revision is within the datastore's software GC window relative to the current time: not so old that it has (likely) been garbage collected, and not from the future.
func HLCKeyLessThanFunc ¶
func HLCKeyLessThanFunc(lhs, rhs HLCRevision) bool
HLCKeyLessThanFunc is used to compare keys created by the HLCKeyFunc.
func TimestampIDKeyFunc ¶
func TimestampIDKeyFunc(r TimestampRevision) int64
TimestampIDKeyFunc is used to create keys for timestamps.
func TimestampIDKeyLessThanFunc ¶
TimestampIDKeyLessThanFunc is used to create keys for timestamps.
func TransactionIDKeyFunc ¶
func TransactionIDKeyFunc(r TransactionIDRevision) uint64
TransactionIDKeyFunc is used to create keys for transaction IDs.
func TransactionIDKeyLessThanFunc ¶
TransactionIDKeyLessThanFunc is used to create keys for transaction IDs.
Types ¶
type CommonDecoder ¶
type CommonDecoder struct {
Kind RevisionKind
DatastoreUniqueID string
}
CommonDecoder is a revision decoder that can decode revisions of a given kind.
func (CommonDecoder) RevisionFromString ¶
func (cd CommonDecoder) RevisionFromString(s string) (datastore.Revision, error)
type HLCRevision ¶
type HLCRevision struct {
// contains filtered or unexported fields
}
HLCRevision is a revision that is a hybrid logical clock, stored as two integers. The first integer is the timestamp in nanoseconds, and the second integer is the logical clock defined as 11 digits, with the first digit being ignored to ensure precision of the given logical clock.
func HLCKeyFunc ¶
func HLCKeyFunc(r HLCRevision) HLCRevision
HLCKeyFunc is used to convert a simple HLC for use in maps.
func HLCRevisionFromString ¶
func HLCRevisionFromString(revisionStr string) (HLCRevision, error)
HLCRevisionFromString parses a string into a hybrid logical clock revision.
func NewForHLC ¶
func NewForHLC(decimal decimal.Decimal) (HLCRevision, error)
NewForHLC creates a new revision for the given hybrid logical clock.
func NewHLCForTime ¶
func NewHLCForTime(time time.Time) HLCRevision
NewHLCForTime creates a new revision for the given time.
func (HLCRevision) AppendSortKey ¶ added in v1.57.0
func (hlc HLCRevision) AppendSortKey(dst []byte) []byte
AppendSortKey implements datastore.SortKeyRevision. Keys are hlcSortKeyLength bytes.
func (HLCRevision) AsDecimal ¶ added in v1.34.0
func (hlc HLCRevision) AsDecimal() (decimal.Decimal, error)
func (HLCRevision) ByteSortable ¶ added in v1.39.0
func (hlc HLCRevision) ByteSortable() bool
func (HLCRevision) ConstructForTimestamp ¶
func (hlc HLCRevision) ConstructForTimestamp(timestamp int64) WithTimestampRevision
func (HLCRevision) GreaterThan ¶
func (hlc HLCRevision) GreaterThan(rhs datastore.Revision) bool
func (HLCRevision) InexactFloat64 ¶
func (hlc HLCRevision) InexactFloat64() float64
func (HLCRevision) String ¶
func (hlc HLCRevision) String() string
func (HLCRevision) TimestampNanoSec ¶
func (hlc HLCRevision) TimestampNanoSec() int64
type ParsingFunc ¶
ParsingFunc is a function that can parse a string into a revision.
func RevisionParser ¶
func RevisionParser(kind RevisionKind) ParsingFunc
RevisionParser returns a ParsingFunc for the given RevisionKind.
type RevisionKind ¶
type RevisionKind string
RevisionKind is an enum of the different kinds of revisions that can be used.
type TimestampRevision ¶
type TimestampRevision int64
TimestampRevision is a revision that is a timestamp.
func NewForTime ¶
func NewForTime(time time.Time) TimestampRevision
NewForTime creates a new revision for the given time.
func NewForTimestamp ¶
func NewForTimestamp(timestampNanosec int64) TimestampRevision
NewForTimestamp creates a new revision for the given timestamp.
func (TimestampRevision) AppendSortKey ¶ added in v1.57.0
func (ir TimestampRevision) AppendSortKey(dst []byte) []byte
AppendSortKey implements datastore.SortKeyRevision. Keys are timestampSortKeyLength bytes.
func (TimestampRevision) ByteSortable ¶ added in v1.39.0
func (ir TimestampRevision) ByteSortable() bool
func (TimestampRevision) ConstructForTimestamp ¶
func (ir TimestampRevision) ConstructForTimestamp(timestamp int64) WithTimestampRevision
func (TimestampRevision) GreaterThan ¶
func (ir TimestampRevision) GreaterThan(rhs datastore.Revision) bool
func (TimestampRevision) LessThan ¶
func (ir TimestampRevision) LessThan(rhs datastore.Revision) bool
func (TimestampRevision) String ¶
func (ir TimestampRevision) String() string
func (TimestampRevision) Time ¶
func (ir TimestampRevision) Time() time.Time
func (TimestampRevision) TimestampNanoSec ¶
func (ir TimestampRevision) TimestampNanoSec() int64
func (TimestampRevision) WithInexactFloat64 ¶
func (ir TimestampRevision) WithInexactFloat64() float64
type TransactionIDRevision ¶
type TransactionIDRevision uint64
TransactionIDRevision is a revision that is a transaction ID.
func NewForTransactionID ¶
func NewForTransactionID(transactionID uint64) TransactionIDRevision
NewForTransactionID creates a new revision for the given transaction ID.
func (TransactionIDRevision) AppendSortKey ¶ added in v1.57.0
func (ir TransactionIDRevision) AppendSortKey(dst []byte) []byte
AppendSortKey implements datastore.SortKeyRevision. Keys are transactionIDSortKeyLength bytes.
func (TransactionIDRevision) ByteSortable ¶ added in v1.39.0
func (ir TransactionIDRevision) ByteSortable() bool
func (TransactionIDRevision) Equal ¶
func (ir TransactionIDRevision) Equal(rhs datastore.Revision) bool
func (TransactionIDRevision) GreaterThan ¶
func (ir TransactionIDRevision) GreaterThan(rhs datastore.Revision) bool
func (TransactionIDRevision) LessThan ¶
func (ir TransactionIDRevision) LessThan(rhs datastore.Revision) bool
func (TransactionIDRevision) String ¶
func (ir TransactionIDRevision) String() string
func (TransactionIDRevision) TransactionID ¶
func (ir TransactionIDRevision) TransactionID() uint64
func (TransactionIDRevision) WithInexactFloat64 ¶
func (ir TransactionIDRevision) WithInexactFloat64() float64
type WithInexactFloat64 ¶
type WithInexactFloat64 interface {
// InexactFloat64 returns a float64 that is an inexact representation of the
// revision.
InexactFloat64() float64
}
WithInexactFloat64 is an interface that can be implemented by a revision to provide an inexact float64 representation of the revision.
type WithTimestampRevision ¶
type WithTimestampRevision interface {
datastore.Revision
TimestampNanoSec() int64
ConstructForTimestamp(timestampNanoSec int64) WithTimestampRevision
}
WithTimestampRevision is an interface that can be implemented by a revision to provide a timestamp.
func Quantize ¶ added in v1.57.0
func Quantize(now WithTimestampRevision, followerReadDelay, quantization time.Duration) (WithTimestampRevision, time.Duration)
Quantize rounds a timestamp-based "now" revision down to a quantization boundary, after subtracting the follower-read delay, and reports how long the result remains valid: until the next boundary. A zero quantization returns the delayed now unchanged with no validity.
This is the in-Go quantization used by datastores whose revision is a clock reading (CockroachDB, Spanner, memdb). Datastores that quantize in SQL (Postgres, MySQL) compute validFor in their query and do not use this helper.