submatview

package
v1.13.2 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2022 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ACLResolver added in v1.13.0

type ACLResolver interface {
	ResolveTokenAndDefaultMeta(token string, entMeta *acl.EnterpriseMeta, authzContext *acl.AuthorizerContext) (resolver.Result, error)
}

type Deps

type Deps struct {
	View    View
	Logger  hclog.Logger
	Waiter  *retry.Waiter
	Request func(index uint64) *pbsubscribe.SubscribeRequest
}

type LocalBackend added in v1.13.0

type LocalBackend interface {
	Subscribe(req *stream.SubscribeRequest) (*stream.Subscription, error)
}

type LocalMaterializer added in v1.13.0

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

LocalMaterializer is a materializer for a stream of events and manages the local subscription to the event publisher until the cache result is discarded when its TTL expires.

func NewLocalMaterializer added in v1.13.0

func NewLocalMaterializer(deps LocalMaterializerDeps) *LocalMaterializer

func (*LocalMaterializer) Query added in v1.13.0

func (m *LocalMaterializer) Query(ctx context.Context, minIndex uint64) (Result, error)

Query implements Materializer

func (*LocalMaterializer) Run added in v1.13.0

func (m *LocalMaterializer) Run(ctx context.Context)

Run receives events from a local subscription backend and sends them to the View. It runs until ctx is cancelled, so it is expected to be run in a goroutine. Mirrors implementation of RPCMaterializer.

Run implements Materializer

type LocalMaterializerDeps added in v1.13.0

type LocalMaterializerDeps struct {
	Deps

	Backend     LocalBackend
	ACLResolver ACLResolver
}

type Materializer

type Materializer interface {
	Run(ctx context.Context)
	Query(ctx context.Context, minIndex uint64) (Result, error)
}

A Materializer maintains a materialized view of a subscription on an event stream.

type MockACLResolver added in v1.13.0

type MockACLResolver struct {
	mock.Mock
}

MockACLResolver is an autogenerated mock type for the ACLResolver type

func NewMockACLResolver added in v1.13.0

func NewMockACLResolver(t testing.TB) *MockACLResolver

NewMockACLResolver creates a new instance of MockACLResolver. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations.

func (*MockACLResolver) ResolveTokenAndDefaultMeta added in v1.13.0

func (_m *MockACLResolver) ResolveTokenAndDefaultMeta(token string, entMeta *acl.EnterpriseMeta, authzContext *acl.AuthorizerContext) (resolver.Result, error)

ResolveTokenAndDefaultMeta provides a mock function with given fields: token, entMeta, authzContext

type RPCMaterializer added in v1.13.0

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

RPCMaterializer is a materializer for a streaming cache type and manages the actual streaming RPC call to the servers behind the scenes until the cache result is discarded when its TTL expires.

func NewRPCMaterializer added in v1.13.0

func NewRPCMaterializer(client StreamClient, deps Deps) *RPCMaterializer

NewRPCMaterializer returns a new Materializer. Run must be called to start it.

func (*RPCMaterializer) Query added in v1.13.0

func (m *RPCMaterializer) Query(ctx context.Context, minIndex uint64) (Result, error)

Query implements Materializer

func (*RPCMaterializer) Run added in v1.13.0

func (m *RPCMaterializer) Run(ctx context.Context)

Run receives events from the StreamClient and sends them to the View. It runs until ctx is cancelled, so it is expected to be run in a goroutine. Mirrors implementation of LocalMaterializer

Run implements Materializer

type Request added in v1.10.0

type Request interface {
	cache.Request
	// NewMaterializer will be called if there is no active materializer to fulfil
	// the request. It should return a Materializer appropriate for streaming
	// data to fulfil this request.
	NewMaterializer() (Materializer, error)
	// Type should return a string which uniquely identifies this type of request.
	// The returned value is used as the prefix of the key used to index
	// entries in the Store.
	Type() string
}

Request is used to request data from the Store. Note that cache.Request is required, but some of the fields cache.RequestInfo fields are ignored (ex: MaxAge, and MustRevalidate).

type Result added in v1.10.0

type Result struct {
	Index uint64
	Value interface{}
	// Cached is true if the requested value was already available locally. If
	// the value is false, it indicates that GetFromView had to wait for an update,
	Cached bool
}

Result returned from the View.

type Store added in v1.10.0

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

Store of Materializers. Store implements an interface similar to agent/cache.Cache, and allows a single Materializer to fulfil multiple requests as long as the requests are identical. Store is used in place of agent/cache.Cache because with the streaming backend there is no longer any need to run a background goroutine to refresh stored values.

func NewStore added in v1.10.0

func NewStore(logger hclog.Logger) *Store

NewStore creates and returns a Store that is ready for use. The caller must call Store.Run (likely in a separate goroutine) to start the expiration loop.

func (*Store) Get added in v1.10.0

func (s *Store) Get(ctx context.Context, req Request) (Result, error)

Get a value from the store, blocking if the store has not yet seen the req.Index value. See agent/cache.Cache.Get for complete documentation.

func (*Store) Notify added in v1.10.0

func (s *Store) Notify(
	ctx context.Context,
	req Request,
	correlationID string,
	updateCh chan<- cache.UpdateEvent,
) error

Notify the updateCh when there are updates to the entry identified by req. See agent/cache.Cache.Notify for complete documentation.

Request.CacheInfo().Timeout is ignored because it is not really relevant in this case. Instead set a deadline on the context.

func (*Store) NotifyCallback added in v1.13.0

func (s *Store) NotifyCallback(
	ctx context.Context,
	req Request,
	correlationID string,
	cb cache.Callback,
) error

NotifyCallback subscribes to updates of the entry identified by req in the same way as Notify, but accepts a callback function instead of a channel.

func (*Store) Run added in v1.10.0

func (s *Store) Run(ctx context.Context)

Run the expiration loop until the context is cancelled.

type StreamClient

type StreamClient interface {
	Subscribe(ctx context.Context, in *pbsubscribe.SubscribeRequest, opts ...grpc.CallOption) (pbsubscribe.StateChangeSubscription_SubscribeClient, error)
}

StreamClient provides a subscription to state change events.

type View

type View interface {
	// Update is called when one or more events are received. The first call will
	// include _all_ events in the initial snapshot which may be an empty set.
	// Subsequent calls will contain one or more update events in the order they
	// are received.
	Update(events []*pbsubscribe.Event) error

	// Result returns the type-specific cache result based on the state. When no
	// events have been delivered yet the result should be an empty value type
	// suitable to return to clients in case there is an empty result on the
	// servers. The index the materialized view represents is maintained
	// separately and passed in in case the return type needs an Index field
	// populating. This allows implementations to not worry about maintaining
	// indexes seen during Update.
	Result(index uint64) interface{}

	// Reset the view to the zero state, done in preparation for receiving a new
	// snapshot.
	Reset()
}

View receives events from, and return results to, Materializer. A view is responsible for converting the pbsubscribe.Event.Payload into the local type, and storing it so that it can be returned by Result().

Jump to

Keyboard shortcuts

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