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

artifact.go client.go doc.go inclusion.go invocation.go invocationid.go metrics.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 ArtifactParentID Uses

func ArtifactParentID(testID, resultID string) string

ArtifactParentID returns a value for Artifacts.ParentId Spanner column.

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

func IncRowCount(ctx context.Context, count int, table Table, rowStatus RowStatus)

IncRowCount increments the row counter.

func InclusionKey Uses

func InclusionKey(including, included InvocationID) spanner.Key

InclusionKey returns a spanner key for an Inclusion row.

func IncrementTestResultCount Uses

func IncrementTestResultCount(ctx context.Context, txn *spanner.ReadWriteTransaction, id InvocationID, delta int64) error

IncrementTestResultCount increases the TestResultCount of the invocation.

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

func ParseArtifactParentID(parentID string) (testID, resultID string, err error)

ParseArtifactParentID parses parentID into testID and resultID. If the artifact's parent is invocation, then testID and resultID are "".

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

func ReadArtifact(ctx context.Context, txn Txn, name string) (*pb.Artifact, error)

ReadArtifact reads an artifact from Spanner. If it does not exist, the returned error is annotated with NotFound GRPC code. Does not return artifact content or its location.

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

func ReadTestResultCount(ctx context.Context, txn Txn, ids InvocationIDSet) (int64, error)

ReadTestResultCount returns the total number of test results of requested invocations.

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

type ArtifactQuery struct {
    InvocationIDs       InvocationIDSet
    ParentIDRegexp      string
    FollowEdges         *pb.QueryArtifactsRequest_EdgeTypeSet
    TestResultPredicate *pb.TestResultPredicate
    PageSize            int // must be positive
    PageToken           string
}

ArtifactQuery specifies artifacts to fetch.

func (*ArtifactQuery) Fetch Uses

func (q *ArtifactQuery) Fetch(ctx context.Context, txn Txn) (arts []*pb.Artifact, nextPageToken string, err error)

Fetch returns a page of artifacts matching q.

Returned artifacts are ordered by level (invocation or test result). Test result artifacts are sorted by parent invocation ID, test ID and artifact ID.

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

func MustParseArtifactName(name string) (invID InvocationID, testID, resultID, artifactID string)

MustParseArtifactName extracts invocation, test, result and artifactIDs. Test and result IDs are "" if this is a invocation-level artifact. Panics on failure.

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

type RowStatus string

RowStatus is a status of a row. Used in metrics.

const (
    Inserted RowStatus = "INSERTED"
    Deleted  RowStatus = "DELETED"
)

Values of RowStatus type.

type Table Uses

type Table string

Table identifies a Spanner table. Used in metrics.

const (
    TestResults Table = "TestResults"
    Invocations Table = "Invocations"
)

Values of Table type.

type TestExonerationQuery Uses

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

TestExonerationQuery specifies test exonerations to fetch.

func (*TestExonerationQuery) Fetch Uses

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

Fetch returns a page test of exonerations matching the query. Returned test exonerations are ordered by invocation ID, test ID and exoneration ID.

type TestResultQuery Uses

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

TestResultQuery specifies test results to fetch.

func (*TestResultQuery) Fetch Uses

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

Fetch returns a page of test results matching q. Returned test results are ordered by parent invocation ID, test ID and result ID.

func (*TestResultQuery) Run Uses

func (q *TestResultQuery) Run(ctx context.Context, txn *spanner.ReadOnlyTransaction, f func(TestResultQueryItem) error) error

Run calls f for test results matching the query. The test results are ordered by parent invocation ID, test ID and result ID.

type TestResultQueryItem Uses

type TestResultQueryItem struct {
    *pb.TestResult
    VariantHash string
}

TestResultQueryItem is one element returned by a TestResultQuery.

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 33 packages (graph) and is imported by 12 packages. Updated 2020-05-28. Refresh now. Tools for package owners.