readpref

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidTagSet = errors.New("an even number of tags must be specified")

ErrInvalidTagSet indicates that an invalid set of tags was specified.

Functions

func Selector

func Selector(rp *ReadPref) func(c *model.Cluster, candidates []*model.Server) ([]*model.Server, error)

Selector creates a ServerSelector that selects servers based on a read preference.

Types

type Mode

type Mode uint8

Mode indicates the user's preference on reads.

const (
	// PrimaryMode indicates that only a primary is
	// considered for reading. This is the default
	// mode.
	PrimaryMode Mode = iota
	// PrimaryPreferredMode indicates that if a primary
	// is available, use it; otherwise, eligible
	// secondaries will be considered.
	PrimaryPreferredMode
	// SecondaryMode indicates that only secondaries
	// should be considered.
	SecondaryMode
	// SecondaryPreferredMode indicates that only secondaries
	// should be considered when one is available. If none
	// are available, then a primary will be considered.
	SecondaryPreferredMode
	// NearestMode indicates that all primaries and secondaries
	// will be considered.
	NearestMode
)

Mode constants

func ModeFromString

func ModeFromString(mode string) (Mode, error)

ModeFromString returns a mode corresponding to mode.

type Option

type Option func(*ReadPref) error

Option configures a read preference

func WithMaxStaleness

func WithMaxStaleness(ms time.Duration) Option

WithMaxStaleness sets the maximum staleness a server is allowed.

func WithTagSets

func WithTagSets(tagSets ...model.TagSet) Option

WithTagSets sets the tag sets used to match a server. The last call to WithTags or WithTagSets overrides all previous calls to either method.

func WithTags

func WithTags(tags ...string) Option

WithTags sets a single tag set used to match a server. The last call to WithTags or WithTagSets overrides all previous calls to either method.

type ReadPref

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

ReadPref determines which servers are considered suitable for read operations.

func Nearest

func Nearest(opts ...Option) *ReadPref

Nearest constructs a read preference with a NearestMode.

func New

func New(mode Mode, opts ...Option) (*ReadPref, error)

New creates a new ReadPref.

func Primary

func Primary() *ReadPref

Primary constructs a read preference with a PrimaryMode.

func PrimaryPreferred

func PrimaryPreferred(opts ...Option) *ReadPref

PrimaryPreferred constructs a read preference with a PrimaryPreferredMode.

func Secondary

func Secondary(opts ...Option) *ReadPref

Secondary constructs a read preference with a SecondaryMode.

func SecondaryPreferred

func SecondaryPreferred(opts ...Option) *ReadPref

SecondaryPreferred constructs a read preference with a SecondaryPreferredMode.

func (*ReadPref) MaxStaleness

func (r *ReadPref) MaxStaleness() (time.Duration, bool)

MaxStaleness is the maximum amount of time to allow a server to be considered eligible for selection. The second return value indicates if this value has been set.

func (*ReadPref) Mode

func (r *ReadPref) Mode() Mode

Mode indicates the mode of the read preference.

func (*ReadPref) TagSets

func (r *ReadPref) TagSets() []model.TagSet

TagSets are multiple tag sets indicating which servers should be considered.

Jump to

Keyboard shortcuts

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