mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raftexample: added build instruction and minor refactoring
This commit is contained in:
parent
8c228d692b
commit
74d6df2bd6
@ -6,6 +6,16 @@ raftexample is an example usage of etcd's [raft library](../../raft). It provide
|
|||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
|
|
||||||
|
### Building raftexample
|
||||||
|
|
||||||
|
Clone `etcd` to `<your directory>/src/go.etcd.io/etcd`
|
||||||
|
|
||||||
|
```sh
|
||||||
|
export GOPATH=<your directory>
|
||||||
|
cd <your directory>/src/go.etcd.io/etcd/contrib/raftexample
|
||||||
|
go build -o raftexample
|
||||||
|
```
|
||||||
|
|
||||||
### Running single node raftexample
|
### Running single node raftexample
|
||||||
|
|
||||||
First start a single-member cluster of raftexample:
|
First start a single-member cluster of raftexample:
|
||||||
|
@ -48,8 +48,8 @@ func newKVStore(snapshotter *snap.Snapshotter, proposeC chan<- string, commitC <
|
|||||||
|
|
||||||
func (s *kvstore) Lookup(key string) (string, bool) {
|
func (s *kvstore) Lookup(key string) (string, bool) {
|
||||||
s.mu.RLock()
|
s.mu.RLock()
|
||||||
|
defer s.mu.RUnlock()
|
||||||
v, ok := s.kvStore[key]
|
v, ok := s.kvStore[key]
|
||||||
s.mu.RUnlock()
|
|
||||||
return v, ok
|
return v, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ func (s *kvstore) recoverFromSnapshot(snapshot []byte) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
|
defer s.mu.Unlock()
|
||||||
s.kvStore = store
|
s.kvStore = store
|
||||||
s.mu.Unlock()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user