]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: Monitor: use rank instead of name when randomly picking monitors
authorJoao Eduardo Luis <joao.luis@inktank.com>
Tue, 30 Apr 2013 15:28:42 +0000 (16:28 +0100)
committerSage Weil <sage@inktank.com>
Wed, 1 May 2013 17:45:51 +0000 (10:45 -0700)
Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
src/common/config_opts.h
src/mon/Monitor.cc
src/mon/Monitor.h

index 9f7dafeb2189b60077b233abfe9ef8ea9b551a98..15cb7d2ad8df4110e77d8a94bc8c2dff7ec27c3e 100644 (file)
@@ -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
index dd490948b455449dd92eb61e219ece1cb9096ff9..54e722ac948c67503936737ce41df12bb613ad96 100644 (file)
@@ -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;
index 1a19914ba9271bdac6d516b6f1bad21f1a346381..c06d2fbb54e3d1a3f430006505a1e74dd1315554 100644 (file)
@@ -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.