Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var SafetyDelta = uint64(100 * time.Millisecond)
SafetyDelta is the period of time that a heart beat should be late after the remthreshold for the cleaner to remove it.
var Timeout = 5 * time.Second
The timeout to execute Raft commands
Functions ¶
func NewInMemStore ¶
func NewInMemStore() *inMemStore
Types ¶
type CleanableResource ¶
type CleanableResource interface {
GetResources() map[string]*ServiceEntry
}
CleanableResource represents a resource (services) accessible by the cleanup service.
type Command ¶
type Command struct { Type string `json:"type"` Key string `json:"key"` // some commands don't have a value such as `DELETE` and `GET` Value string `json:"value,omitempty"` }
Command is what we will use to change the state of the Replicate state machine. The type field defines how the message is going to be interpreted by the system.
type DelRequest ¶
type DelRequest struct { Name string Instance InstanceEntry }
type HttpServer ¶
type HttpServer struct {
// contains filtered or unexported fields
}
HttpServer is the component that will interact with the outside world through a REST API to perform different operations:
- Perform `Join` requests from other nodes that will later join the cluster (if this is a leader)
- Reply to client requests to investigate the state of the key-value store.
func NewServer ¶
func NewServer(addr string, node *Node) *HttpServer
NewServer will create a new `HttpServer` that will listen on `addr` later on after `Start` is Called.
func (*HttpServer) ServeHTTP ¶
func (s *HttpServer) ServeHTTP(res http.ResponseWriter, req *http.Request)
ServeHTTP is an implementation of the `http.Handler` interface to process incoming client requets.
func (*HttpServer) Shutdown ¶
func (s *HttpServer) Shutdown()
Shutdown will be used for graceful shutdown.
func (*HttpServer) Start ¶
func (s *HttpServer) Start() error
Start will start listening for incoming client requests. The HttpServer will create and run in it's own goroutine.
type InstanceEntry ¶
type InstanceRegistration ¶
type JoinRequest ¶
JoinRequest is the message received by the API to handle new nodes joining the cluster.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
func NewNode ¶
func NewNode(id, dataDir, raftAddr string, store StorageEngine) *Node
type ServiceEntry ¶
type ServiceEntry struct { Name string Instances []*InstanceEntry }
type ServicesResponse ¶
type ServicesResponse struct {
Services []Service
}
ServicesResponse is the message returned by the leader when the `/services` endpoint is queried.
type StorageEngine ¶
type StorageEngine interface { // Inherit the behaviour of a Raft state machine. raft.FSM // Inherit the CleanableReource CleanableResource // Put the key-value pair into the underlying storage, and return an error if it's not possible to // finish the operation. Put(string, string) error // Get the value identified by the given key. Get(string) (string, error) // Delete the value identifier by the given key from the underlying storage, // and return it. Delete(string) (string, error) // GetServices will return the list of known live services to the heartbeat service // at query time. GetServices() *ServicesResponse // RegisterInstance will update the store's service list with the new // instance, This is usually resulting from a new service starting somewhere, // and doing a heartbeat request. RegisterInstance(InstanceRegistration) // DeleteInstance will delete the corresponding entry (instance) from the replicated // state machine DeleteInstance(string, InstanceEntry) }
A storage engine abstraction over the key-value store.
The engine can be thought of as a Finite state machine that can be fed into the Raft cluster.