sharediterator

package
v1.9.4 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DatastoreStorageOpt

type DatastoreStorageOpt func(*Storage)

func WithSharedIteratorDatastoreStorageLimit

func WithSharedIteratorDatastoreStorageLimit(limit int) DatastoreStorageOpt

WithSharedIteratorDatastoreStorageLimit sets the limit on the number of items in SF iterator iters.

type IteratorDatastore

type IteratorDatastore struct {
	// RelationshipTupleReader is the inner datastore that provides the actual implementation of reading tuples.
	storage.RelationshipTupleReader
	// contains filtered or unexported fields
}

IteratorDatastore is a wrapper around a storage.RelationshipTupleReader that provides shared iterators. It uses an internal storage to manage shared iterators and provides methods to read tuples starting with a user, read userset tuples, and read tuples by key. The shared iterators are created lazily and are shared across multiple requests to improve performance.

func NewSharedIteratorDatastore

func NewSharedIteratorDatastore(inner storage.RelationshipTupleReader, internalStorage *Storage, opts ...IteratorDatastoreOpt) *IteratorDatastore

NewSharedIteratorDatastore creates a new IteratorDatastore with the given inner RelationshipTupleReader and internal storage. It also accepts optional configuration options to customize the behavior of the datastore. The datastore will use shared iterators to improve performance by reusing iterators across multiple requests. If the number of active iterators exceeds the specified limit, new requests will be bypassed and handled by the inner reader.

func (*IteratorDatastore) Read

Read reads tuples by key using shared iterators. If the request is for higher consistency, it will fall back to the inner RelationshipTupleReader.

func (*IteratorDatastore) ReadStartingWithUser

ReadStartingWithUser reads tuples starting with a user using shared iterators. If the request is for higher consistency, it will fall back to the inner RelationshipTupleReader.

func (*IteratorDatastore) ReadUsersetTuples

ReadUsersetTuples reads userset tuples using shared iterators. If the request is for higher consistency, it will fall back to the inner RelationshipTupleReader.

type IteratorDatastoreOpt

type IteratorDatastoreOpt func(*IteratorDatastore)

func WithMaxAdmissionTime added in v1.8.13

func WithMaxAdmissionTime(maxAdmissionTime time.Duration) IteratorDatastoreOpt

WithMaxAdmissionTime sets the maximum duration for which a shared iterator may reused. After this period, the shared iterator will be removed from the cache. This is done to prevent stale data if there are very long-running requests.

func WithMaxIdleTime added in v1.9.3

func WithMaxIdleTime(maxIdleTime time.Duration) IteratorDatastoreOpt

WithMaxIdleTime sets the maximum duration for which a shared iterator can remain idle before it is no longer reusable. After this period, the shared iterator will be removed from the cache. This is done to prevent unused shared iterators from being cached for longer than necessary.

func WithMethod added in v1.8.13

func WithMethod(method string) IteratorDatastoreOpt

WithMethod specifies whether the shared iterator is for check or list objects for metrics.

func WithSharedIteratorDatastoreLogger

func WithSharedIteratorDatastoreLogger(logger logger.Logger) IteratorDatastoreOpt

WithSharedIteratorDatastoreLogger sets the logger for the IteratorDatastore.

type Storage

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

Storage is a simple in-memory storage for shared iterators. It uses a sync.Map to store iterators and an atomic counter to keep track of the number of items. The limit is set to defaultSharedIteratorLimit, which can be overridden by the user. The storage is used to share iterators across multiple requests, allowing for efficient reuse of iterators.

func NewSharedIteratorDatastoreStorage

func NewSharedIteratorDatastoreStorage(opts ...DatastoreStorageOpt) *Storage

Jump to

Keyboard shortcuts

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