rpc

package
v0.0.0-...-4b0e997 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2021 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package rpc implements a reference PeerLoader and corresponding handler.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler(cache *ttlcache.Cache, prefix string, timeout time.Duration) http.Handler

Handler returns a http.Handler to respond to requests sent by the PeerLoader returned by Loader(). We expect requests with a path beginning with prefix, which should match the first argument to http.Handle(), e.g. "/". Note it must end with a trailing slash in order to do a prefix rather than exact match. The timeout is to prevent gets endlessly bouncing around a cluster, even if the client is willing to wait.

func Loader

func Loader(cache string, client *http.Client, basePath string) ttlcache.PeerLoader

Loader returns a new PeerLoader that will send requests to <addr>:<metaport><basePath>/keys/<key> using the provided client. As we modify the client's transport, it should not be used for any other purpose, as the requests will lead to incorrect metrics. The timeout of each request is controlled by the client's Timeout. The loader implementation will back-off exponentially until the context expires. If non-empty, the base path must begin with a /.

func UninstrumentedHandler

func UninstrumentedHandler(cache *ttlcache.Cache, prefix string, timeout time.Duration) http.Handler

UninstrumentedHandler provides the underlying handler used by Handler, without instrumentation. This is intended to be a useful starting point for an external request handler.

Types

type Delegate

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

Delegate is a trivial memberlist.Delegate implementation that responds with a static set of metadata. This struct is immutable.

func NewDelegate

func NewDelegate(port uint16) Delegate

NewDelegate returns a delegate that will serve metadata identifying the provided port.

func (Delegate) GetBroadcasts

func (d Delegate) GetBroadcasts(_, _ int) [][]byte

func (Delegate) LocalState

func (d Delegate) LocalState(_ bool) []byte

func (Delegate) MergeRemoteState

func (d Delegate) MergeRemoteState(_ []byte, _ bool)

func (Delegate) NodeMeta

func (d Delegate) NodeMeta(limit int) []byte

func (Delegate) NotifyMsg

func (d Delegate) NotifyMsg(_ []byte)

type Metadata

type Metadata struct {

	// Port is the port the node is listening for peer loads on.
	Port uint16
}

Metadata contains additional information about a given peer, and is required for other peers to be able to interact with it. Direct use of this struct is only necessary if already using memberlist's metadata facility elsewhere, and you want to embed this package's metadata in your own. Otherwise, simply use NewDelegate() passing in the port directly.

func (*Metadata) Decode

func (m *Metadata) Decode(b []byte) error

Decode unserialises the metadata received from a peer, generated by Encode().

func (*Metadata) Encode

func (m *Metadata) Encode() []byte

Encode serialises the metadata into a byte slice for passing to memberlist. The bytes should not be interpreted by the caller; we may switch to protobuf in future.

type Pair

type Pair struct {

	// Prefix is the pattern under which the loader and handler will operate,
	// e.g. /ttlcache/caches/<name>/keys/. This is passed unmodified when
	// binding the handler, so must end with a /. The loader and handler are
	// deliberately not cache-aware to allow registering different handlers
	// against different caches.
	Prefix string
}

Pair is a wrapper around Loader and Handler that makes it impossible to have an inconsistent base path. Fields should not be modified post-creation.

func (*Pair) Handle

func (p *Pair) Handle(mux *http.ServeMux, cache *ttlcache.Cache, timeout time.Duration)

Handle builds a Handler to serve requests from the provided cache, then binds it to the provided mux at the correct path. The timeout is a safety mechanism to ensure a request doesn't bounce around the cluster forever, even if a client is willing to wait.

func (*Pair) Loader

func (p *Pair) Loader(name string, client *http.Client) ttlcache.PeerLoader

Loader builds a PeerLoader that will request keys from the named cache, using the provided HTTP client. The Timeout of the client controls the time to allow for each request.

Jump to

Keyboard shortcuts

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