Skip to content

Commit

Permalink
Merge pull request #1091 from nats-io/fix_990
Browse files Browse the repository at this point in the history
[IMPROVED] Clustering: Report possible misconfiguration of peers list
  • Loading branch information
kozlovic authored Oct 6, 2020
2 parents f11f6f9 + 164f72f commit d6f0466
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
33 changes: 33 additions & 0 deletions server/clustering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3801,6 +3801,39 @@ func TestClusteringNodeIDInPeersArray(t *testing.T) {
s1.Shutdown()
}

func TestClusteringNodeWrongPeerList(t *testing.T) {
cleanupDatastore(t)
defer cleanupDatastore(t)
cleanupRaftLog(t)
defer cleanupRaftLog(t)

ns := natsdTest.RunDefaultServer()
defer ns.Shutdown()

l := &captureWarnLogger{}

s1Opts := getTestDefaultOptsForClustering("a", false)
s1Opts.Clustering.Peers = []string{"a,b,c"}
s1Opts.CustomLogger = l
s1 := runServerWithOpts(t, s1Opts, nil)
defer s1.Shutdown()

waitFor(t, 5*time.Second, 15*time.Millisecond, func() error {
var ok bool
l.Lock()
for _, line := range l.warnings {
if strings.Contains(line, "string with commas") {
ok = true
}
}
l.Unlock()
if ok {
return nil
}
return fmt.Errorf("Did not print warning about commas in peer list")
})
}

func TestClusteringUnableToContactPeer(t *testing.T) {
if runtime.GOOS == "windows" {
t.SkipNow()
Expand Down
13 changes: 13 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2025,6 +2025,19 @@ func (s *StanServer) start(runningState State) error {
}
s.log.Noticef("Cluster Node ID : %s", s.info.NodeID)
s.log.Noticef("Cluster Log Path: %s", s.opts.Clustering.RaftLogPath)
if len(s.opts.Clustering.Peers) > 0 {
s.log.Noticef("Cluster known peers:")
var alert bool
for i, peer := range s.opts.Clustering.Peers {
if strings.Contains(peer, ",") {
alert = true
}
s.log.Noticef("peer %d: %q", i+1, peer)
}
if alert {
s.log.Warnf("Peer name contains ',' make sure you provided an array of peer names, not a string with commas")
}
}
if err := s.startRaftNode(recoveredState != nil); err != nil {
return err
}
Expand Down

0 comments on commit d6f0466

Please sign in to comment.