submatview

package
v1.9.12 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2021 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Deps

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

type Materializer

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

Materializer consumes the event stream, handling any framing events, and sends the events to View as they are received.

Materializer is used as the cache.Result.State 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 TTL expires.

func NewMaterializer

func NewMaterializer(deps Deps) *Materializer

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

func (*Materializer) Fetch

func (m *Materializer) Fetch(done <-chan struct{}, opts cache.FetchOptions) (cache.FetchResult, error)

Fetch implements the logic a StreamingCacheType will need during it's Fetch call. Cache types that use streaming should just be able to proxy to this once they have a subscription object and return it's results directly.

func (*Materializer) Run

func (m *Materializer) 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.

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{}, error)

	// 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