raftkv

package
v0.0.0-...-8f2cee6 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OK       = "OK"
	ErrNoKey = "ErrNoKey"
)
View Source
const Debug = 0

Variables

This section is empty.

Functions

func DPrintf

func DPrintf(format string, a ...interface{}) (n int, err error)

Types

type Clerk

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

func MakeClerk

func MakeClerk(servers []labrpc.Client) *Clerk

func (*Clerk) Append

func (ck *Clerk) Append(key string, value string)

func (*Clerk) Get

func (ck *Clerk) Get(key string) string

fetch the current value for a key. returns "" if the key does not exist. keeps trying forever in the face of all other errors.

you can send an RPC with code like this: ok := ck.servers[i].Call("RaftKV.Get", &args, &reply)

the types of args and reply (including whether they are pointers) must match the declared types of the RPC handler function's arguments. and reply must be passed as a pointer.

func (*Clerk) Put

func (ck *Clerk) Put(key string, value string)

func (*Clerk) PutAppend

func (ck *Clerk) PutAppend(key string, value string, op string)

shared by Put and Append.

you can send an RPC with code like this: ok := ck.servers[i].Call("RaftKV.PutAppend", &args, &reply)

the types of args and reply (including whether they are pointers) must match the declared types of the RPC handler function's arguments. and reply must be passed as a pointer.

type Err

type Err string

type GetArgs

type GetArgs struct {
	Key string

	ClientID int64
	ReqID    int
}

func (GetArgs) String

func (obj GetArgs) String() string

type GetReply

type GetReply struct {
	WrongLeader bool
	Err         Err
	Value       string
}

func (GetReply) String

func (obj GetReply) String() string

type Op

type Op struct {
	ReqType  string
	Key      string
	Value    string
	ClientID int64
	ReqID    int
}

func (Op) String

func (obj Op) String() string

type PubSub

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

func NewPubSub

func NewPubSub() *PubSub

func (*PubSub) Publish

func (ps *PubSub) Publish(topic int, op Op)

func (*PubSub) Subscribe

func (ps *PubSub) Subscribe(topic int) <-chan Op

type PutAppendArgs

type PutAppendArgs struct {
	// You'll have to add definitions here.
	Key   string
	Value string
	Op    string // "Put" or "Append"

	ClientID int64
	ReqID    int
}

Put or Append

func (PutAppendArgs) String

func (obj PutAppendArgs) String() string

type PutAppendReply

type PutAppendReply struct {
	WrongLeader bool
	Err         Err
}

func (PutAppendReply) String

func (obj PutAppendReply) String() string

type RaftKV

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

func StartKVServer

func StartKVServer(servers []labrpc.Client, me int, persister *raft.Persister, maxraftstate int) *RaftKV

servers[] contains the ports of the set of servers that will cooperate via Raft to form the fault-tolerant key/value service. me is the index of the current server in servers[]. the k/v server should store snapshots with persister.SaveSnapshot(), and Raft should save its state (including log) with persister.SaveRaftState(). the k/v server should snapshot when Raft's saved state exceeds maxraftstate bytes, in order to allow Raft to garbage-collect its log. if maxraftstate is -1, you don't need to snapshot. StartKVServer() must return quickly, so it should start goroutines for any long-running work.

func (*RaftKV) AppendEntryToLog

func (kv *RaftKV) AppendEntryToLog(entry Op) bool

func (*RaftKV) Get

func (kv *RaftKV) Get(args *GetArgs, reply *GetReply) error

func (*RaftKV) Kill

func (kv *RaftKV) Kill()

the tester calls Kill() when a RaftKV instance won't be needed again. you are not required to do anything in Kill(), but it might be convenient to (for example) turn off debug output from this instance.

func (*RaftKV) PutAppend

func (kv *RaftKV) PutAppend(args *PutAppendArgs, reply *PutAppendReply) error

Jump to

Keyboard shortcuts

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