-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Remove unnecessary locking and serverlist syncing in heartbeats #5654
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -201,12 +201,16 @@ func (m *Manager) SetServers(servers Servers) bool { | |
m.Lock() | ||
defer m.Unlock() | ||
|
||
// Sort both the existing and incoming servers | ||
servers.Sort() | ||
m.servers.Sort() | ||
|
||
// Determine if they are equal | ||
equal := servers.Equal(m.servers) | ||
equal := m.serversAreEqual(servers) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @schmichael this is ready for another look |
||
|
||
// If server list is equal don't change the list and return immediately | ||
// This prevents unnecessary shuffling of a failed server that was moved to the | ||
// bottom of the list | ||
if equal { | ||
m.logger.Debug("Not replacing server list, current server list is identical to servers discovered in Consul") | ||
return !equal | ||
} | ||
|
||
// Randomize the incoming servers | ||
servers.shuffle() | ||
|
@@ -215,6 +219,23 @@ func (m *Manager) SetServers(servers Servers) bool { | |
return !equal | ||
} | ||
|
||
// Method to check if the arg list of servers is equal to the one we already have | ||
func (m *Manager) serversAreEqual(servers Servers) bool { | ||
// We use a copy of the server list here because determining | ||
// equality requires a sort step which modifies the order of the server list | ||
var copy Servers | ||
copy = make([]*Server, 0, len(m.servers)) | ||
for _, s := range m.servers { | ||
copy = append(copy, s.Copy()) | ||
} | ||
|
||
// Sort both the existing and incoming servers | ||
copy.Sort() | ||
servers.Sort() | ||
|
||
return copy.Equal(servers) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't it better to compare servers lists omitting their DC, only by IP-addresses? Cause servers coming from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great catch! As far as I can tell the code to prefer the local DC's server has been broken since v0.8.0. I'm going to remove the DC field and add an issue+TODO. |
||
} | ||
|
||
// FindServer returns a server to send an RPC too. If there are no servers, nil | ||
// is returned. | ||
func (m *Manager) FindServer() *Server { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious how this call was dropped? Was it a regression?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it was ever there so for long running clients only failed rpcs or discovering new servers would cause reshuffling.