ring

package
v0.0.0-...-54ca42f Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2017 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyRing = errors.New("empty circle")

ErrEmptyRing is the error returned when trying to get an element when nothing has been added to hash.

View Source
var (

	// ErrNotFound is returned by ConsulClient.Get.
	ErrNotFound = fmt.Errorf("Not found")
)

Functions

func ProtoDescFactory

func ProtoDescFactory() proto.Message

ProtoDescFactory makes new Descs

Types

type ByToken

type ByToken []*TokenDesc

ByToken is a sortable list of TokenDescs

func (ByToken) Len

func (ts ByToken) Len() int

func (ByToken) Less

func (ts ByToken) Less(i, j int) bool

func (ByToken) Swap

func (ts ByToken) Swap(i, j int)

type CASCallback

type CASCallback func(in interface{}) (out interface{}, retry bool, err error)

CASCallback is the type of the callback to CAS. If err is nil, out must be non-nil.

type Codec

type Codec interface {
	Decode([]byte) (interface{}, error)
	Encode(interface{}) ([]byte, error)
}

Codec allows the consult client to serialise and deserialise values.

type Config

type Config struct {
	ConsulConfig

	HeartbeatTimeout time.Duration
}

Config for a Ring

func (*Config) RegisterFlags

func (cfg *Config) RegisterFlags(f *flag.FlagSet)

RegisterFlags adds the flags required to config this to the given FlagSet

type ConsulClient

type ConsulClient interface {
	CAS(key string, f CASCallback) error
	WatchPrefix(path string, done <-chan struct{}, f func(string, interface{}) bool)
	WatchKey(key string, done <-chan struct{}, f func(interface{}) bool)
	PutBytes(key string, buf []byte) error
}

ConsulClient is a high-level client for Consul, that exposes operations such as CAS and Watch which take callbacks. It also deals with serialisation by having an instance factory passed in to methods and deserialising into that.

func NewConsulClient

func NewConsulClient(cfg ConsulConfig, codec Codec) (ConsulClient, error)

NewConsulClient returns a new ConsulClient.

func PrefixClient

func PrefixClient(client ConsulClient, prefix string) ConsulClient

PrefixClient takes a ConsulClient and forces a prefix on all its operations.

type ConsulConfig

type ConsulConfig struct {
	Host   string
	Prefix string
	// contains filtered or unexported fields
}

ConsulConfig to create a ConsulClient

func (*ConsulConfig) RegisterFlags

func (cfg *ConsulConfig) RegisterFlags(f *flag.FlagSet)

RegisterFlags adds the flags required to config this to the given FlagSet

type IngesterRegistration

type IngesterRegistration struct {
	Ring *Ring
	// contains filtered or unexported fields
}

IngesterRegistration manages the connection between the ingester and Consul.

func RegisterIngester

func RegisterIngester(cfg IngesterRegistrationConfig) (*IngesterRegistration, error)

RegisterIngester registers an ingester with Consul.

func (*IngesterRegistration) ChangeState

func (r *IngesterRegistration) ChangeState(state IngesterState)

ChangeState changes the state of an ingester in the ring.

func (*IngesterRegistration) Unregister

func (r *IngesterRegistration) Unregister()

Unregister removes ingester config from Consul; will block until we'll successfully unregistered.

type IngesterRegistrationConfig

type IngesterRegistrationConfig struct {
	Config

	ListenPort *int
	NumTokens  int

	// For testing
	Addr     string
	Hostname string
	// contains filtered or unexported fields
}

IngesterRegistrationConfig is the config for an IngesterRegistration

func (*IngesterRegistrationConfig) RegisterFlags

func (cfg *IngesterRegistrationConfig) RegisterFlags(f *flag.FlagSet)

RegisterFlags adds the flags required to config this to the given FlagSet

type Operation

type Operation int

Operation can be Read or Write

const (
	Read Operation = iota
	Write
)

Values for Operation

type ProtoCodec

type ProtoCodec struct {
	Factory func() proto.Message
}

ProtoCodec is a Codec for proto/snappy

func (ProtoCodec) Decode

func (p ProtoCodec) Decode(bytes []byte) (interface{}, error)

Decode implements Codec

func (ProtoCodec) Encode

func (p ProtoCodec) Encode(msg interface{}) ([]byte, error)

Encode implements Codec

type Ring

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

Ring holds the information about the members of the consistent hash circle.

func New

func New(cfg Config) (*Ring, error)

New creates a new Ring

func (*Ring) BatchGet

func (r *Ring) BatchGet(keys []uint32, n int, op Operation) ([][]*IngesterDesc, error)

BatchGet returns n (or more) ingesters which form the replicas for the given key. The order of the result matches the order of the input.

func (*Ring) Collect

func (r *Ring) Collect(ch chan<- prometheus.Metric)

Collect implements prometheus.Collector.

func (*Ring) Describe

func (r *Ring) Describe(ch chan<- *prometheus.Desc)

Describe implements prometheus.Collector.

func (*Ring) Get

func (r *Ring) Get(key uint32, n int, op Operation) ([]*IngesterDesc, error)

Get returns n (or more) ingesters which form the replicas for the given key.

func (*Ring) GetAll

func (r *Ring) GetAll() []*IngesterDesc

GetAll returns all available ingesters in the circle.

func (*Ring) Ready

func (r *Ring) Ready() bool

Ready is true when all ingesters are active and healthy.

func (*Ring) ServeHTTP

func (r *Ring) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*Ring) Stop

func (r *Ring) Stop()

Stop the distributor.

Jump to

Keyboard shortcuts

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