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

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 inclusion.go invocation.go invocationid.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 ErrNoResults = iterator.Done

ErrNoResults is an error returned when a query unexpectedly has no results.

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 CurrentMaxShard Uses

func CurrentMaxShard(ctx context.Context) (int, error)

CurrentMaxShard reads the highest shard id in the Invocations table. This may differ from the constant above when it has changed recently.

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 is a shortcut for (&Buffer{}).FromSpanner. Appropriate when FromSpanner is called only once, whereas Buffer is reusable throughout function.

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 InsertOrUpdateMap Uses

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

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

func Query Uses

func Query(ctx context.Context, txn Txn, st spanner.Statement, fn func(row *spanner.Row) error) error

Query executes a query. Ensures st.Params are Spanner-compatible by modifying st.Params in place.

func QueryFirstRow Uses

func QueryFirstRow(ctx context.Context, txn Txn, st spanner.Statement, ptrs ...interface{}) error

QueryFirstRow executes a query, reads the first row into ptrs and stops the iterator. Returns ErrNoResults if the query does not return at least one row.

func QueryTestExonerations Uses

func QueryTestExonerations(ctx context.Context, txn *spanner.ReadOnlyTransaction, q TestExonerationQuery) (tes []*pb.TestExoneration, nextPageToken string, err error)

QueryTestExonerations reads test exonerations matching the predicate. Returned test exonerations from the same invocation are contiguous.

func QueryTestResults Uses

func QueryTestResults(ctx context.Context, txn *spanner.ReadOnlyTransaction, q TestResultQuery) (trs []*pb.TestResult, nextPageToken string, err error)

QueryTestResults reads test results matching the predicate. Returned test results from the same invocation are contiguous.

func QueryTestResultsStreaming Uses

func QueryTestResultsStreaming(ctx context.Context, txn *spanner.ReadOnlyTransaction, q TestResultQuery, f func(tr *pb.TestResult, variantHash string) error) error

QueryTestResultsStreaming is like QueryTestResults, but returns calls fn instead of returning a slice.

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 from Spanner. If the invocation does not exist, the returned error is annotated with NotFound GRPC code.

func ReadInvocationFullWithUpdateToken Uses

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

ReadInvocationFullWithUpdateToken reads one invocation and it's updateToken from Spanner. If the invocation does not exist, the returned error is annotated with NotFound GRPC code.

func ReadInvocationRealm Uses

func ReadInvocationRealm(ctx context.Context, txn Txn, id InvocationID) (string, error)

ReadInvocationRealm returns the invocation's realm.

func ReadInvocationState Uses

func ReadInvocationState(ctx context.Context, txn Txn, id InvocationID) (pb.Invocation_State, error)

ReadInvocationState returns the invocation's state.

func ReadInvocationStates Uses

func ReadInvocationStates(ctx context.Context, txn Txn, ids InvocationIDSet) (map[InvocationID]pb.Invocation_State, error)

ReadInvocationStates reads the states of invocations.

func ReadInvocationsFull Uses

func ReadInvocationsFull(ctx context.Context, txn Txn, ids InvocationIDSet) (map[InvocationID]*pb.Invocation, error)

ReadInvocationsFull returns multiple invocations. If any of them are not found, returns an error.

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 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 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 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 Buffer Uses

type Buffer struct {
    // contains filtered or unexported fields
}

Buffer can convert a value from a Spanner type to a Go type. Supported types:

- string
- InvocationID
- InvocationIDSet
- tspb.Timestamp
- pb.InvocationState
- pb.TestStatus
- pb.Artifact
- typepb.Variant
- typepb.StringPair
- Compressed
- CompressedProto
- proto.Message

func (*Buffer) FromSpanner Uses

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

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

type Compressed Uses

type Compressed []byte

Compressed instructs ToSpanner and FromSpanner functions to compress the content with https://godoc.org/github.com/klauspost/compress/zstd encoding.

type CompressedProto Uses

type CompressedProto struct{ Message proto.Message }

CompressedProto is like Compressed, but for protobuf messages.

Although not strictly necessary, FromSpanner expects a *CompressedProto, for consistency.

Note that `type CompressedProto proto.Message` and `type CompressedProto interface{proto.Message}` do not work well with type-switches.

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, testID, exonerationID string)

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

func MustParseTestResultName Uses

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

MustParseTestResultName retrieves the invocation ID, unescaped test id, and result ID.

Panics if the name is invalid. Should be used only with trusted data.

MustParseTestResultName is faster than pbutil.ParseTestResultName.

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. If id is empty, returns "".

type InvocationIDSet Uses

type InvocationIDSet map[InvocationID]struct{}

InvocationIDSet is an unordered set of invocation ids.

func MustParseInvocationNames Uses

func MustParseInvocationNames(names []string) InvocationIDSet

MustParseInvocationNames converts invocation names to InvocationIDSet. Panics if a name is invalid. Useful for situations when names were already validated.

func NewInvocationIDSet Uses

func NewInvocationIDSet(ids ...InvocationID) InvocationIDSet

NewInvocationIDSet creates an InvocationIDSet from members.

func ReadIncludedInvocations Uses

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

ReadIncludedInvocations reads ids of included invocations.

func ReadReachableInvocations Uses

func ReadReachableInvocations(ctx context.Context, txn Txn, limit int, roots InvocationIDSet) (reachable InvocationIDSet, err error)

ReadReachableInvocations returns a transitive closure of roots. If the returned error is non-nil, it is annotated with a gRPC code.

limit must be positive. If the size of the transitive closure exceeds the limit, returns an error tagged with TooManyInvocationsTag.

func (InvocationIDSet) Add Uses

func (s InvocationIDSet) Add(id InvocationID)

Add adds id to the set.

func (InvocationIDSet) Has Uses

func (s InvocationIDSet) Has(id InvocationID) bool

Has returns true if id is in the set.

func (InvocationIDSet) Keys Uses

func (s InvocationIDSet) Keys(suffix ...interface{}) spanner.KeySet

Keys returns a spanner.KeySet.

func (InvocationIDSet) Names Uses

func (s InvocationIDSet) Names() []string

Names returns a sorted slice of invocation names.

func (InvocationIDSet) Remove Uses

func (s InvocationIDSet) Remove(id InvocationID)

Remove removes id from the set if it was present.

func (InvocationIDSet) String Uses

func (s InvocationIDSet) String() string

String implements fmt.Stringer.

type TestExonerationQuery Uses

type TestExonerationQuery struct {
    InvocationIDs InvocationIDSet
    Predicate     *pb.TestExonerationPredicate // Predicate.Invocation must be nil.
    PageSize      int                          // must be positive
    PageToken     string
}

TestExonerationQuery specifies test exonerations to fetch.

type TestResultQuery Uses

type TestResultQuery struct {
    InvocationIDs     InvocationIDSet
    Predicate         *pb.TestResultPredicate // Predicate.Invocation must be nil.
    PageSize          int                     // must be positive
    PageToken         string
    SelectVariantHash bool
    ExcludeArtifacts  bool
}

TestResultQuery specifies test results to fetch.

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.

Directories

PathSynopsis
spantestPackage spantest contains tests for package span.

Package span imports 29 packages (graph) and is imported by 6 packages. Updated 2020-02-27. Refresh now. Tools for package owners.