]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: simplify logmonitor check_subs; less noise
authorSage Weil <sage@inktank.com>
Tue, 10 Jul 2012 00:24:19 +0000 (17:24 -0700)
committerSage Weil <sage@inktank.com>
Wed, 11 Jul 2012 04:27:50 +0000 (21:27 -0700)
 * simple helper to translate name to id
 * verify sub type is valid in caller
 * assert sub type is valid in method
 * simplify iterator usage

Among other things, this gets rid of this noise in the logs:

2012-07-10 20:51:42.617152 7facb23f1700  1 mon.a@1(peon).log v310 check_sub sub monmap not log type

Signed-off-by: Sage Weil <sage@inktank.com>
src/mon/LogMonitor.cc
src/mon/LogMonitor.h
src/mon/Monitor.cc

index 468c5fe97486271163cc602d33a3e4ea5b7ae129..41b15b4ab623f7316ed40d72cdea5743bddeed1a 100644 (file)
@@ -320,20 +320,31 @@ bool LogMonitor::prepare_command(MMonCommand *m)
 }
 
 
+int LogMonitor::sub_name_to_id(const string& n)
+{
+  if (n == "log-debug")
+    return CLOG_DEBUG;
+  if (n == "log-info")
+    return CLOG_INFO;
+  if (n == "log-sec")
+    return CLOG_SEC;
+  if (n == "log-warn")
+    return CLOG_WARN;
+  if (n == "log-error")
+    return CLOG_ERROR;
+  return -1;
+}
+
 void LogMonitor::check_subs()
 {
   dout(10) << __func__ << dendl;
-
-  map<string, xlist<Subscription*>*>::iterator subs_map_it;
-  subs_map_it = mon->session_map.subs.begin();
-
-  for (; subs_map_it != mon->session_map.subs.end(); subs_map_it++) {
-
-    xlist<Subscription*> *subs_lst = subs_map_it->second;
-    xlist<Subscription*>::iterator subs_lst_it = subs_lst->begin();
-
-    for (; !subs_lst_it.end(); ++subs_lst_it)
-      check_sub(*subs_lst_it);
+  for (map<string, xlist<Subscription*>*>::iterator i = mon->session_map.subs.begin();
+       i != mon->session_map.subs.end();
+       i++) {
+    for (xlist<Subscription*>::iterator j = i->second->begin(); !j.end(); ++j) {
+      if (sub_name_to_id((*j)->type) >= 0)
+       check_sub(*j);
+    }
   }
 }
 
@@ -341,20 +352,10 @@ void LogMonitor::check_sub(Subscription *s)
 {
   dout(10) << __func__ << " client wants " << s->type << " ver " << s->next << dendl;
 
-  map<string, int> types;
-  types["log-debug"]  = CLOG_DEBUG;
-  types["log-info"]   = CLOG_INFO;
-  types["log-sec"]    = CLOG_SEC;
-  types["log-warn"]   = CLOG_WARN;
-  types["log-error"]  = CLOG_ERROR;
-
-  if (!types.count(s->type)) {
-    dout(1) << __func__ << " sub " << s->type << " not log type " << dendl;
-    return;
-  }
+  int sub_level = sub_name_to_id(s->type);
+  assert(sub_level >= 0);
 
   version_t summary_version = summary.version;
-
   if (s->next > summary_version) {
     dout(10) << __func__ << " client " << s->session->inst 
            << " requested version (" << s->next << ") is greater than ours (" 
@@ -363,7 +364,6 @@ void LogMonitor::check_sub(Subscription *s)
     return;
   } 
  
-  int sub_level = types[s->type];
   MLog *mlog = new MLog(mon->monmap->fsid);
 
   if (s->next == 0) { 
index a2ce987603fe8bdb6d5cefde9e957c49af4fe384..884cd6b1f74026afb5f667f6bfe0b4ec5a5e13f9 100644 (file)
@@ -69,6 +69,15 @@ private:
 
   void check_subs();
   void check_sub(Subscription *s);
+
+  /**
+   * translate log sub name ('log-info') to integer id
+   *
+   * @param n name
+   * @return id, or -1 if unrecognized
+   */
+  int sub_name_to_id(const string& n);
+
 };
 
 #endif
index 5903ac4f52daf1cac28405237725f006d5b261d4..1db0a257e4ab3cea33c59ea1c732b25123dc7861 100644 (file)
@@ -1819,9 +1819,7 @@ void Monitor::handle_subscribe(MMonSubscribe *m)
       }
     } else if (p->first == "monmap") {
       check_sub(s->sub_map["monmap"]);
-    } else if ((p->first == "log-error") || (p->first == "log-warn")
-       || (p->first == "log-sec") || (p->first == "log-info") 
-       || (p->first == "log-debug")) {
+    } else if (logmon()->sub_name_to_id(p->first) >= 0) {
       logmon()->check_sub(s->sub_map[p->first]);
     }
   }