Merge pull request #1864 from influxdb/fix-1180
fix #1180: race in startStateLooppull/1849/merge v0.9.0-rc9
commit
3454523bae
|
@ -3,6 +3,7 @@
|
|||
### Bugfixes
|
||||
|
||||
- [#1867](https://github.com/influxdb/influxdb/pull/1867): Fix race accessing topic replicas map
|
||||
- [#1864](https://github.com/influxdb/influxdb/pull/1864): fix race in startStateLoop
|
||||
|
||||
## v0.9.0-rc8 [2015-03-05]
|
||||
|
||||
|
|
18
raft/log.go
18
raft/log.go
|
@ -14,7 +14,6 @@ import (
|
|||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
@ -629,20 +628,21 @@ func (l *Log) Leave() error {
|
|||
// Returns once the state has transitioned to the initial state passed in.
|
||||
func (l *Log) startStateLoop(closing <-chan struct{}, state State) {
|
||||
l.wg.Add(1)
|
||||
go l.stateLoop(closing, state)
|
||||
stateChanged := make(chan struct{})
|
||||
go l.stateLoop(closing, state, stateChanged)
|
||||
|
||||
// Wait until state change.
|
||||
for {
|
||||
if l.state == state {
|
||||
break
|
||||
}
|
||||
runtime.Gosched()
|
||||
}
|
||||
<-stateChanged
|
||||
}
|
||||
|
||||
// stateLoop runs in a separate goroutine and runs the appropriate state loop.
|
||||
func (l *Log) stateLoop(closing <-chan struct{}, state State) {
|
||||
func (l *Log) stateLoop(closing <-chan struct{}, state State, stateChanged chan struct{}) {
|
||||
defer l.wg.Done()
|
||||
|
||||
l.Logger.Printf("log state change: %s => %s", l.state, state)
|
||||
l.state = state
|
||||
close(stateChanged)
|
||||
|
||||
for {
|
||||
// Transition to new state.
|
||||
l.Logger.Printf("log state change: %s => %s", l.state, state)
|
||||
|
|
Loading…
Reference in New Issue