trie

package
v4.0.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package trie provides a trie implementation specialised to Flair's requirements.

Not every possible setup is supported. Maybe eventually it will get cleverer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ReplicatedFunc

type ReplicatedFunc func(*Server) error

A ReplicatedFunc is a function that is passed to the replicator that gets called potentially more than once against different servers. If the returned appear appears to be retryable we will try on a new replica (e.g. we would retry Unavailable errors where the server is down, we wouldn't retry InvalidArgument where it seems it would be pointless).

type Replicator

type Replicator struct {
	Trie     *Trie
	Replicas int
	// contains filtered or unexported fields
}

A Replicator implements replication for our RPCs.

func NewReplicator

func NewReplicator(t *Trie, replicas int) *Replicator

NewReplicator returns a new Replicator instance.

func (*Replicator) Parallel

func (r *Replicator) Parallel(key string, f ReplicatedFunc) error

Parallel replicates the given function to all replicas at once. It returns an error if all replicas fail, hence it is possible for some replicas not to receive data.

func (*Replicator) Sequential

func (r *Replicator) Sequential(key string, f ReplicatedFunc) error

Sequential runs the function sequentially from the primary, attempting each replica in sequence until either one is successful or they all fail. It returns an error if all replicas fail, which is the error of the primary replica (with appropriate status code etc).

type Server

A Server holds several gRPC connections to the same server.

type Trie

type Trie struct {
	// If TLS is set, newly created connections will use a generic TLS configuration.
	TLS bool
	// contains filtered or unexported fields
}

A Trie provides fast lookups on hash keys. The zero value is usable.

func (*Trie) Add

func (t *Trie) Add(rangeSpec, address string) error

Add adds a node to this trie. It returns an error on any failure, including overlapping ranges.

func (*Trie) AddAll

func (t *Trie) AddAll(spec map[string]string) error

AddAll adds everything from the given map to this trie. It produces a mildly better memory layout than repeatedly calling Add.

func (*Trie) AddRange

func (t *Trie) AddRange(start, end, address string) error

AddRange adds a specific hash range to this trie.

func (*Trie) Check

func (t *Trie) Check() error

Check performs a check on this trie, validating that all ranges are accounted for.

func (*Trie) Get

func (t *Trie) Get(key string) *Server

Get returns a server from this trie. It is assumed not to fail since the trie is already complete.

func (*Trie) GetOffset

func (t *Trie) GetOffset(key string, offset int) *Server

GetOffset gets a server with the hash offset by a given amount.

Jump to

Keyboard shortcuts

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