Documentation
¶
Index ¶
- func ContextWithDataLayer(ctx context.Context, dl DataLayer) context.Context
- func ContextWithHandle(ctx context.Context) context.Context
- func NewCountingDataLayer(dl DataLayer) (DataLayer, *MethodCounts)
- func SetInContext(ctx context.Context, dl DataLayer) error
- func StreamCountingInterceptor(exporter MethodCountsExporter) grpc.StreamServerInterceptor
- func StreamServerInterceptor(dl DataLayer) grpc.StreamServerInterceptor
- func UnaryCountingInterceptor(exporter MethodCountsExporter) grpc.UnaryServerInterceptor
- func UnaryServerInterceptor(dl DataLayer) grpc.UnaryServerInterceptor
- func UnwrapDatastore(dl DataLayer) datastore.Datastore
- type DataLayer
- type LegacySchemaWriterdeprecated
- type MethodCounts
- type MethodCountsExporter
- type ReadWriteTransaction
- type RevisionedReader
- type SchemaReader
- type TxUserFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextWithDataLayer ¶
ContextWithDataLayer adds the handle and DataLayer in one step.
func ContextWithHandle ¶
ContextWithHandle adds a placeholder to a context that will later be filled by the datalayer.
func NewCountingDataLayer ¶
func NewCountingDataLayer(dl DataLayer) (DataLayer, *MethodCounts)
NewCountingDataLayer wraps a DataLayer with per-request counting.
func SetInContext ¶
SetInContext sets the DataLayer in the given context.
func StreamCountingInterceptor ¶
func StreamCountingInterceptor(exporter MethodCountsExporter) grpc.StreamServerInterceptor
StreamCountingInterceptor wraps the datalayer with counting for each stream request. The exporter function is called after each stream to export counts (e.g. to Prometheus).
func StreamServerInterceptor ¶
func StreamServerInterceptor(dl DataLayer) grpc.StreamServerInterceptor
StreamServerInterceptor returns a new stream server interceptor that adds the DataLayer to the context.
func UnaryCountingInterceptor ¶
func UnaryCountingInterceptor(exporter MethodCountsExporter) grpc.UnaryServerInterceptor
UnaryCountingInterceptor wraps the datalayer with counting for each unary request. The exporter function is called after each request to export counts (e.g. to Prometheus).
func UnaryServerInterceptor ¶
func UnaryServerInterceptor(dl DataLayer) grpc.UnaryServerInterceptor
UnaryServerInterceptor returns a new unary server interceptor that adds the DataLayer to the context.
func UnwrapDatastore ¶
UnwrapDatastore extracts the underlying datastore.Datastore from a DataLayer. This is for internal use by code that needs raw datastore access (e.g., schema operations).
Types ¶
type DataLayer ¶
type DataLayer interface {
SnapshotReader(datastore.Revision) RevisionedReader
ReadWriteTx(context.Context, TxUserFunc, ...options.RWTOptionsOption) (datastore.Revision, error)
OptimizedRevision(ctx context.Context) (datastore.Revision, error)
HeadRevision(ctx context.Context) (datastore.Revision, error)
CheckRevision(ctx context.Context, revision datastore.Revision) error
RevisionFromString(serialized string) (datastore.Revision, error)
Watch(ctx context.Context, afterRevision datastore.Revision, options datastore.WatchOptions) (<-chan datastore.RevisionChanges, <-chan error)
ReadyState(ctx context.Context) (datastore.ReadyState, error)
Features(ctx context.Context) (*datastore.Features, error)
OfflineFeatures() (*datastore.Features, error)
Statistics(ctx context.Context) (datastore.Stats, error)
UniqueID(ctx context.Context) (string, error)
MetricsID() (string, error)
Close() error
}
DataLayer is the interface for accessing data from the calling layer. It abstracts the underlying datastore, hiding Legacy* methods and providing clean access to schema, relationships, and metadata.
func FromContext ¶
FromContext reads the DataLayer out of a context.Context and returns nil if it does not exist.
func MustFromContext ¶
MustFromContext reads the DataLayer out of a context.Context and panics if it does not exist.
func NewDataLayer ¶
NewDataLayer creates a new DataLayer wrapping a datastore.Datastore.
func NewReadOnlyDataLayer ¶
func NewReadOnlyDataLayer(ds datastore.ReadOnlyDatastore) DataLayer
NewReadOnlyDataLayer creates a DataLayer from a ReadOnlyDatastore. ReadWriteTx will return a readonly error.
func NewReadonlyDataLayer ¶
NewReadonlyDataLayer wraps a DataLayer so that ReadWriteTx returns an error.
type LegacySchemaWriter
deprecated
type LegacySchemaWriter interface {
LegacyWriteCaveats(ctx context.Context, caveats []*core.CaveatDefinition) error
LegacyWriteNamespaces(ctx context.Context, newConfigs ...*core.NamespaceDefinition) error
LegacyDeleteCaveats(ctx context.Context, names []string) error
LegacyDeleteNamespaces(ctx context.Context, nsNames []string, delOption datastore.DeleteNamespacesRelationshipsOption) error
}
LegacySchemaWriter provides access to legacy schema write operations.
Deprecated: This is only for backwards-compatible additive-only schema changes and will be removed when the additive-only schema mode is removed.
type MethodCounts ¶
type MethodCounts struct {
// contains filtered or unexported fields
}
MethodCounts holds per-request counters for tracked methods.
func (*MethodCounts) QueryRelationships ¶
func (m *MethodCounts) QueryRelationships() uint64
QueryRelationships returns the count of QueryRelationships calls.
func (*MethodCounts) ReverseQueryRelationships ¶
func (m *MethodCounts) ReverseQueryRelationships() uint64
ReverseQueryRelationships returns the count of ReverseQueryRelationships calls.
type MethodCountsExporter ¶
type MethodCountsExporter func(counts *MethodCounts)
MethodCountsExporter is a function that exports method counts (e.g. to Prometheus). This is provided by callers to avoid duplicate metric registration.
type ReadWriteTransaction ¶
type ReadWriteTransaction interface {
RevisionedReader
// WriteRelationships takes a list of tuple mutations and applies them to the datastore.
WriteRelationships(ctx context.Context, mutations []tuple.RelationshipUpdate) error
// DeleteRelationships deletes relationships that match the provided filter.
DeleteRelationships(ctx context.Context, filter *v1.RelationshipFilter,
options ...options.DeleteOptionsOption,
) (uint64, bool, error)
// BulkLoad writes all relationships from the source in an optimized fashion.
BulkLoad(ctx context.Context, iter datastore.BulkWriteRelationshipSource) (uint64, error)
// WriteSchema writes the full set of schema definitions.
WriteSchema(ctx context.Context, definitions []datastore.SchemaDefinition, schemaString string, caveatTypeSet *caveattypes.TypeSet) error
// LegacySchemaWriter returns a legacy schema writer for backwards-compatible
// additive-only schema operations.
//
// Deprecated: Will be removed when additive-only schema mode is removed.
LegacySchemaWriter() LegacySchemaWriter
// RegisterCounter registers a count with the provided filter.
RegisterCounter(ctx context.Context, name string, filter *core.RelationshipFilter) error
// UnregisterCounter unregisters a counter.
UnregisterCounter(ctx context.Context, name string) error
// StoreCounterValue stores a count for the counter with the given name.
StoreCounterValue(ctx context.Context, name string, value int, computedAtRevision datastore.Revision) error
}
ReadWriteTransaction supports both reading and writing.
type RevisionedReader ¶
type RevisionedReader interface {
// ReadSchema returns a SchemaReader for organized schema operations.
ReadSchema() (SchemaReader, error)
// QueryRelationships reads relationships, starting from the resource side.
QueryRelationships(
ctx context.Context,
filter datastore.RelationshipsFilter,
options ...options.QueryOptionsOption,
) (datastore.RelationshipIterator, error)
// ReverseQueryRelationships reads relationships, starting from the subject.
ReverseQueryRelationships(
ctx context.Context,
subjectsFilter datastore.SubjectsFilter,
options ...options.ReverseQueryOptionsOption,
) (datastore.RelationshipIterator, error)
// CountRelationships returns the count of relationships that match the provided counter.
CountRelationships(ctx context.Context, name string) (int, error)
// LookupCounters returns all registered counters.
LookupCounters(ctx context.Context) ([]datastore.RelationshipCounter, error)
}
RevisionedReader reads data at a specific revision.
type SchemaReader ¶
type SchemaReader interface {
// SchemaText returns the full schema text.
SchemaText() (string, error)
// LookupTypeDefByName looks up a type definition by name.
LookupTypeDefByName(ctx context.Context, name string) (datastore.RevisionedTypeDefinition, bool, error)
// LookupCaveatDefByName looks up a caveat definition by name.
LookupCaveatDefByName(ctx context.Context, name string) (datastore.RevisionedCaveat, bool, error)
// ListAllTypeDefinitions lists all type definitions.
ListAllTypeDefinitions(ctx context.Context) ([]datastore.RevisionedTypeDefinition, error)
// ListAllCaveatDefinitions lists all caveat definitions.
ListAllCaveatDefinitions(ctx context.Context) ([]datastore.RevisionedCaveat, error)
// ListAllSchemaDefinitions lists all type and caveat definitions.
ListAllSchemaDefinitions(ctx context.Context) (map[string]datastore.SchemaDefinition, error)
// LookupSchemaDefinitionsByNames looks up type and caveat definitions by name.
LookupSchemaDefinitionsByNames(ctx context.Context, names []string) (map[string]datastore.SchemaDefinition, error)
// LookupTypeDefinitionsByNames looks up type definitions by name.
LookupTypeDefinitionsByNames(ctx context.Context, names []string) (map[string]datastore.TypeDefinition, error)
// LookupCaveatDefinitionsByNames looks up caveat definitions by name.
LookupCaveatDefinitionsByNames(ctx context.Context, names []string) (map[string]datastore.CaveatDefinition, error)
}
SchemaReader groups schema read methods, accessed via RevisionedReader.ReadSchema().
func SchemaReaderFromLegacy ¶
func SchemaReaderFromLegacy(legacyReader datastore.LegacySchemaReader) SchemaReader
SchemaReaderFromLegacy returns a SchemaReader that adapts a datastore.LegacySchemaReader by calling Legacy* methods on the underlying reader.
type TxUserFunc ¶
type TxUserFunc func(context.Context, ReadWriteTransaction) error
TxUserFunc is a type for the function that users supply when they invoke a read-write transaction.