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

Randomize implicit servers #376

Merged
merged 2 commits into from
May 15, 2020
Merged

Randomize implicit servers #376

merged 2 commits into from
May 15, 2020

Conversation

ColinSullivan1
Copy link
Member

See nats-io/nats.go#565.

The server list is randomized on initial setup, then implicit servers are added into the list in a random position. The NoRandomize option is honored, which will keep the initial server list static and place implicit servers at the end of the server list.

This PR also includes unit testing for the server pool.

Signed-off-by: Colin Sullivan [email protected]

Signed-off-by: Colin Sullivan <[email protected]>
Copy link
Member

@kozlovic kozlovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a note about the copyright date for the new test file.

@@ -0,0 +1,139 @@
// Copyright 2015-2020 The NATS Authors
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it is new file, start at 2020

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix... Thanks!

Signed-off-by: Colin Sullivan <[email protected]>
{
// pick a random spot to add the server.
var randElem = sList.ElementAt(rand.Next(sList.Count));
sList.AddAfter(sList.Find(randElem), s);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on latest comment on the Go client, I wonder if this need to be updated. Basically in Go I was shuffling the pool after adding all new URLs (when processing INFO). But the point made was that possibly the first URL in the pool would be moved (say to position 2 (index 1)), and on reconnect that would be the very next one to be tried although we just disconnected from it. Let me know if I make sense (note the Go PR has not been updated as I type this).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per discussions in Slack, we've concluded that this achieves the same result, so I'll keep this as is. Appreciate the catch here!

@ColinSullivan1 ColinSullivan1 merged commit 6742c53 into master May 15, 2020
@ColinSullivan1 ColinSullivan1 deleted the randomize-servers branch June 25, 2020 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants