Skip to content

Commit

Permalink
Merge pull request etcd-io#10496 from trung/raft-example
Browse files Browse the repository at this point in the history
raftexample: added build instruction  and minor refactoring
  • Loading branch information
xiang90 authored Feb 26, 2019
2 parents 5effa15 + 5b4ff6c commit a7e3bd0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions contrib/raftexample/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ raftexample is an example usage of etcd's [raft library](../../raft). It provide

## Getting Started

### Building raftexample

Clone `etcd` to `<directory>/src/go.etcd.io/etcd`

```sh
export GOPATH=<directory>
cd <directory>/src/go.etcd.io/etcd/contrib/raftexample
go build -o raftexample
```

### Running single node raftexample

First start a single-member cluster of raftexample:
Expand Down
4 changes: 2 additions & 2 deletions contrib/raftexample/kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

0 comments on commit a7e3bd0

Please sign in to comment.