shardkv

package
v0.0.0-...-d482dbc Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OK             = "OK"
	ErrNoKey       = "ErrNoKey"
	ErrWrongGroup  = "ErrWrongGroup"
	ErrWrongLeader = "ErrWrongLeader"
)
View Source
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"
)
View Source
const (
	TIMEOUT = 100 // 100 millseconds
)

Variables

This section is empty.

Functions

func Debug

func Debug(topic logTopic, format string, a ...interface{})

Types

type CfgiData

type CfgiData [shardctrler.NShards]Shard // store the shard for on config num

func (*CfgiData) Copy

func (cfgidata *CfgiData) Copy() CfgiData

type Clerk

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

func MakeClerk

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

测试程序会调用MakeClerk函数。 ctrlers[] 数组用于调用 shardctrler.MakeClerk() 函数。 make_end(servername) 函数将 Config.Groups[gid][i] 中的服务器名称转换为可以发送 RPC 请求的 labrpc.ClientEnd 对象。

func (*Clerk) Append

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

func (*Clerk) Get

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

获取指定键的当前值。 如果该键不存在,则返回 ""。 在遇到其他所有错误时,函数将一直尝试。 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)

Put 和 Append 共用的代码。 You will have to modify this function.

type Err

type Err string

type GCArgs

type GCArgs struct {
	CfgNum  int
	ShardId int
}

type GCReply

type GCReply struct {
	Error Err
}

type GetArgs

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

type GetReply

type GetReply struct {
	Err   Err
	Value string
}

type GetShardArgs

type GetShardArgs struct {
	ShardId   int
	ConfigNum int
}

type GetShardReply

type GetShardReply struct {
	Shard Shard
	Error Err
}

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 OpResult

type OpResult struct {
	Error Err
	Value string
}

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 Shard struct {
	Data               map[string]string
	Client_to_last_req map[int64]uint64
	Client_to_last_res map[int64]OpResult
	Status             Status
}

func (*Shard) Copy

func (sd *Shard) Copy() 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) CheckAcqShard

func (kv *ShardKV) CheckAcqShard()

周期性根据当前状态检查是否需要从其他group拉取shard

func (*ShardKV) CheckStatus

func (kv *ShardKV) CheckStatus() bool

check whethe change from last_config to cur_config is all working

func (*ShardKV) DeSerilizeState

func (kv *ShardKV) DeSerilizeState(snapshot []byte)

func (*ShardKV) GC

func (kv *ShardKV) GC(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) 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()

func (*ShardKV) SendAcqShard

func (kv *ShardKV) SendAcqShard(shardId int, servers []string, cfgNum int)

type Status

type Status string
const (
	WORKING Status = "woring"
	ACQUING Status = "acquring"
	EXPIRED Status = "expired"
	INVALID Status = "invalid"
)

Jump to

Keyboard shortcuts

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