luci: go.chromium.org/luci/resultdb/internal/span Index | Files

package span

import "go.chromium.org/luci/resultdb/internal/span"

Package span contains utility functions to interact with the underlying Spanner storage. It does not attempt to encapsulate Spanner.

Index

Package Files

client.go doc.go hash.go inclusion.go invocation.go tag.go test_exoneration.go test_result.go util.go

Constants

const InvocationShards = 100

InvocationShards is the sharding level for the Invocations table. Column Invocations.ShardId is a value in range [0, InvocationShards).

Variables

var TooManyInvocationsTag = errors.BoolTag{
    Key: errors.NewTagKey("too many matching invocations matched the condition"),
}

TooManyInvocationsTag set in an error indicates that too many invocations matched a condition.

func Client Uses

func Client(ctx context.Context) *spanner.Client

Client retrieves the current spanner client from the context.

func FromMicros Uses

func FromMicros(micros int64) *durpb.Duration

FromMicros converts microseconds to a duration.Duration proto.

func FromSpanner Uses

func FromSpanner(row *spanner.Row, ptrs ...interface{}) error

FromSpanner reads values from row to ptrs, converting types from Spanner to Go along the way. Supported types:

- string
- tspb.Timestamp
- pb.InvocationState
- pb.TestStatus
- pb.Artifact
- typepb.Variant
- typepb.StringPair

func InclusionKey Uses

func InclusionKey(including, included InvocationID) spanner.Key

InclusionKey returns a spanner key for an Inclusion row.

func InsertMap Uses

func InsertMap(table string, in map[string]interface{}) *spanner.Mutation

InsertMap is a shortcut for spanner.InsertMap with ToSpannerMap applied to in.

func QueryInvocations Uses

func QueryInvocations(ctx context.Context, txn *spanner.ReadOnlyTransaction, pred *pb.InvocationPredicate, limit int) (map[InvocationID]*pb.Invocation, error)

QueryInvocations returns a list of invocation IDs that satisfy the predicate. The limit must be positive. If the number of matching invocations exceeds the limit, returns an error tagged with TooManyInvocationsTag. Assumes pred is valid. Does not support paging.

func ReadInvocation Uses

func ReadInvocation(ctx context.Context, txn Txn, id InvocationID, ptrMap map[string]interface{}) error

ReadInvocation reads one invocation from Spanner. If the invocation does not exist, the returned error is annotated with NotFound GRPC code. For ptrMap see ReadRow comment in util.go.

func ReadInvocationFull Uses

func ReadInvocationFull(ctx context.Context, txn Txn, id InvocationID) (*pb.Invocation, error)

ReadInvocationFull reads one invocation struct from Spanner. If the invocation does not exist, the returned error is annotated with NotFound GRPC code.

func ReadInvocationsByTag Uses

func ReadInvocationsByTag(ctx context.Context, txn Txn, tag *typepb.StringPair, limit int) (map[InvocationID]*pb.Invocation, error)

ReadInvocationsByTag fetches invocations that have the tag. If limit > 0 and there are more than limit matching invocations, returns an error with TooManyInvocationsTag tag.

func ReadReachableInvocations Uses

func ReadReachableInvocations(ctx context.Context, txn *spanner.ReadOnlyTransaction, limit int, roots map[InvocationID]*pb.Invocation) (map[InvocationID]*pb.Invocation, error)

ReadReachableInvocations fetches all invocations reachable from the roots. If the returned error is non-nil, it is annotated with a gRPC code.

limit must be positive. If the number of matching invocations exceeds limit, returns an error tagged with TooManyInvocationsTag.

Does not re-fetch roots.

func ReadRow Uses

func ReadRow(ctx context.Context, txn Txn, table string, key spanner.Key, ptrMap map[string]interface{}) error

ReadRow reads a single row from the database and reads its values. ptrMap must map from column names to pointers where the values will be written.

func ReadTestExonerationFull Uses

func ReadTestExonerationFull(ctx context.Context, txn Txn, name string) (*pb.TestExoneration, error)

ReadTestExonerationFull reads a test exoneration from Spanner. If it does not exist, the returned error is annotated with NotFound GRPC code.

func ReadTestExonerations Uses

func ReadTestExonerations(ctx context.Context, txn Txn, invID InvocationID, cursorTok string, pageSize int) (tes []*pb.TestExoneration, nextCursorTok string, err error)

ReadTestExonerations reads all test exonerations from the invocation.

func ReadTestResult Uses

func ReadTestResult(ctx context.Context, txn Txn, name string) (*pb.TestResult, error)

