ring

package
v0.0.0-...-ee1864c Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2018 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// ConsulKey is the key under which we store the ring in consul.
	ConsulKey = "ring"
)

Variables

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

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 GenerateTokens

func GenerateTokens(numTokens int, takenTokens []uint32) []uint32

GenerateTokens make numTokens random tokens, none of which clash with takenTokens. Assumes takenTokens is sorted.

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
	ReplicationFactor int
	Mock              KVClient
	// contains filtered or unexported fields
}

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 ConsulConfig

type ConsulConfig struct {
	Host              string
	Prefix            string
	ACLToken          string
	HTTPClientTimeout time.Duration
	ConsistentReads   bool
}

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 FlushTransferer

type FlushTransferer interface {
	StopIncomingRequests()
	Flush()
	TransferOut(ctx context.Context) error
}

FlushTransferer controls the shutdown of an ingester.

type KVClient

type KVClient interface {
	CAS(ctx context.Context, key string, f CASCallback) error
	WatchKey(ctx context.Context, key string, f func(interface{}) bool)
	Get(ctx context.Context, key string) (interface{}, error)
	PutBytes(ctx context.Context, key string, buf []byte) error
}

KVClient 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) (KVClient, error)

NewConsulClient returns a new ConsulClient.

func NewInMemoryKVClient

func NewInMemoryKVClient() KVClient

NewInMemoryKVClient makes a new mock consul client.

func PrefixClient

func PrefixClient(client KVClient, prefix string) KVClient

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

type Lifecycler

type Lifecycler struct {
	KVStore KVClient

	// These values are initialised at startup, and never change
	ID string
	// contains filtered or unexported fields
}

Lifecycler is responsible for managing the lifecycle of entries in the ring.

func NewLifecycler

func NewLifecycler(cfg LifecyclerConfig, flushTransferer FlushTransferer) (*Lifecycler, error)

NewLifecycler makes and starts a new Lifecycler.

func (*Lifecycler) ChangeState

func (i *Lifecycler) ChangeState(ctx context.Context, state IngesterState) error

ChangeState of the ingester, for use off of the loop() goroutine.

func (*Lifecycler) ClaimTokensFor

func (i *Lifecycler) ClaimTokensFor(ctx context.Context, ingesterID string) error

ClaimTokensFor takes all the tokens for the supplied ingester and assigns them to this ingester.

func (*Lifecycler) GetState

func (i *Lifecycler) GetState() IngesterState

GetState returns the state of this ingester.

func (*Lifecycler) IsReady

func (i *Lifecycler) IsReady(ctx context.Context) bool

IsReady is used to rate limit the number of ingesters that can be coming or going at any one time, by only returning true if all ingesters are active.

func (*Lifecycler) Shutdown

func (i *Lifecycler) Shutdown()

Shutdown the lifecycle. It will: - send chunks to another ingester, if it can. - otherwise, flush chunks to the chunk store. - remove config from Consul. - block until we've successfully shutdown.

type LifecyclerConfig

type LifecyclerConfig struct {
	KVClient   KVClient
	RingConfig Config

	// Config for the ingester lifecycle control
	ListenPort      *int
	NumTokens       int
	HeartbeatPeriod time.Duration
	JoinAfter       time.Duration
	ClaimOnRollout  bool

	// For testing, you can override the address and ID of this ingester
	Addr           string
	InfName        string
	ID             string
	SkipUnregister bool
}

LifecyclerConfig is the config to build a Lifecycler.

func (*LifecyclerConfig) RegisterFlags

func (cfg *LifecyclerConfig) 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
	Reporting // Special value for inquiring about health
)

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 ReadRing

type ReadRing interface {
	prometheus.Collector

	Get(key uint32, op Operation) (ReplicationSet, error)
	BatchGet(keys []uint32, op Operation) ([]ReplicationSet, error)
	GetAll() (ReplicationSet, error)
	ReplicationFactor() int
}

ReadRing represents the read inferface to the ring.

type ReplicationSet

type ReplicationSet struct {
	Ingesters []*IngesterDesc
	MaxErrors int
}

ReplicationSet describes the ingesters to talk to for a given key, and how many errors to tolerate.

type Ring

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

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

func New

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

New creates a new Ring

func (*Ring) BatchGet

func (r *Ring) BatchGet(keys []uint32, op Operation) ([]ReplicationSet, error)

BatchGet returns ReplicationFactor (or more) ingesters which form the replicas for the given keys. 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, op Operation) (ReplicationSet, error)

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

func (*Ring) GetAll

func (r *Ring) GetAll() (ReplicationSet, error)

GetAll returns all available ingesters in the ring.

func (*Ring) IsHealthy

func (r *Ring) IsHealthy(ingester *IngesterDesc, op Operation) bool

IsHealthy checks whether an ingester appears to be alive and heartbeating

func (*Ring) ReplicationFactor

func (r *Ring) ReplicationFactor() int

ReplicationFactor of the ring.

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