Documentation ¶
Index ¶
- Variables
- func GrowCluster(ctx context.Context, target Acceptor, proposers ...Proposer) error
- func ShrinkCluster(ctx context.Context, target Acceptor, proposers ...Proposer) error
- type Accepter
- type Acceptor
- type Addresser
- type Ballot
- type ChangeFunc
- type ConflictError
- type LocalProposer
- func (p *LocalProposer) AddAccepter(target Acceptor) error
- func (p *LocalProposer) AddPreparer(target Acceptor) error
- func (p *LocalProposer) Propose(ctx context.Context, key string, f ChangeFunc) (newState []byte, err error)
- func (p *LocalProposer) RemoveAccepter(target Acceptor) error
- func (p *LocalProposer) RemovePreparer(target Acceptor) error
- type MemoryAcceptor
- type Preparer
- type Proposer
Constants ¶
This section is empty.
Variables ¶
var ( // ErrPrepareFailed indicates a failure during the first "prepare" phase. ErrPrepareFailed = errors.New("not enough confirmations during prepare phase; proposer ballot was fast-forwarded") // ErrAcceptFailed indicates a failure during the first "accept" phase. ErrAcceptFailed = errors.New("not enough confirmations during accept phase") // ErrDuplicate indicates the same acceptor was added twice. ErrDuplicate = errors.New("duplicate") // ErrNotFound indicates an attempt to remove a non-present acceptor. ErrNotFound = errors.New("not found") )
Functions ¶
func GrowCluster ¶
GrowCluster adds the target acceptor to the cluster of proposers.
Types ¶
type Acceptor ¶
Acceptor models a complete, uniquely-addressable acceptor.
Here we have a little fun with names: use Acceptor (-or) as a noun, to model the whole composite acceptor, and Accepter (-er) as a verb, to model the second-phase "accept" responsibilities only.
type Addresser ¶
type Addresser interface {
Address() string // typically "protocol://host:port"
}
Addresser models something with a unique address.
type Ballot ¶
Ballot models a ballot number, which are maintained by proposers and cached by acceptors.
From the paper: "It's convenient to use tuples as ballot numbers. To generate it a proposer combines its numerical ID with a local increasing counter: (counter, ID)."
type ChangeFunc ¶
ChangeFunc models client change proposals.
type ConflictError ¶
ConflictError is returned by acceptors when there's a ballot conflict.
func (ConflictError) Error ¶
func (ce ConflictError) Error() string
type LocalProposer ¶
type LocalProposer struct {
// contains filtered or unexported fields
}
LocalProposer performs the initialization by communicating with acceptors, and keep minimal state needed to generate unique increasing update IDs (ballot numbers).
func NewLocalProposer ¶
func NewLocalProposer(id uint64, logger log.Logger, initial ...Acceptor) *LocalProposer
NewLocalProposer returns a usable Proposer uniquely identified by id. It communicates with the initial set of acceptors.
func (*LocalProposer) AddAccepter ¶
func (p *LocalProposer) AddAccepter(target Acceptor) error
AddAccepter adds the target acceptor to the pool of accepters used in the second phase of proposals. It's the first step in growing the cluster, which is a global process that needs to be orchestrated by an operator.
func (*LocalProposer) AddPreparer ¶
func (p *LocalProposer) AddPreparer(target Acceptor) error
AddPreparer adds the target acceptor to the pool of preparers used in the first phase of proposals. It's the third step in growing the cluster, which is a global process that needs to be orchestrated by an operator.
func (*LocalProposer) Propose ¶
func (p *LocalProposer) Propose(ctx context.Context, key string, f ChangeFunc) (newState []byte, err error)
Propose a change from a client into the cluster.
func (*LocalProposer) RemoveAccepter ¶
func (p *LocalProposer) RemoveAccepter(target Acceptor) error
RemoveAccepter removes the target acceptor from the pool of accepters used in the second phase of proposals. It's the third step in shrinking the cluster, which is a global process that needs to be orchestrated by an operator.
func (*LocalProposer) RemovePreparer ¶
func (p *LocalProposer) RemovePreparer(target Acceptor) error
RemovePreparer removes the target acceptor from the pool of preparers used in the first phase of proposals. It's the first step in shrinking the cluster, which is a global process that needs to be orchestrated by an operator.
type MemoryAcceptor ¶
type MemoryAcceptor struct {
// contains filtered or unexported fields
}
MemoryAcceptor persists data in-memory.
func NewMemoryAcceptor ¶
func NewMemoryAcceptor(addr string, logger log.Logger) *MemoryAcceptor
NewMemoryAcceptor returns a usable in-memory acceptor. Useful primarily for testing.
func (*MemoryAcceptor) Accept ¶
func (a *MemoryAcceptor) Accept(ctx context.Context, key string, b Ballot, value []byte) (err error)
Accept implements the second-phase responsibilities of an acceptor.
func (*MemoryAcceptor) Address ¶
func (a *MemoryAcceptor) Address() string
Address implements Addresser.
type Preparer ¶
type Preparer interface {
Prepare(ctx context.Context, key string, b Ballot) (value []byte, current Ballot, err error)
}
Preparer models the first-phase responsibilities of an acceptor.
type Proposer ¶
type Proposer interface { Propose(ctx context.Context, key string, f ChangeFunc) (newState []byte, err error) AddAccepter(target Acceptor) error AddPreparer(target Acceptor) error RemovePreparer(target Acceptor) error RemoveAccepter(target Acceptor) error }
Proposer models a concrete proposer.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package cluster provides an elastic peer discovery and gossip layer.
|
Package cluster provides an elastic peer discovery and gossip layer. |
cmd
|
|
Package httpapi implements a simple API as a tech demo.
|
Package httpapi implements a simple API as a tech demo. |