added etcd kv

This commit is contained in:
ston1th 2020-11-15 22:02:23 +01:00
commit fd9f8fc1fd
8 changed files with 54 additions and 71 deletions

View file

@ -18,10 +18,10 @@ type kv struct {
r *raft.Raft
}
func (kv *kv) Get(k string) []byte {
func (kv *kv) Get(k string) ([]byte, error) {
kv.mu.Lock()
defer kv.mu.Unlock()
return kv.m[k]
return kv.m[k], nil
}
func (kv *kv) Set(k string, v []byte) error {

View file

@ -155,6 +155,10 @@ func (c *Cluster) Start(raftcfg *config.Config) error {
if leading {
c.r.LeadershipTransfer().Error()
}
if c.callbacks.Cleanup != nil {
ctx, _ := context.WithTimeout(context.Background(), time.Second*2)
c.callbacks.Cleanup(ctx, c)
}
close(c.done)
return nil
}