1
0
Fork 0

Silently ignore unchanged node self-joins

master
Philip O'Toole 2 years ago
parent 5924d0c275
commit 90b4dc0745

@ -36,10 +36,6 @@ var (
// operation.
ErrNotLeader = errors.New("not leader")
// ErrSelfJoin is returned when a join-request is received from a node
// with the same Raft ID as this node.
ErrSelfJoin = errors.New("self-join attempted")
// ErrStaleRead is returned if the executing the query would violate the
// requested freshness.
ErrStaleRead = errors.New("stale read")
@ -214,9 +210,10 @@ type Store struct {
numTrailingLogs uint64
// For whitebox testing
numNoops int
numSnapshotsMu sync.Mutex
numSnapshots int
numIgnoredJoins int
numNoops int
numSnapshotsMu sync.Mutex
numSnapshots int
}
// IsNewNode returns whether a node using raftDir would be a brand-new node.
@ -1013,9 +1010,6 @@ func (s *Store) Join(id, addr string, voter bool) error {
if s.raft.State() != raft.Leader {
return ErrNotLeader
}
if id == s.raftID {
return ErrSelfJoin
}
configFuture := s.raft.GetConfiguration()
if err := configFuture.Error(); err != nil {
@ -1031,6 +1025,7 @@ func (s *Store) Join(id, addr string, voter bool) error {
// join is actually needed.
if srv.Address == raft.ServerAddress(addr) && srv.ID == raft.ServerID(id) {
stats.Add(numIgnoredJoins, 1)
s.numIgnoredJoins++
s.logger.Printf("node %s at %s already member of cluster, ignoring join request", id, addr)
return nil
}

@ -2,7 +2,6 @@ package store
import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"math/rand"
@ -1105,7 +1104,7 @@ func Test_SingleNodeRecoverNetworkChangeSnapshot(t *testing.T) {
}
}
func Test_SingleNodeSelfJoinFail(t *testing.T) {
func Test_SingleNodeSelfJoinNoChangeOK(t *testing.T) {
s0, ln0 := mustNewStore(t, true)
defer ln0.Close()
if err := s0.Open(); err != nil {
@ -1120,13 +1119,13 @@ func Test_SingleNodeSelfJoinFail(t *testing.T) {
t.Fatalf("Error waiting for leader: %s", err)
}
// Self-join should fail.
// Self-join should not be a problem. It should just be ignored.
err := s0.Join(s0.ID(), s0.Addr(), true)
if err == nil {
t.Fatalf("failed to receive error for self-join")
if err != nil {
t.Fatalf("received error for non-changing self-join")
}
if !errors.Is(err, ErrSelfJoin) {
t.Fatalf("received wrong error for self-join attempt: %s", err)
if got, exp := s0.numIgnoredJoins, 1; got != exp {
t.Fatalf("wrong number of ignored joins, exp %d, got %d", exp, got)
}
}

Loading…
Cancel
Save