1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-27 13:57:23 +03:00

Fix random election timeout rounds (srand(0) == srand(1) for glibc)

This commit is contained in:
Ruben S. Montero 2018-06-11 16:39:55 +02:00
parent 5f77b49c85
commit 360cef02f0

View File

@ -1040,11 +1040,16 @@ void RaftManager::request_vote()
logdb->update_raft_state(raft_state_xml); logdb->update_raft_state(raft_state_xml);
srand(_server_id); srand(_server_id+1);
ms = rand() % 500 + election_timeout.tv_sec * 1000 ms = rand() % 1000 + election_timeout.tv_sec * 1000
+ election_timeout.tv_nsec / 1000000; + election_timeout.tv_nsec / 1000000;
oss.str("");
oss << "No leader found, starting new election in " << ms << "ms";
NebulaLog::log("RCM", Log::INFO, oss);
set_timeout(ms, etimeout); set_timeout(ms, etimeout);
nanosleep(&etimeout, 0); nanosleep(&etimeout, 0);