1
0
Fork 0

Clean up code without changing behaviour.

This commit is contained in:
Max Neunhoeffer 2017-01-24 12:11:57 +01:00
parent 95a165d5f4
commit f62042ef3a
1 changed files with 14 additions and 45 deletions

View File

@ -2360,35 +2360,19 @@ void ClusterInfo::loadCurrentDBServers() {
std::vector<ServerID> ClusterInfo::getCurrentDBServers() { std::vector<ServerID> ClusterInfo::getCurrentDBServers() {
std::vector<ServerID> result; std::vector<ServerID> result;
int tries = 0;
if (!_DBServersProt.isValid) { if (!_DBServersProt.isValid) {
loadCurrentDBServers(); loadCurrentDBServers();
tries++;
} }
while (true) { // return a consistent state of servers
{ READ_LOCKER(readLocker, _DBServersProt.lock);
// return a consistent state of servers
READ_LOCKER(readLocker, _DBServersProt.lock);
result.reserve(_DBServers.size()); result.reserve(_DBServers.size());
for (auto& it : _DBServers) { for (auto& it : _DBServers) {
result.emplace_back(it.first); result.emplace_back(it.first);
}
return result;
}
if (++tries >= 2) {
break;
}
// loadCurrentDBServers needs the write lock
loadCurrentDBServers();
} }
// note that the result will be empty if we get here
return result; return result;
} }
@ -2560,35 +2544,20 @@ int ClusterInfo::getResponsibleShard(LogicalCollection* collInfo,
std::vector<ServerID> ClusterInfo::getCurrentCoordinators() { std::vector<ServerID> ClusterInfo::getCurrentCoordinators() {
std::vector<ServerID> result; std::vector<ServerID> result;
int tries = 0;
if (!_coordinatorsProt.isValid) { if (!_coordinatorsProt.isValid) {
loadCurrentCoordinators(); loadCurrentCoordinators();
tries++;
}
while (true) {
{
// return a consistent state of servers
READ_LOCKER(readLocker, _coordinatorsProt.lock);
result.reserve(_coordinators.size());
for (auto& it : _coordinators) {
result.emplace_back(it.first);
}
return result;
}
if (++tries >= 2) {
break;
}
// loadCurrentCoordinators needs the write lock
loadCurrentCoordinators();
} }
// note that the result will be empty if we get here // return a consistent state of servers
READ_LOCKER(readLocker, _coordinatorsProt.lock);
result.reserve(_coordinators.size());
for (auto& it : _coordinators) {
result.emplace_back(it.first);
}
return result; return result;
} }