shardkv

package
v0.0.0-...-ae99a8b Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OK                 = "OK"
	ErrNoKey           = "ErrNoKey"
	ErrWrongGroup      = "ErrWrongGroup"
	ErrWrongLeader     = "ErrWrongLeader"
	ErrTimeout         = "ErrTimeout"
	ErrConfigNotMatch  = "ErrConfigNotMatch"
	ErrAlreadyMigrated = "ErrAlreadyMigrated"
)
View Source
const (
	WaitForConfigConsistentTimeOut = time.Millisecond * 500
	TryNextGroupServerInterval     = time.Millisecond * 50
)
View Source
const (
	WaitOpTimeOut      = time.Millisecond * 500
	ReconfigTimeOut    = time.Millisecond * 100
	WaitMigrateTimeOut = time.Millisecond * 100
	QueryConfigTimeout = time.Millisecond * 2500
)
View Source
const (
	GET                  = "Get"
	PUT                  = "Put"
	APPEND               = "Append"
	MIGRATESHARDS        = "MigrateShards"
	UPDATECONFIG         = "UpdateConfig"
	GETCONFIG            = "GetConfig"
	GETSHARDSDATA        = "GetShardsData"
	GETMIGRATINGSARDS    = "GetMigratingShards"
	GETRECEIVEDSHARDS    = "GetReceivedShards"
	UPDATEMIGRATINGSARDS = "UpdateMigratingShards"
	GETRECEIVECONFIGNUM  = "GetReceiveConfigNum"
)

Variables

This section is empty.

Functions

This section is empty.

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 ClerkMsgId

type ClerkMsgId int64

type Err

type Err string

type ExeResult

type ExeResult struct {
	Err              Err
	Value            string
	Config           shardmaster.Config
	ShardsKvData     map[string]string
	MigratingShards  []int
	ReceivedShards   []int
	ReceiveConfigNum map[int]int
}

type GetArgs

type GetArgs struct {
	Key string
	// You'll have to add definitions here.
	ClientId TypeClientId
	MsgId    ClerkMsgId

	Shard int
}

type GetConfigArgs

type GetConfigArgs struct {
	ClientId TypeClientId
	MsgId    ClerkMsgId
}

type GetConfigReply

type GetConfigReply struct {
	Err    Err
	Config shardmaster.Config
}

type GetMigratingShardsArgs

type GetMigratingShardsArgs struct {
	ClientId TypeClientId
	MsgId    ClerkMsgId
}

type GetMigratingShardsReply

type GetMigratingShardsReply struct {
	Err             Err
	MigratingShards []int
}

type GetReceiveConfigNumArgs

type GetReceiveConfigNumArgs struct {
	ClientId TypeClientId
	MsgId    ClerkMsgId
}

type GetReceiveConfigNumReply

type GetReceiveConfigNumReply struct {
	Err              Err
	ReceiveConfigNum map[int]int
}

type GetReceivedShardsArgs

type GetReceivedShardsArgs struct {
	ClientId TypeClientId
	MsgId    ClerkMsgId
}

type GetReceivedShardsReply

type GetReceivedShardsReply struct {
	Err            Err
	ReceivedShards []int
}

type GetReply

type GetReply struct {
	Err   Err
	Value string
}

type GetShardsDataArgs

type GetShardsDataArgs struct {
	Shards   []int
	ClientId TypeClientId
	MsgId    ClerkMsgId
}

type GetShardsDataReply

type GetShardsDataReply struct {
	Err        Err
	ShardsData map[string]string
}

type Method

type Method string

type MigrateShardsArgs

type MigrateShardsArgs struct {
	ShardsKvData map[string]string
	ConfigNum    int
	FromGid      int
	IsNewGroup   bool
	Shards       []int
	ClientId     TypeClientId
	MsgId        ClerkMsgId
}

type MigrateShardsReply

type MigrateShardsReply struct {
	Err Err
}

type Op

type Op struct {
	Method Method

	DataShard int

	Key   string
	Value string

	ClientId TypeClientId
	MsgId    ClerkMsgId

	// ServerId + OpId is unique for each op
	ServerId int
	OpId     TypeOpId

	// for Migrate
	ShardsKvData  map[string]string
	ConfigNum     int
	OldGid        int
	IsNewGroup    bool
	MigrateShards []int

	// for UpdateConfig
	Config       shardmaster.Config
	DeleteShards []int

	// for GetShardsData
	GetShards []int

	// for UpdateMigratingShards
	MigratingShards []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 TypeClientId
	MsgId    ClerkMsgId

	Shard 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) CallGetConfig

func (kv *ShardKV) CallGetConfig() shardmaster.Config

internal virtual client caller

func (*ShardKV) CallGetMigratingShards

func (kv *ShardKV) CallGetMigratingShards() []int

internal virtual client caller

func (*ShardKV) CallGetReceivedShards

func (kv *ShardKV) CallGetReceivedShards() []int

internal virtual client caller (this is not used temporarily)

func (*ShardKV) CallGetShardsData

func (kv *ShardKV) CallGetShardsData(shards []int) map[string]string

internal virtual client caller

func (*ShardKV) CallUpdateConfig

func (kv *ShardKV) CallUpdateConfig(config shardmaster.Config, deleteShards []int)

internal virtual client caller

func (*ShardKV) CallUpdateMigratingShards

func (kv *ShardKV) CallUpdateMigratingShards(migratingShards []int)

internal virtual client caller

func (*ShardKV) Get

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

outside client request

func (*ShardKV) GetConfig

func (kv *ShardKV) GetConfig(args *GetConfigArgs, reply *GetConfigReply)

only for internal request

func (*ShardKV) GetMigratingShards

func (kv *ShardKV) GetMigratingShards(args *GetMigratingShardsArgs, reply *GetMigratingShardsReply)

only for internal request

func (*ShardKV) GetReceiveConfigNum

func (kv *ShardKV) GetReceiveConfigNum(args *GetReceiveConfigNumArgs, reply *GetReceiveConfigNumReply)

only for internal request

func (*ShardKV) GetReceivedShards

func (kv *ShardKV) GetReceivedShards(args *GetReceivedShardsArgs, reply *GetReceivedShardsReply)

only for internal request

func (*ShardKV) GetShardsData

func (kv *ShardKV) GetShardsData(args *GetShardsDataArgs, reply *GetShardsDataReply)

only for internal request

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) MigrateShards

func (kv *ShardKV) MigrateShards(args *MigrateShardsArgs, reply *MigrateShardsReply)

Shard KV RPCs

func (*ShardKV) PutAppend

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

outside client request

func (*ShardKV) UpdateConfig

func (kv *ShardKV) UpdateConfig(args *UpdateConfigArgs, reply *UpdateConfigReply)

only for internal request

func (*ShardKV) UpdateMigratingShards

func (kv *ShardKV) UpdateMigratingShards(args *UpdateMigratingShardsArgs, reply *UpdateMigratingShardsReply)

only for internal request

type TypeClientId

type TypeClientId int64

type TypeOpId

type TypeOpId int64

type UpdateConfigArgs

type UpdateConfigArgs struct {
	Config       shardmaster.Config
	DeleteShards []int
	ClientId     TypeClientId
	MsgId        ClerkMsgId
}

type UpdateConfigReply

type UpdateConfigReply struct {
	Err Err
}

type UpdateMigratingShardsArgs

type UpdateMigratingShardsArgs struct {
	MigratingShards []int
	ClientId        TypeClientId
	MsgId           ClerkMsgId
}

type UpdateMigratingShardsReply

type UpdateMigratingShardsReply struct {
	Err Err
}

Jump to

Keyboard shortcuts

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