-bool
-config::remove_wo(std::string m)
-{
- tprintf("config::remove: myvid %d remove? %s\n", myvid, m.c_str());
- std::vector<std::string> n;
- for (unsigned i = 0; i < mems.size(); i++) {
- if (mems[i] != m) n.push_back(mems[i]);
- }
- std::string v = value(n);
- std::vector<std::string> cmems = mems;
- int nextvid = myvid + 1;
- VERIFY(pthread_mutex_unlock(&cfg_mutex)==0);
- bool r = pro->run(nextvid, cmems, v);
- VERIFY(pthread_mutex_lock(&cfg_mutex)==0);
- if (r) {
- tprintf("config::remove: proposer returned success\n");
- } else {
- tprintf("config::remove: proposer returned failure\n");
- }
- return r;
-}
-
-void
-config::heartbeater()
-{
- struct timeval now;
- struct timespec next_timeout;
- std::string m;
- heartbeat_t h;
- bool stable;
- unsigned vid;
- std::vector<std::string> cmems;
- ScopedLock ml(&cfg_mutex);
-
- while (1) {
-
- gettimeofday(&now, NULL);
- next_timeout.tv_sec = now.tv_sec + 3;
- next_timeout.tv_nsec = 0;
- tprintf("heartbeater: go to sleep\n");
- pthread_cond_timedwait(&config_cond, &cfg_mutex, &next_timeout);
-
- stable = true;
- vid = myvid;
- cmems = get_view_wo(vid);
- tprintf("heartbeater: current membership %s\n", print_members(cmems).c_str());
-
- if (!isamember(me, cmems)) {
- tprintf("heartbeater: not member yet; skip hearbeat\n");
- continue;
- }
-
- //find the node with the smallest id
- m = me;
- for (unsigned i = 0; i < cmems.size(); i++) {
- if (m > cmems[i])
- m = cmems[i];
- }
-
- if (m == me) {
- //if i am the one with smallest id, ping the rest of the nodes
- for (unsigned i = 0; i < cmems.size(); i++) {
- if (cmems[i] != me) {
- if ((h = doheartbeat(cmems[i])) != OK) {
- stable = false;
- m = cmems[i];
- break;
- }
- }
- }
- } else {
- //the rest of the nodes ping the one with smallest id
- if ((h = doheartbeat(m)) != OK)
- stable = false;