From 74d6df2bd6e0ca17e21262d01ff2bb32cc0622fb Mon Sep 17 00:00:00 2001 From: Trung Nguyen Date: Thu, 21 Feb 2019 15:00:38 -0500 Subject: [PATCH 1/2] raftexample: added build instruction and minor refactoring --- contrib/raftexample/README.md | 10 ++++++++++ contrib/raftexample/kvstore.go | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/contrib/raftexample/README.md b/contrib/raftexample/README.md index 312adeb9c2e..90fe59ee2c3 100644 --- a/contrib/raftexample/README.md +++ b/contrib/raftexample/README.md @@ -6,6 +6,16 @@ raftexample is an example usage of etcd's [raft library](../../raft). It provide ## Getting Started +### Building raftexample + +Clone `etcd` to `/src/go.etcd.io/etcd` + +```sh +export GOPATH= +cd /src/go.etcd.io/etcd/contrib/raftexample +go build -o raftexample +``` + ### Running single node raftexample First start a single-member cluster of raftexample: diff --git a/contrib/raftexample/kvstore.go b/contrib/raftexample/kvstore.go index b56dcb31aec..b057501a40a 100644 --- a/contrib/raftexample/kvstore.go +++ b/contrib/raftexample/kvstore.go @@ -48,8 +48,8 @@ func newKVStore(snapshotter *snap.Snapshotter, proposeC chan<- string, commitC < func (s *kvstore) Lookup(key string) (string, bool) { s.mu.RLock() + defer s.mu.RUnlock() v, ok := s.kvStore[key] - s.mu.RUnlock() return v, ok } @@ -106,7 +106,7 @@ func (s *kvstore) recoverFromSnapshot(snapshot []byte) error { return err } s.mu.Lock() + defer s.mu.Unlock() s.kvStore = store - s.mu.Unlock() return nil } From 5b4ff6c6d555586c945d38a4441015db5d1281e7 Mon Sep 17 00:00:00 2001 From: Trung Nguyen Date: Thu, 21 Feb 2019 16:56:52 -0500 Subject: [PATCH 2/2] raftexample: update readme --- contrib/raftexample/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/raftexample/README.md b/contrib/raftexample/README.md index 90fe59ee2c3..2e73996a6a6 100644 --- a/contrib/raftexample/README.md +++ b/contrib/raftexample/README.md @@ -8,11 +8,11 @@ raftexample is an example usage of etcd's [raft library](../../raft). It provide ### Building raftexample -Clone `etcd` to `/src/go.etcd.io/etcd` +Clone `etcd` to `/src/go.etcd.io/etcd` ```sh -export GOPATH= -cd /src/go.etcd.io/etcd/contrib/raftexample +export GOPATH= +cd /src/go.etcd.io/etcd/contrib/raftexample go build -o raftexample ```