From 0b3f6932df065a18194eae12fb690a5ea234e84d Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Fri, 25 Mar 2016 12:54:36 -0700 Subject: [PATCH] Only rotate server list with more than one server Fantastic observation by slackpad. This was left over from when there was a boolean for health in the server struct (vs current strategy where we use server position in the list and rely on serf to cleanup the stale members). Pointed out by: slackpad --- consul/server_manager/server_manager.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/consul/server_manager/server_manager.go b/consul/server_manager/server_manager.go index e6d847c5d4..0f935c0b62 100644 --- a/consul/server_manager/server_manager.go +++ b/consul/server_manager/server_manager.go @@ -198,8 +198,9 @@ func (sm *ServerManager) NotifyFailedServer(server *server_details.ServerDetails // the list, acquire the lock, retest, and take the penalty of moving // the server to the end of the list. - // Use atomic.CAS to emulate a TryLock(). - if len(serverCfg.servers) > 0 && serverCfg.servers[0] == server && + // Only rotate the server list when there is more than one server + if len(serverCfg.servers) > 1 && serverCfg.servers[0] == server && + // Use atomic.CAS to emulate a TryLock(). atomic.CompareAndSwapInt32(&sm.notifyFailedBarrier, 0, 1) { defer atomic.StoreInt32(&sm.notifyFailedBarrier, 0) @@ -209,7 +210,7 @@ func (sm *ServerManager) NotifyFailedServer(server *server_details.ServerDetails defer sm.serverConfigLock.Unlock() serverCfg = sm.getServerConfig() - if len(serverCfg.servers) > 0 && serverCfg.servers[0] == server { + if len(serverCfg.servers) > 1 && serverCfg.servers[0] == server { serverCfg.servers = serverCfg.cycleServer() sm.saveServerConfig(serverCfg) }