Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMPROVED] Clustering: Report possible misconfiguration of peers list #1091

Merged
merged 1 commit into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -2003,6 +2003,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