Documentation ¶
Overview ¶
Package agree helps you distribute any data structure using Raft.
Index ¶
- Variables
- type Callback
- type Command
- type Config
- type ConsistencyLevel
- type ForwardingClient
- type Mutation
- type Wrapper
- func (w *Wrapper) AddNode(addr string) error
- func (w *Wrapper) Marshal() ([]byte, error)
- func (w *Wrapper) Mutate(method string, args ...interface{}) error
- func (w *Wrapper) Read(method string, c ConsistencyLevel, args ...interface{}) (interface{}, error)
- func (w *Wrapper) RemoveNode(addr string) error
- func (w *Wrapper) SubscribeChan(method string, c chan *Mutation)
- func (w *Wrapper) SubscribeFunc(method string, f Callback)
Constants ¶
This section is empty.
Variables ¶
var ( //ErrMethodNotFound is the error that is returned if you try to apply a method that the type does not have. ErrMethodNotFound = errors.New("Cannot apply the method as it was not found") //DefaultRaftDirectory is the default directory where raft files should be stored. DefaultRaftDirectory = "." //DefaultRetainSnapshotCount is the number of Raft snapsnots that will be retained. DefaultRetainSnapshotCount = 2 )
var ( //ErrNotLeader is returned when a Command is mistakenly sent to a follower. You should never receive this as Go-Agree takes care of following commands to the leader. ErrNotLeader = errors.New("Commands should be sent to leader and cannot be sent to followers") //ErrIncorrectType is returned when a Raft snapshot cannot be unmarshalled to the expected type. ErrIncorrectType = errors.New("Snapshot contained data of an incorrect type") //ErrTooManyalues is returned when a Read() method returns more than one value (plus optional error return) ErrTooManyalues = errors.New("Method returned too many values") )
Functions ¶
This section is empty.
Types ¶
type Callback ¶
type Callback func(m Mutation)
Callback is a callback function that is invoked when you subscribe to mutations using Wrapper.SusbcribeFunc() and a mutation occurs. The args contain the details of the mutation that just occurred.
type Config ¶
type Config struct { Peers []string // List of peers. Peers' raft ports can be different but the forwarding port must be the same for each peer in the cluster. RaftConfig *raft.Config // Raft configuration, see github.com/hashicorp/raft. Default raft.DefaultConfig() RaftBind string // Where to bind Raft, default ":8080" RaftDirectory string // Where Raft files will be stored RetainSnapshotCount int // How many Raft snapshots to retain // contains filtered or unexported fields }
Config is a configuration struct that is passed to Wrap(). It specifies Raft settings and command forwarding port.
type ConsistencyLevel ¶
type ConsistencyLevel int
ConsistencyLevel describes how consistent we want our reads to be
const ( //Any means that stale reads are allowed Any ConsistencyLevel = iota //Leader means that there is a short window of inconsistency but requires no network round trip to verify leadership Leader ConsistencyLevel = iota //Consistent means a linearizable read. It requires a network round trip on every read. Consistent ConsistencyLevel = iota )
type ForwardingClient ¶
type ForwardingClient struct {
// contains filtered or unexported fields
}
ForwardingClient is a client that forwards commands to the Raft leader. Should not be used, the only reason it is exported is because the rpc package requires it.
func (*ForwardingClient) AddPeer ¶
func (r *ForwardingClient) AddPeer(addr string, reply *int) error
AddPeer accepts a forwarded request to add a peer, sent to the Raft leader.
func (*ForwardingClient) Apply ¶
func (r *ForwardingClient) Apply(cmd []byte, reply *int) error
Apply forwards the given mutating Command to the Raft leader.
func (*ForwardingClient) Read ¶
func (r *ForwardingClient) Read(cmd []byte, reply interface{}) error
Read forwards the given read to the Raft leader.
func (ForwardingClient) RemovePeer ¶
func (r ForwardingClient) RemovePeer(addr string, reply *int) error
RemovePeer accepts a forwarded request to remove a peer, sent to the Raft leader.
type Mutation ¶
type Mutation struct { NewValue interface{} // The new, mutated wrapped value Method string // The name of the method passed to Mutate() MethodArgs []interface{} // The arguments the method was called with }
Mutation is passed to observers to notify them of mutations. Observers should not mutate NewValue.
type Wrapper ¶
Wrapper is a wrapper for the datastructure you want to distribute. It inherics from sync/RWMutex and if you retained a pointer to the interface before you passed it to Wrap(), you should RLock()/RUnlock() the wrapper whenever you access the interface's value outside Go-Agree's helper methods.
func Wrap ¶
Wrap returns a wrapper for your type. Type methods should have JSON-marshallable arguments.
func (*Wrapper) AddNode ¶
AddNode adds a node, located at addr, to the cluster. The node must be ready to respond to Raft commands at the address.
func (*Wrapper) Read ¶
func (w *Wrapper) Read(method string, c ConsistencyLevel, args ...interface{}) (interface{}, error)
Read invokes the specified method on the wrapped interface, at the given consistency level. The invoked method should return a single value or a single value followed by an error. The method should **not** mutate the value of the wrapper as this mutation is not committed to the Raft log. To mutate the value use Mutate() instead.
func (*Wrapper) RemoveNode ¶
RemoveNode removes a node, located at addr, from the cluster.
func (*Wrapper) SubscribeChan ¶
SubscribeChan sends values to the returned channel when the underlying structure is mutated. The callback should not mutate the interface or strange things will happen.
func (*Wrapper) SubscribeFunc ¶
SubscribeFunc executes the `Callback` func when the distributed object is mutated by applying `Mutate` on `method`. The callback should not mutate the interface or strange things will happen.