datastore

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const Ellipsis = "..."

Ellipsis is a special relation that is assumed to be valid on the right hand side of a tuple.

Variables

This section is empty.

Functions

func BuildFinalizerFunction

func BuildFinalizerFunction() func(iter *sliceTupleIterator)

BuildFinalizerFunction creates a function which can be used as a finalizer to make sure that tuples are getting closed before they are garbage collected.

func NewInvalidRevisionErr

func NewInvalidRevisionErr(revision Revision, reason InvalidRevisionReason) error

NewInvalidRevisionErr constructs a new invalid revision error.

func NewNamespaceNotFoundErr

func NewNamespaceNotFoundErr(nsName string) error

NewNamespaceNotFoundErr constructs a new namespace not found error.

func NewPreconditionFailedErr

func NewPreconditionFailedErr(precondition *v1.Precondition) error

NewPreconditionFailedErr constructs a new precondition failed error.

func NewReadonlyErr

func NewReadonlyErr() error

func NewWatchCanceledErr

func NewWatchCanceledErr() error

NewWatchCanceledErr constructs a new watch was canceled error.

func NewWatchDisconnectedErr

func NewWatchDisconnectedErr() error

NewWatchDisconnectedErr constructs a new watch was disconnected error.

func SeparateContextWithTracing

func SeparateContextWithTracing(ctx context.Context) context.Context

SeparateContextWithTracing is a utility method which allows for severing the context between grpc and the datastore to prevent context cancellation from killing database connections that should otherwise go back to the connection pool.

Types

type CommonTupleQuery

type CommonTupleQuery interface {
	// Execute runs the tuple query and returns a result iterator.
	Execute(ctx context.Context) (TupleIterator, error)

	// Limit sets a limit on the query.
	Limit(limit uint64) CommonTupleQuery
}

CommonTupleQuery is the common interface shared between TupleQuery and ReverseTupleQuery.

type Datastore

type Datastore interface {
	GraphDatastore

	// WriteTuples takes a list of existing tuples that must exist, and a list of
	// tuple mutations and applies it to the datastore for the specified
	// namespace.
	WriteTuples(ctx context.Context, preconditions []*v1.Precondition, mutations []*v1.RelationshipUpdate) (Revision, error)

	// DeleteRelationships deletes all Relationships that match the provided
	// filter if all preconditions are met.
	DeleteRelationships(ctx context.Context, preconditions []*v1.Precondition, filter *v1.RelationshipFilter) (Revision, error)

	// Revision gets the currently replicated revision for this datastore.
	Revision(ctx context.Context) (Revision, error)

	// SyncRevision gets a revision that is guaranteed to be at least as fresh as
	// right now.
	SyncRevision(ctx context.Context) (Revision, error)

	// Watch notifies the caller about all changes to tuples.
	//
	// All events following afterRevision will be sent to the caller.
	Watch(ctx context.Context, afterRevision Revision) (<-chan *RevisionChanges, <-chan error)

	// WriteNamespace takes a proto namespace definition and persists it,
	// returning the version of the namespace that was created.
	WriteNamespace(ctx context.Context, newConfig *v0.NamespaceDefinition) (Revision, error)

	// ReadNamespace reads a namespace definition and version and returns it if
	// found.
	ReadNamespace(ctx context.Context, nsName string) (*v0.NamespaceDefinition, Revision, error)

	// DeleteNamespace deletes a namespace and any associated tuples.
	DeleteNamespace(ctx context.Context, nsName string) (Revision, error)

	// ListNamespaces lists all namespaces defined.
	ListNamespaces(ctx context.Context) ([]*v0.NamespaceDefinition, error)

	// IsReady returns whether the datastore is ready to accept data. Datastores that require
	// database schema creation will return false until the migrations have been run to create
	// the necessary tables.
	IsReady(ctx context.Context) (bool, error)
}

Datastore represents tuple access for a single namespace.

type ErrInvalidRevision

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

ErrInvalidRevision occurs when a revision specified to a call was invalid.

func (ErrInvalidRevision) InvalidRevision

func (eri ErrInvalidRevision) InvalidRevision() Revision

InvalidRevision is the revision that failed.

func (ErrInvalidRevision) MarshalZerologObject

func (eri ErrInvalidRevision) MarshalZerologObject(e *zerolog.Event)

func (ErrInvalidRevision) Reason

Reason is the reason the revision failed.

type ErrNamespaceNotFound

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

ErrNamespaceNotFound occurs when a namespace was not found.

func (ErrNamespaceNotFound) MarshalZerologObject

