Documentation
¶
Index ¶
- Constants
- func Debug(topic logTopic, format string, a ...interface{})
- type CfgiData
- type Clerk
- type Err
- type GCArgs
- type GCReply
- type GetArgs
- type GetReply
- type GetShardArgs
- type GetShardReply
- type Op
- type OpResult
- type PutAppendArgs
- type PutAppendReply
- type Shard
- type ShardKV
- func (kv *ShardKV) AcquireShard(args *GetShardArgs, reply *GetShardReply)
- func (kv *ShardKV) CheckAcqShard()
- func (kv *ShardKV) CheckStatus() bool
- func (kv *ShardKV) DeSerilizeState(snapshot []byte)
- func (kv *ShardKV) GC(args *GCArgs, reply *GCReply)
- func (kv *ShardKV) Get(args *GetArgs, reply *GetReply)
- func (kv *ShardKV) Kill()
- func (kv *ShardKV) PullConfig()
- func (kv *ShardKV) PutAppend(args *PutAppendArgs, reply *PutAppendReply)
- func (kv *ShardKV) ResetStatus()
- func (kv *ShardKV) SendAcqShard(shardId int, servers []string, cfgNum int)
- type Status
Constants ¶
const ( OK = "OK" ErrNoKey = "ErrNoKey" ErrWrongGroup = "ErrWrongGroup" ErrWrongLeader = "ErrWrongLeader" )
const ( GET = "Get" PUT = "Put" APPEND = "Append" PUTAPP = "PUTAPPEND" CHANGE_CONFIG = "CHANGE_CONFIG" GET_NEW_SHARD = "GET_NEW_SHARD" CHANGE_SHARD = "CHANGE_SHARD" GC = "GC" )
const (
TIMEOUT = 100 // 100 millseconds
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CfgiData ¶
type CfgiData [shardctrler.NShards]Shard // store the shard for on config num
type Clerk ¶
type Clerk struct {
// contains filtered or unexported fields
}
func MakeClerk ¶
测试程序会调用MakeClerk函数。 ctrlers[] 数组用于调用 shardctrler.MakeClerk() 函数。 make_end(servername) 函数将 Config.Groups[gid][i] 中的服务器名称转换为可以发送 RPC 请求的 labrpc.ClientEnd 对象。
type GetShardArgs ¶
type GetShardReply ¶
type Op ¶
type Op struct { // Your definitions here. // Field names must start with capital letters, // otherwise RPC will break. Type string Key string Value string NewConfig shardctrler.Config NewShardCfgNum int NewShardId int NewShard Shard GCCfgNum int GCShardID int ClientId int64 ClientSeq uint64 ServerSeq int64 }
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 ClientSeq uint64 }
Put or Append
type PutAppendReply ¶
type PutAppendReply struct {
Err Err
}
type Shard ¶
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, ctrlers []*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 shardctrler.
pass ctrlers[] to shardctrler.MakeClerk() so you can send RPCs to the shardctrler.
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 ctrlers[] 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) AcquireShard ¶
func (kv *ShardKV) AcquireShard(args *GetShardArgs, reply *GetShardReply)
func (*ShardKV) CheckStatus ¶
check whethe change from last_config to cur_config is all working
func (*ShardKV) DeSerilizeState ¶
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) PullConfig ¶
func (kv *ShardKV) PullConfig()
pull new config from master periodically
func (*ShardKV) PutAppend ¶
func (kv *ShardKV) PutAppend(args *PutAppendArgs, reply *PutAppendReply)
func (*ShardKV) ResetStatus ¶
func (kv *ShardKV) ResetStatus()