shardkv

package
v0.0.0-...-3e2643c Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2021 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OK             = "OK"
	ErrNoKey       = "ErrNoKey"
	ErrWrongGroup  = "ErrWrongGroup"
	ErrWrongLeader = "ErrWrongLeader"
)
View Source
const ChangeLeaderInterval = time.Millisecond * 10
View Source
const Debug = 0

Debugging

View Source
const WaitCommandInterval = time.Millisecond * 500

Variables

This section is empty.

Functions

func DPrintf

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

func Max

func Max(a, b int) int

Types

type Clerk

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

func MakeClerk

func MakeClerk(masters []*labrpc.ClientEnd, make_end func(string) *labrpc.ClientEnd) *Clerk

the tester calls MakeClerk.

masters[] is needed to call shardmaster.MakeClerk().

make_end(servername) turns a server name from a Config.Groups[gid][i] into a labrpc.ClientEnd on which you can send RPCs.

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 will have to modify this function.

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 will have to modify this function.

type Err

type Err string

type GCArgs

type GCArgs struct {
	Shard     int
	ConfigNum int
}

type GCReply

type GCReply struct {
	Err Err
}

type GetArgs

type GetArgs struct {
	Key string
	// You'll have to add definitions here.
	ClientId  int64
	RequestId int
}

type GetReply

type GetReply struct {
	Err   Err
	Value string
}

type MigrateArgs

type MigrateArgs struct {
	Shard     int
	ConfigNum int
}

type MigrateReply

type MigrateReply struct {
	Err         Err
	ConfigNum   int
	Shard       int
	DB          map[string]string
	LastApplies map[int64]int
}
4B:只是发SHARD DATA是不够的。比如一个APPEND REQUEST 在向A发送的时候,timeout了。这个时候A已经做了这个更新操作。在这个点之后,Reconfiguration 发生,

CLIENT 去问B发送APPEND REQ。如果只是SHARD DATA过去。会造成APPEND 2次。所以我们还需要把用于去重的map(LastApplies)也一起发过去。

type Op

type Op struct {
	// Your definitions here.
	// Field names must start with capital letters,
	// otherwise RPC will break.
	Key       string
	Value     string
	Type      string
	ClientId  int64
	RequestId int
}

type PutAppendArgs

type PutAppendArgs struct {
	// You'll have to add definitions here.
	Key   string
	Value string
	Op    string // "Put" or "Append"
	// You'll have to add definitions here.
	// Field names must start with capital letters,
	// otherwise RPC will break.
	ClientId  int64
	RequestId int
}

Put or Append

type PutAppendReply

type PutAppendReply struct {
	Err Err
}

type ShardKV

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

func StartServer

func StartServer(servers []*labrpc.ClientEnd, me int, persister *raft.Persister, maxraftstate int, gid int, masters []*labrpc.ClientEnd, make_end func(string) *labrpc.ClientEnd) *ShardKV

servers[] contains the ports of the servers in this group.

me is the index of the current server in servers[].

the k/v server should store snapshots through the underlying Raft implementation, which should call persister.SaveStateAndSnapshot() to atomically save the Raft state along with the snapshot.

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.

gid is this group's GID, for interacting with the shardmaster.

pass masters[] to shardmaster.MakeClerk() so you can send RPCs to the shardmaster.

make_end(servername) turns a server name from a Config.Groups[gid][i] into a labrpc.ClientEnd on which you can send RPCs. You'll need this to send RPCs to other groups.

look at client.go for examples of how to use masters[] and make_end() to send RPCs to the group owning a specific shard.

StartServer() must return quickly, so it should start goroutines for any long-running work.

func (*ShardKV) GarbageCollection

func (kv *ShardKV) GarbageCollection(args *GCArgs, reply *GCReply)

func (*ShardKV) Get

func (kv *ShardKV) Get(args *GetArgs, reply *GetReply)

func (*ShardKV) Kill

func (kv *ShardKV) Kill()

the tester calls Kill() when a ShardKV 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 (*ShardKV) PutAppend

func (kv *ShardKV) PutAppend(args *PutAppendArgs, reply *PutAppendReply)

func (*ShardKV) ShardMigration

func (kv *ShardKV) ShardMigration(args *MigrateArgs, reply *MigrateReply)

需要发送shard的Server接收到请求,将自己要发送的shards做一个deepCopy,然后

Jump to

Keyboard shortcuts

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