func (enf ErrNamespaceNotFound) MarshalZerologObject(e *zerolog.Event)

func (ErrNamespaceNotFound) NotFoundNamespaceName

func (enf ErrNamespaceNotFound) NotFoundNamespaceName() string

NotFoundNamespaceName is the name of the namespace not found.

type ErrPreconditionFailed

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

ErrPreconditionFailed occurs when the precondition to a write tuple call does not match.

func (ErrPreconditionFailed) MarshalZerologObject

func (epf ErrPreconditionFailed) MarshalZerologObject(e *zerolog.Event)

type ErrReadOnly

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

ErrReadOnly is returned when the operation cannot be completed because the datastore is in read-only mode.

type ErrWatchCanceled

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

ErrWatchCanceled occurs when a watch was canceled by the caller

type ErrWatchDisconnected

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

ErrWatchDisconnected occurs when a watch has fallen too far behind and was forcibly disconnected as a result.

type GraphDatastore

type GraphDatastore interface {
	// QueryTuples creates a builder for reading tuples from the datastore.
	QueryTuples(filter TupleQueryResourceFilter, revision Revision) TupleQuery

	// ReverseQueryTuplesFromSubject creates a builder for reading tuples from
	// subject onward from the datastore.
	ReverseQueryTuplesFromSubject(subject *v0.ObjectAndRelation, revision Revision) ReverseTupleQuery

	// ReverseQueryTuplesFromSubjectRelation creates a builder for reading tuples
	// from a subject relation onward from the datastore.
	ReverseQueryTuplesFromSubjectRelation(subjectNamespace, subjectRelation string, revision Revision) ReverseTupleQuery

	// ReverseQueryTuplesFromSubjectNamespace creates a builder for reading
	// tuples from a subject namespace onward from the datastore.
	ReverseQueryTuplesFromSubjectNamespace(subjectNamespace string, revision Revision) ReverseTupleQuery

	// CheckRevision checks the specified revision to make sure it's valid and
	// hasn't been garbage collected.
	CheckRevision(ctx context.Context, revision Revision) error
}

GraphDatastore is a subset of the datastore interface that is passed to graph resolvers.

type InvalidRevisionReason

type InvalidRevisionReason int

InvalidRevisionReason is the reason the revision could not be used.

const (
	RevisionStale InvalidRevisionReason = iota
	RevisionInFuture
	CouldNotDetermineRevision
)

type ReverseTupleQuery

type ReverseTupleQuery interface {
	CommonTupleQuery

	// WithObjectRelation filters to tuples with the given object relation on the
	// left hand side.
	WithObjectRelation(namespace string, relation string) ReverseTupleQuery
}

ReverseTupleQuery is a builder for constructing reverse tuple queries.

type Revision

type Revision = decimal.Decimal

Revision is a type alias to make changing the revision type a little bit easier if we need to do it in the future. Implementations should code directly against decimal.Decimal when creating or parsing.

var NoRevision Revision

NoRevision is a zero type for the revision that will make changing the revision type in the future a bit easier if necessary. Implementations should use any time they want to signal an empty/error revision.

type RevisionChanges

type RevisionChanges struct {
	Revision Revision
	Changes  []*v0.RelationTupleUpdate
}

RevisionChanges represents the changes in a single transaction.

type TupleIterator

type TupleIterator interface {
	// Next returns the next tuple in the result set.
	Next() *v0.RelationTuple

	// After receiving a nil response, the caller must check for an error.
	Err() error

	// Close cancels the query and closes any open connections.
	Close()
}

TupleIterator is an iterator over matched tuples.

func NewSliceTupleIterator

func NewSliceTupleIterator(tuples []*v0.RelationTuple) TupleIterator

NewSliceTupleIterator creates a datastore.TupleIterator instance from a materialized slice of tuples.

type TupleQuery

type TupleQuery interface {
	CommonTupleQuery

	// WithUserset adds a userset filter to the query.
	WithSubjectFilter(*v1.SubjectFilter) TupleQuery

	// WithUsersets adds multiple userset filters to the query.
	WithUsersets(usersets []*v0.ObjectAndRelation) TupleQuery
}

TupleQuery is a builder for constructing tuple queries.

type TupleQueryResourceFilter added in v0.0.2

type TupleQueryResourceFilter struct {
	ResourceType             string
	OptionalResourceID       string
	OptionalResourceRelation string
}

TupleQueryResourceFilter are the baseline fields used to filter results when querying a datastore for tuples.

OptionalFields are ignored when their value is the empty string.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL