Skip to content

Commit 9fdc72a

Browse files
author
Junlong Gao
committed
Off by one error in election time out.
This was caught in TestCandidateStartNewElection2AA, 1/20 th chance of hitting it.
1 parent 69dc3ca commit 9fdc72a

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM golang:1.13.8
2+
3+
COPY . /src
4+
ENTRYPOINT ["/src/entrypoint.sh"]

entrypoint.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#!/bin/bash -ex
22
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
33
cd $DIR
4-
4+
iter=0
5+
export GO111MODULE=on
6+
go mod tidy
57
while true; do
6-
export GO111MODULE=on
7-
go mod tidy
8+
iter=$((iter+1))
9+
echo "iteration $iter"
810
make project1
911
make project2a
1012
make project2b

log/log.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ var _log *Logger = New()
5656
func init() {
5757
SetFlags(Ldate | Ltime | Lshortfile)
5858
SetHighlighting(runtime.GOOS != "windows")
59-
SetLevel(LOG_LEVEL_NONE)
60-
_log._log.SetOutput(os.Stderr)
59+
SetLevel(LOG_LEVEL_INFO)
60+
_log._log.SetOutput(os.Stdout)
6161
}
6262

6363
func GlobalLogger() *log.Logger {

raft/raft.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ func (r *Raft) becomeFollower(term uint64, lead uint64) {
419419
r.votes = make(map[uint64]bool)
420420

421421
r.electionElapsed = 0
422-
r.electionTimeout = r.electionTimeoutConfig + rand.Int()%(r.electionTimeoutConfig+1)
422+
r.electionTimeout = r.electionTimeoutConfig + rand.Int()%r.electionTimeoutConfig
423423
}
424424

425425
// becomeCandidate transform this peer's state to candidate
@@ -432,7 +432,7 @@ func (r *Raft) becomeCandidate() {
432432

433433
r.Term++
434434
r.State = StateCandidate
435-
r.electionTimeout = r.electionTimeoutConfig + rand.Int()%(r.electionTimeoutConfig+1)
435+
r.electionTimeout = r.electionTimeoutConfig + rand.Int()%r.electionTimeoutConfig
436436
r.Lead = None
437437

438438
}

0 commit comments

Comments
 (0)