Documentation
¶
Index ¶
- func ContextWithDataLayer(ctx context.Context, dl DataLayer) context.Context
- func ContextWithHandle(ctx context.Context) context.Context
- func SetInContext(ctx context.Context, dl DataLayer) error
- func StreamServerInterceptor(dl DataLayer) grpc.StreamServerInterceptor
- func UnaryServerInterceptor(dl DataLayer) grpc.UnaryServerInterceptor
- func UnwrapDatastore(dl DataLayer) datastore.Datastore
- func WriteSchemaViaStoredSchema(ctx context.Context, rwt datastore.ReadWriteTransaction, ...) error
- func WriteStoredSchemaForTest(ctx context.Context, ds datastore.Datastore, schemaText string) (datastore.Revision, error)
- type DataLayer
- type DataLayerOption
- type LegacySchemaWriterdeprecated
- type ReadWriteTransaction
- type RevisionedReader
- type SchemaCache
- type SchemaCacheKey
- type SchemaHash
- type SchemaMode
- 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 SetInContext ¶
SetInContext sets the DataLayer in the given context.
func StreamServerInterceptor ¶
func StreamServerInterceptor(dl DataLayer) grpc.StreamServerInterceptor
StreamServerInterceptor returns a new stream server interceptor that adds the DataLayer to the context.
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).
func WriteSchemaViaStoredSchema ¶ added in v1.53.0
func WriteSchemaViaStoredSchema(ctx context.Context, rwt datastore.ReadWriteTransaction, definitions []datastore.SchemaDefinition, schemaString string, cache storedSchemaCache, ) error
WriteSchemaViaStoredSchema builds a StoredSchema proto and writes it via WriteStoredSchema. If cache is nil, a no-op cache is used.
func WriteStoredSchemaForTest ¶ added in v1.53.0
func WriteStoredSchemaForTest(ctx context.Context, ds datastore.Datastore, schemaText string) (datastore.Revision, error)
WriteStoredSchemaForTest takes a datastore handle and a schema string and writes a stored schema with hash to the datastore. Intended as a convenient handle for test logic.
Types ¶
type DataLayer ¶
type DataLayer interface {
SnapshotReader(datastore.Revision, SchemaHash) RevisionedReader
ReadWriteTx(context.Context, TxUserFunc, ...options.RWTOptionsOption) (datastore.Revision, error)
OptimizedRevision(ctx context.Context) (datastore.Revision, SchemaHash, error)
HeadRevision(ctx context.Context) (datastore.Revision, SchemaHash, 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 ¶
func NewDataLayer(ds datastore.Datastore, opts ...DataLayerOption) DataLayer
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 DataLayerOption ¶ added in v1.53.0
type DataLayerOption func(*defaultDataLayer)
DataLayerOption configures a DataLayer.
func WithSchemaCache ¶ added in v1.53.0
func WithSchemaCache(cache SchemaCache) DataLayerOption
WithSchemaCache sets the backing schema cache for the DataLayer. When set, ReadStoredSchema calls are cached and WriteStoredSchema updates the cache.
func WithSchemaMode ¶ added in v1.53.0
func WithSchemaMode(mode SchemaMode) DataLayerOption
WithSchemaMode sets the schema mode for the DataLayer.
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 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(ctx context.Context) (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 SchemaCache ¶ added in v1.53.0
type SchemaCache interface {
Get(key SchemaCacheKey) (*datastore.ReadOnlyStoredSchema, bool)
Set(key SchemaCacheKey, entry *datastore.ReadOnlyStoredSchema, cost int64) bool
Wait()
}
SchemaCache defines the interface for the backing cache used by schemaHashCache. This is satisfied by cache.Cache[SchemaCacheKey, *datastore.ReadOnlyStoredSchema].
type SchemaCacheKey ¶ added in v1.53.0
type SchemaCacheKey string
SchemaCacheKey is the key type used for schema cache lookups. It implements cache.KeyString so it can be used with the cache package.
func (SchemaCacheKey) KeyString ¶ added in v1.53.0
func (k SchemaCacheKey) KeyString() string
KeyString implements cache.KeyString.
type SchemaHash ¶ added in v1.53.0
type SchemaHash string
SchemaHash is a string that uniquely identifies a specific version of a schema. It is used by caching layers to avoid redundant reads of the schema from the underlying datastore when the schema hasn't changed.
const ( // NoSchemaHashInTransaction is a sentinel value used when reading within a // read-write transaction where the schema revision is not yet stable. NoSchemaHashInTransaction SchemaHash = "no-schema-hash-in-transaction" // NoSchemaHashInDevelopment is a sentinel value used when operating in // development mode, where caching of schema is not desired. NoSchemaHashInDevelopment SchemaHash = "no-schema-hash-in-development" // NoSchemaHashForTesting is a sentinel value used in tests, where schema // caching is not needed. NoSchemaHashForTesting SchemaHash = "no-schema-hash-for-testing" // NoSchemaHashForWatch is a sentinel value used when reading schema for // watch operations, where the hash is not yet available. NoSchemaHashForWatch SchemaHash = "no-schema-hash-for-watch" // NoSchemaHashForLegacyCursor is a sentinel value for decoding legacy cursors // that do not contain a schema hash field. NoSchemaHashForLegacyCursor SchemaHash = "no-schema-hash-for-legacy-cursor" // NoSchemaHashInLegacyMode is a sentinel value used when the DataLayer is // operating in legacy schema mode, where no unified schema exists. NoSchemaHashInLegacyMode SchemaHash = "no-schema-hash-in-legacy-mode" )
func (SchemaHash) IsBypassSentinel ¶ added in v1.53.0
func (sh SchemaHash) IsBypassSentinel() bool
IsBypassSentinel returns true if this SchemaHash is a sentinel value that should bypass any caching.
type SchemaMode ¶ added in v1.53.0
type SchemaMode uint8
SchemaMode represents the experimental schema mode for datastore operations. It controls how schema is read from and written to the datastore, allowing a gradual migration from legacy per-definition storage to unified schema storage.
const ( // SchemaModeReadLegacyWriteLegacy uses legacy schema reader and writer. // This is the default and backward-compatible mode. SchemaModeReadLegacyWriteLegacy SchemaMode = iota // SchemaModeReadLegacyWriteBoth uses legacy schema reader and writes to both // legacy and unified schema storage. Use this as the first migration step. SchemaModeReadLegacyWriteBoth // SchemaModeReadNewWriteBoth uses unified schema reader and writes to both // legacy and unified schema storage. Use this as the second migration step. SchemaModeReadNewWriteBoth // SchemaModeReadNewWriteNew uses unified schema reader and writer only. // This is the final migration target. SchemaModeReadNewWriteNew )
func ParseSchemaMode ¶ added in v1.53.0
func ParseSchemaMode(s string) (SchemaMode, error)
ParseSchemaMode converts a string to a SchemaMode. Returns an error if the string is invalid.
func (SchemaMode) ReadsFromNew ¶ added in v1.53.0
func (s SchemaMode) ReadsFromNew() bool
ReadsFromNew returns true if the mode reads from the unified schema storage.
func (SchemaMode) String ¶ added in v1.53.0
func (s SchemaMode) String() string
String returns the string representation of the SchemaMode.
func (SchemaMode) WritesToLegacy ¶ added in v1.53.0
func (s SchemaMode) WritesToLegacy() bool
WritesToLegacy returns true if the mode writes to legacy schema storage.
func (SchemaMode) WritesToNew ¶ added in v1.53.0
func (s SchemaMode) WritesToNew() bool
WritesToNew returns true if the mode writes to unified schema storage.
type SchemaReader ¶
type SchemaReader interface {
// SchemaText returns the full schema text.
SchemaText(ctx context.Context) (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.