ReadTestResult reads specified TestResult within the transaction. If the TestResult does not exist, the returned error is annotated with NotFound GRPC code.

func ReadTestResults Uses

func ReadTestResults(ctx context.Context, txn Txn, invID InvocationID, includeExpected bool, cursorTok string, pageSize int) (trs []*pb.TestResult, nextCursorTok string, err error)

ReadTestResults reads the specified test results, if any, of an invocation within the transaction. pageSize must be positive.

func ReadWriteTransaction Uses

func ReadWriteTransaction(ctx context.Context, f func(context.Context, *spanner.ReadWriteTransaction) error) (commitTimestamp time.Time, err error)

ReadWriteTransaction calls Client(ctx).ReadWriteTransaction and unwraps a "transaction is aborted" errors such that the spanner client properly retries the function.

func SortInvocationIDs Uses

func SortInvocationIDs(ids []InvocationID)

SortInvocationIDs sorts ids lexicographically.

func TagRowID Uses

func TagRowID(tag *typepb.StringPair) string

TagRowID returns a value for the TagId column in InvocationsByTag table.

func ToMicros Uses

func ToMicros(d *durpb.Duration) int64

ToMicros converts a duration.Duration proto to microseconds.

func ToSpanner Uses

func ToSpanner(v interface{}) interface{}

ToSpanner converts values from Go types to Spanner types. In addition to supported types in FromSpanner, also supports []interface{} and map[string]interface{}.

func ToSpannerMap Uses

func ToSpannerMap(values map[string]interface{}) map[string]interface{}

ToSpannerMap converts a map of Go values to a map of Spanner values. See also ToSpanner.

func ToSpannerSlice Uses

func ToSpannerSlice(values ...interface{}) []interface{}

ToSpannerSlice converts a slice of Go values to a slice of Spanner values. See also ToSpanner.

func UpdateMap Uses

func UpdateMap(table string, in map[string]interface{}) *spanner.Mutation

UpdateMap is a shortcut for spanner.UpdateMap with ToSpannerMap applied to in.

func WithClient Uses

func WithClient(ctx context.Context, client *spanner.Client) context.Context

WithClient returns a context with the client embedded.

type InvocationID Uses

type InvocationID string

InvocationID can convert an invocation id to various formats.

func InvocationIDFromRowID Uses

func InvocationIDFromRowID(rowID string) InvocationID

InvocationIDFromRowID converts a Spanner-level row ID to an InvocationID.

func MustParseInvocationName Uses

func MustParseInvocationName(name string) InvocationID

MustParseInvocationName converts an invocation name to an InvocationID. Panics if the name is invalid. Useful for situations when name was already validated.

func MustParseTestExonerationName Uses

func MustParseTestExonerationName(name string) (invID InvocationID, testPath, exonerationID string)

MustParseTestExonerationName extracts invocation, test path and exoneration IDs from the name. Panics on failure.

func MustParseTestResultName Uses

func MustParseTestResultName(name string) (invID InvocationID, testPath, resultID string)

MustParseTestResultName retrieves the invocation ID, unescaped test path, and result ID. Panics if the name is invalid. Useful for situations when name was already validated.

func ReadIncludedInvocations Uses

func ReadIncludedInvocations(ctx context.Context, txn Txn, id InvocationID) ([]InvocationID, error)

ReadIncludedInvocations reads ids of included invocations.

func (InvocationID) Key Uses

func (id InvocationID) Key(suffix ...interface{}) spanner.Key

Key returns a invocation spanner key.

func (InvocationID) Name Uses

func (id InvocationID) Name() string

Name returns an invocation name.

func (InvocationID) RowID Uses

func (id InvocationID) RowID() string

RowID returns an invocation ID used in spanner rows.

type Txn Uses

type Txn interface {
    // ReadRow reads a single row from the database.
    ReadRow(ctx context.Context, table string, key spanner.Key, columns []string) (*spanner.Row, error)

    // Read reads multiple rows from the database.
    Read(ctx context.Context, table string, key spanner.KeySet, columns []string) *spanner.RowIterator

    // ReadOptions reads multiple rows from the database, and allows customizing
    // options.
    ReadWithOptions(ctx context.Context, table string, keys spanner.KeySet, columns []string, opts *spanner.ReadOptions) (ri *spanner.RowIterator)

    // Query reads multiple rows returned by SQL statement.
    Query(ctx context.Context, statement spanner.Statement) *spanner.RowIterator
}

Txn is implemented by all spanner transactions.

Package span imports 20 packages (graph) and is imported by 6 packages. Updated 2019-11-15. Refresh now. Tools for package owners.