From: Joao Eduardo Luis Date: Tue, 30 Apr 2013 15:28:42 +0000 (+0100) Subject: mon: Monitor: use rank instead of name when randomly picking monitors X-Git-Tag: v0.61~11^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7f48fd0643c580b9cfe9962e1927f120e9785da7;p=ceph.git mon: Monitor: use rank instead of name when randomly picking monitors Signed-off-by: Joao Eduardo Luis --- diff --git a/src/common/config_opts.h b/src/common/config_opts.h index 9f7dafeb2189..15cb7d2ad8df 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -177,9 +177,9 @@ OPTION(mon_sync_timeout, OPT_DOUBLE, 30.0) OPTION(mon_sync_max_retries, OPT_INT, 5) OPTION(mon_sync_max_payload_size, OPT_U32, 1048576) // max size for a sync chunk payload (say, 1MB) OPTION(mon_sync_debug, OPT_BOOL, false) // enable sync-specific debug -OPTION(mon_sync_debug_leader, OPT_STR, "") // monitor to be used as the sync leader -OPTION(mon_sync_debug_provider, OPT_STR, "") // monitor to be used as the sync provider -OPTION(mon_sync_debug_provider_fallback, OPT_STR, "") // monitor to be used as fallback if sync provider fails +OPTION(mon_sync_debug_leader, OPT_INT, -1) // monitor to be used as the sync leader +OPTION(mon_sync_debug_provider, OPT_INT, -1) // monitor to be used as the sync provider +OPTION(mon_sync_debug_provider_fallback, OPT_INT, -1) // monitor to be used as fallback if sync provider fails OPTION(mon_sync_leader_kill_at, OPT_INT, 0) // kill the sync leader at a specifc point in the work flow OPTION(mon_sync_provider_kill_at, OPT_INT, 0) // kill the sync provider at a specific point in the work flow OPTION(mon_sync_requester_kill_at, OPT_INT, 0) // kill the sync requester at a specific point in the work flow diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index dd490948b455..54e722ac948c 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -1064,17 +1064,17 @@ void Monitor::handle_sync_finish(MMonSync *m) // synchronization provider -string Monitor::_pick_random_mon(int other) +int Monitor::_pick_random_mon(int other) { assert(monmap->size() > 0); if (monmap->size() == 1) - return monmap->get_name(0); + return 0; int max = monmap->size(); int n = sync_rng() % max; if (other >= 0 && n >= other) n++; - return monmap->get_name(n); + return n; } int Monitor::_pick_random_quorum_mon(int other) @@ -1112,24 +1112,31 @@ void Monitor::sync_timeout(entity_inst_t &entity) } unsigned int i = 0; - string entity_name = monmap->get_name(entity.addr); - string debug_mon = g_conf->mon_sync_debug_provider; - string debug_fallback = g_conf->mon_sync_debug_provider_fallback; + int entity_rank = monmap->get_rank(entity.addr); + int debug_mon = g_conf->mon_sync_debug_provider; + int debug_fallback = g_conf->mon_sync_debug_provider_fallback; + + dout(10) << __func__ << " entity " << entity << " rank " << entity_rank << dendl; + dout(10) << __func__ << " our-rank " << rank << dendl; + while ((i++) < 2*monmap->size()) { // we are trying to pick a random monitor, but we cannot do this forever. // in case something goes awfully wrong, just stop doing it after a // couple of attempts and try again later. - string new_mon = _pick_random_mon(); + int new_mon = _pick_random_mon(rank); - if (!debug_fallback.empty()) { - if (entity_name != debug_fallback) + if (debug_fallback >= 0) { + if (entity_rank != debug_fallback) new_mon = debug_fallback; - else if (!debug_mon.empty() && (entity_name != debug_mon)) + else if (debug_mon >= 0 && (entity_rank != debug_mon)) new_mon = debug_mon; } - if ((new_mon != name) && (new_mon != entity_name)) { + dout(10) << __func__ << " randomly picking mon rank " << new_mon << dendl; + + if ((new_mon != rank) && (new_mon != entity_rank)) { sync_provider->entity = monmap->get_inst(new_mon); + dout(10) << __func__ << " randomly choosing " << sync_provider->entity << " rank " << new_mon << dendl; sync_state = SYNC_STATE_START; sync_start_chunks(sync_provider); return; @@ -1417,13 +1424,13 @@ void Monitor::sync_start(entity_inst_t &other) entity_inst_t leader = other; entity_inst_t provider = other; - if (!g_conf->mon_sync_debug_leader.empty()) { + if (g_conf->mon_sync_debug_leader >= 0) { leader = monmap->get_inst(g_conf->mon_sync_debug_leader); dout(10) << __func__ << " assuming " << leader << " as the leader for debug" << dendl; } - if (!g_conf->mon_sync_debug_provider.empty()) { + if (g_conf->mon_sync_debug_provider >= 0) { provider = monmap->get_inst(g_conf->mon_sync_debug_provider); dout(10) << __func__ << " assuming " << provider << " as the provider for debug" << dendl; diff --git a/src/mon/Monitor.h b/src/mon/Monitor.h index 1a19914ba927..c06d2fbb54e3 100644 --- a/src/mon/Monitor.h +++ b/src/mon/Monitor.h @@ -719,7 +719,7 @@ private: * @param other Any monitor other than the one with rank @p other * @returns The picked monitor's name. */ - string _pick_random_mon(int other = -1); + int _pick_random_mon(int other = -1); int _pick_random_quorum_mon(int other = -1); /** * Deal with the consequences of @p entity's sync timing out.