election

package
v1.0.21 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2018 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package election provides master election tools, and interfaces for plugging in a custom underlying mechanism. TODO(pavelkalinnikov): Migrate this package to Trillian.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Election

type Election interface {
	// Await blocks until the instance captures mastership. Returns immediately
	// if it is already the master. Returns an error if capturing fails, or the
	// passed in context is canceled before mastership is captured. If an error
	// is returned, the instance might still have become the master. Idempotent,
	// might be useful to retry in case of an error.
	Await(ctx context.Context) error

	// Observe returns a "mastership context" which remains active until the
	// instance stops being the master, or the passed in context is canceled. If
	// the instance is not the master during this call, returns an already
	// canceled context. In particular, this will happen if Observe is called
	// without a preceding Await.
	//
	// The resources used for maintaining the mastership context are released
	// when the latter gets canceled. This happens when the instance loses
	// mastership, calls Resign, an error occurs in mastership monitoring, or the
	// context passed in to Observe is explicitly canceled.
	Observe(ctx context.Context) (context.Context, error)

	// Resign releases mastership for this instance. The instance can be elected
	// again using Await. Idempotent, might be useful to retry if fails.
	//
	// Note: Resign does not guarantee immediate cancelation of the context
	// returned from Observe. However, the latter will happen *eventually* if
	// resigning is successful. The caller can force mastership context
	// cancelation by explicitly canceling the context passed in to Observe.
	//
	// The caller is advised to tear down mastership-related work before invoking
	// Resign to have best protection against double-master situations.
	Resign(ctx context.Context) error

	// Close permanently stops participating in election, and releases the
	// resources. It does best effort on resigning despite potential cancelation
	// of the passed in context, so that other instances can overtake mastership
	// faster. No other method should be called after Close.
	//
	// Note: Does not guarantee immediate mastership context cancelation, see
	// Resign comment for details.
	Close(ctx context.Context) error
}

Election controls an instance's participation in master election process. Note: Implementations are not intended to be thread-safe.

type Factory

type Factory interface {
	NewElection(ctx context.Context, treeID int64) (Election, error)
}

Factory encapsulates the creation of an Election instance for a treeID.

type NoopElection

type NoopElection int64

NoopElection is a stub Election that always believes to be the master.

func (NoopElection) Await

func (ne NoopElection) Await(ctx context.Context) error

Await returns immediately, as the instance is always the master.

func (NoopElection) Close

func (ne NoopElection) Close(ctx context.Context) error

Close does nothing because NoopElection is always the master.

func (NoopElection) Observe

func (ne NoopElection) Observe(ctx context.Context) (context.Context, error)

Observe returns the passed in context as a mastership context.

func (NoopElection) Resign

func (ne NoopElection) Resign(ctx context.Context) error

Resign does nothing because NoopElection is always the master.

type NoopFactory

type NoopFactory struct{}

NoopFactory creates NoopElection instances.

func (NoopFactory) NewElection

func (nf NoopFactory) NewElection(ctx context.Context, treeID int64) (Election, error)

NewElection creates a specific NoopElection instance.

Directories

Path Synopsis
Package etcd provides an implementation of master election based on etcd.
Package etcd provides an implementation of master election based on etcd.

Jump to

Keyboard shortcuts

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