util

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2017 License: Apache-2.0 Imports: 12 Imported by: 86

Documentation

Overview

Package util holds various utility functions used throughout the Trillian codebase.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AwaitSignal

func AwaitSignal(doneFn func())

AwaitSignal waits for standard termination signals, then runs the given function; it should be run as a separate goroutine.

func HeldInfo

func HeldInfo(held []int64, ids []int64) string

HeldInfo produces a textual description of the set of held IDs, compared to a complete set of IDs.

func StartHTTPServer

func StartHTTPServer(addr string) error

StartHTTPServer starts an HTTP server on the given address.

Types

type ElectionFactory

type ElectionFactory interface {
	NewElection(ctx context.Context, treeID int64) (MasterElection, error)
}

ElectionFactory encapsulates the creation of a MasterElection instance for a treeID.

type FakeTimeSource

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

FakeTimeSource provides a time that can be any arbitrarily set value for use in tests. It should not be used in production code.

func NewFakeTimeSource

func NewFakeTimeSource(t time.Time) *FakeTimeSource

NewFakeTimeSource creates a FakeTimeSource instance

func (*FakeTimeSource) Now

func (f *FakeTimeSource) Now() time.Time

Now returns the time value this instance contains

func (*FakeTimeSource) Set

func (f *FakeTimeSource) Set(t time.Time)

Set gives the time that this instance will report

type IncrementingFakeTimeSource

type IncrementingFakeTimeSource struct {
	BaseTime      time.Time
	Increments    []time.Duration
	NextIncrement int
}

IncrementingFakeTimeSource takes a base time and several increments, which will be applied to the base time each time Now() is called. The first call will return the base time + zeroth increment. If called more times than provided for then it will panic. Does not require that increments increase monotonically.

func (*IncrementingFakeTimeSource) Now

Now returns the current time according to this time source, which depends on how many times this method has already been invoked.

type MasterElection

type MasterElection interface {
	// Start kicks off the process of mastership election.
	Start(context.Context) error
	// WaitForMastership blocks until the current instance is master for this election.
	WaitForMastership(context.Context) error
	// IsMaster returns whether the current instance is master.
	IsMaster(context.Context) (bool, error)
	// ResignAndRestart releases mastership, and re-joins the election.
	ResignAndRestart(context.Context) error
	// Close permanently stops the mastership election process.
	Close(context.Context) error
}

MasterElection provides operations for determining if a local instance is the current master for a particular election.

type MasterTracker

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

MasterTracker tracks the current mastership state across multiple IDs.

func NewMasterTracker

func NewMasterTracker(ids []int64) *MasterTracker

NewMasterTracker creates a new MasterTracker instance to track the mastership status for the given set of ids.

func (*MasterTracker) Count

func (mt *MasterTracker) Count() int

Count returns the number of IDs for which we are currently master.

func (*MasterTracker) Held

func (mt *MasterTracker) Held() []int64

Held returns a (sorted) list of the IDs for which we are currently master.

func (*MasterTracker) IDs

func (mt *MasterTracker) IDs() []int64

IDs returns a (sorted) list of the IDs that we are currently tracking.

func (*MasterTracker) Set

func (mt *MasterTracker) Set(id int64, val bool)

Set changes the tracked mastership status for the given id. This method should be called exactly once for each state transition.

func (*MasterTracker) String

func (mt *MasterTracker) String() string

String returns a textual decription of the current mastership status.

type NoopElection

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

NoopElection is a stub implementation that tells every instance that it is master.

func (*NoopElection) Close

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

Close permanently stops the mastership election process.

func (*NoopElection) IsMaster

func (ne *NoopElection) IsMaster(ctx context.Context) (bool, error)

IsMaster returns whether the current instance is master.

func (*NoopElection) ResignAndRestart

func (ne *NoopElection) ResignAndRestart(ctx context.Context) error

ResignAndRestart releases mastership, and re-joins the election.

func (*NoopElection) Start

func (ne *NoopElection) Start(ctx context.Context) error

Start kicks off the process of mastership election.

func (*NoopElection) WaitForMastership

func (ne *NoopElection) WaitForMastership(ctx context.Context) error

WaitForMastership blocks until the current instance is master for this election.

type NoopElectionFactory

type NoopElectionFactory struct {
	InstanceID string
}

NoopElectionFactory creates NoopElection instances.

func (NoopElectionFactory) NewElection

func (nf NoopElectionFactory) NewElection(ctx context.Context, treeID int64) (MasterElection, error)

NewElection creates a specific NoopElection instance.

type SystemTimeSource

type SystemTimeSource struct{}

SystemTimeSource provides the current system local time

func (SystemTimeSource) Now

func (s SystemTimeSource) Now() time.Time

Now returns the true current local time.

type TimeSource

type TimeSource interface {
	// Now returns the current time in real implementations or a suitable value in others
	Now() time.Time
}

TimeSource can provide the current time, or be replaced by a mock in tests to return specific values.

Directories

Path Synopsis
Package etcd holds an etcd-specific implementation of the util.MasterElection interface.
Package etcd holds an etcd-specific implementation of the util.MasterElection interface.
Package flagsaver provides a simple way to save and restore flag values.
Package flagsaver provides a simple way to save and restore flag values.
Package proxy forwards Trillian Log Server requests to another server.
Package proxy forwards Trillian Log Server requests to another server.

Jump to

Keyboard shortcuts

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