cmd

package
v0.0.0-...-5c9d26a Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FOLLOWER  ServerState = "FOLLOWER"
	CANDIDATE             = "CANDIDATE"
	LEADER                = "LEADER"
)
View Source
const (
	PUT    = "PUT"
	DELETE = "DELETE"
	GET    = "GET"
)

Variables

This section is empty.

Functions

func CallRemoteNode

func CallRemoteNode(coords *Coords, nodesToSendRPC []string, command, key, value string) chan *AppendResult

func Execute

func Execute()

func GetKey

func GetKey(w http.ResponseWriter, r *http.Request)

func Run

func Run(cmd *cobra.Command, args []string)

func SetKey

func SetKey(coords *Coords) func(http.ResponseWriter, *http.Request)

SetKey will set the value for the respective key

Types

type AppendArgument

type AppendArgument struct {
	Term              int
	LeaderId          string
	PrevLogIndex      int
	PrevLogTerm       int
	Entries           []LogEntry
	LeaderCommitIndex int
}

type AppendResult

type AppendResult struct {
	Term    int
	Success bool
}

type Coords

type Coords struct {
	State    ServerState
	Term     int
	VotedFor interface{} // interface because it can be string or nil
	Log      []LogEntry
}

func NewCoords

func NewCoords() *Coords

func (*Coords) AppendEntry

func (c *Coords) AppendEntry(appendArg *AppendArgument, state *AppendResult) error

func (*Coords) RequestVote

func (c *Coords) RequestVote(voteArg *VoteArgument, result *VoteResult) error

type LogEntry

type LogEntry struct {
	Term    int         `json:"-"`
	Command string      `json:"-"`
	Key     string      `json:"key"`
	Value   interface{} `json:"value"`
}

type RequestValueWithKey

type RequestValueWithKey struct {
	Key string
}

type ServerState

type ServerState string

type UpdateKey

type UpdateKey struct {
	Key   string
	Value string
}

type VoteArgument

type VoteArgument struct {
	Term         int
	CandidateId  string
	LastLogIndex int
	LastLogTerm  int
}

type VoteResult

type VoteResult struct {
	Term        int
	VoteGranted bool
}

Jump to

Keyboard shortcuts

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