From 5a3b49a7bc8fb0d0ffc012fd4521ef8b8c27d132 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Fri, 20 Dec 2013 16:27:54 +0100 Subject: [PATCH] fixed r/w deadlock --- arangod/Cluster/ClusterState.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/arangod/Cluster/ClusterState.cpp b/arangod/Cluster/ClusterState.cpp index ea876d0cfa..adf14e1560 100644 --- a/arangod/Cluster/ClusterState.cpp +++ b/arangod/Cluster/ClusterState.cpp @@ -133,18 +133,22 @@ std::string ClusterState::getServerEndpoint (ServerID const& serverID) { return string(""); } -ServerID ClusterState::getResponsibleServer (ShardID const& shardID) -{ - READ_LOCKER(lock); - map::iterator i = shards.find(shardID); - if (i != shards.end()) { - return i->second; - } - loadShardInformation(); - i = shards.find(shardID); - if (i != shards.end()) { - return i->second; +ServerID ClusterState::getResponsibleServer (ShardID const& shardID) { + int tries = 0; + + while (++tries < 3) { + { + READ_LOCKER(lock); + map::iterator i = shards.find(shardID); + if (i != shards.end()) { + return i->second; + } + } + + // must call loadShardInformation outside the lock + loadShardInformation(); } + return ServerID(""); }