[Reconnoiter-devel] [reconnoiter commit] r1215 - trunk/src

svn-commit at lists.omniti.com svn-commit at lists.omniti.com
Fri Feb 12 11:12:02 EST 2010


Author: jesus
Date: 2010-02-12 11:12:02 -0500 (Fri, 12 Feb 2010)
New Revision: 1215

Modified:
   trunk/src/stratcon_datastore.c
   trunk/src/stratcon_jlog_streamer.c
   trunk/src/stratcon_jlog_streamer.h
Log:
cache noits by cn if specified and use that as a short-circuit, refs #255

Modified: trunk/src/stratcon_datastore.c
===================================================================
--- trunk/src/stratcon_datastore.c	2010-02-11 16:57:22 UTC (rev 1214)
+++ trunk/src/stratcon_datastore.c	2010-02-12 16:12:02 UTC (rev 1215)
@@ -604,6 +604,7 @@
   for(node = d->rt; node; node = node->next) {
     char uuid_str[UUID_STR_LEN+1];
     const char *fqdn, *dsn, *remote_cn;
+    char remote_ip[32];
     int storagenode_id;
 
     uuid_unparse_lower(node->checkid, uuid_str);
@@ -611,8 +612,19 @@
                                  &storagenode_id, &remote_cn, &fqdn, &dsn))
       continue;
 
-    noitL(noit_debug, "stratcon_datastore_find <- (%d, %s)\n",
-          node->sid, remote_cn ? remote_cn : "(null)");
+    noitL(noit_debug, "stratcon_datastore_find <- (%d, %s) @ %s\n",
+          node->sid, remote_cn ? remote_cn : "(null)", dsn ? dsn : "(null)");
+
+    /* We might be able to find the IP from our config if someone has
+     * specified the expected cn in the noit definition.
+     */
+    if(stratcon_find_noit_ip_by_cn(remote_cn,
+                                   remote_ip, sizeof(remote_ip)) == 0) {
+      node->noit = strdup(remote_ip);
+      noitL(noit_debug, "lookup(cache): %s -> %s\n", remote_cn, node->noit);
+      continue;
+    }
+
     cq = get_conn_q_for_remote(NULL, remote_cn, fqdn, dsn);
     stratcon_database_connect(cq);
 
@@ -621,29 +633,20 @@
     PG_EXEC(check_find);
     row_count = PQntuples(d->res);
     if(row_count != 1) {
+      noitL(noit_debug, "lookup (sid:%d): NOT THERE!\n", node->sid, val);
       PQclear(d->res);
       goto bad_row;
     }
 
-    /* Get the check uuid */
-    PG_GET_STR_COL(val, 0, "id");
-    if(!val) {
-      PQclear(d->res);
-      goto bad_row;
-    }
-    if(uuid_parse(val, node->checkid)) {
-      PQclear(d->res);
-      goto bad_row;
-    }
-  
     /* Get the remote_address (which noit owns this) */
     PG_GET_STR_COL(val, 0, "remote_address");
     if(!val) {
+      noitL(noit_debug, "lookup: %s -> NOT THERE!\n", remote_cn);
       PQclear(d->res);
       goto bad_row;
     }
     node->noit = strdup(val);
- 
+    noitL(noit_debug, "lookup: %s -> %s\n", remote_cn, node->noit);
    bad_row: 
     free_params((ds_single_detail *)d);
     d->nparams = 0;

Modified: trunk/src/stratcon_jlog_streamer.c
===================================================================
--- trunk/src/stratcon_jlog_streamer.c	2010-02-11 16:57:22 UTC (rev 1214)
+++ trunk/src/stratcon_jlog_streamer.c	2010-02-12 16:12:02 UTC (rev 1215)
@@ -55,6 +55,8 @@
 
 pthread_mutex_t noits_lock;
 noit_hash_table noits = NOIT_HASH_EMPTY;
+pthread_mutex_t noit_ip_by_cn_lock;
+noit_hash_table noit_ip_by_cn = NOIT_HASH_EMPTY;
 
 static void noit_connection_initiate_connection(noit_connection_ctx_t *ctx);
 
@@ -787,8 +789,48 @@
   }
   free(noit_configs);
 }
+int
+stratcon_find_noit_ip_by_cn(const char *cn, char *ip, int len) {
+  int rv = -1;
+  void *vip;
+  pthread_mutex_lock(&noit_ip_by_cn_lock);
+  if(noit_hash_retrieve(&noit_ip_by_cn, cn, strlen(cn), &vip)) {
+    int new_len;
+    char *new_ip = (char *)vip;
+    new_len = strlen(new_ip);
+    strlcpy(ip, new_ip, len);
+    if(new_len >= len) rv = new_len+1;
+    else rv = 0;
+  }
+  pthread_mutex_unlock(&noit_ip_by_cn_lock);
+  return rv;
+}
 void
+stratcon_jlog_streamer_recache_noit() {
+  int di, cnt;
+  noit_conf_section_t *noit_configs;
+  noit_configs = noit_conf_get_sections(NULL, "//noits//noit", &cnt);
+  pthread_mutex_lock(&noit_ip_by_cn_lock);
+  noit_hash_delete_all(&noit_ip_by_cn, free, free);
+  for(di=0; di<cnt; di++) {
+    char address[64];
+    if(noit_conf_get_stringbuf(noit_configs[di], "self::node()/@address",
+                                 address, sizeof(address))) {
+      char expected_cn[256];
+      if(noit_conf_get_stringbuf(noit_configs[di], "self::node()/config/cn",
+                                 expected_cn, sizeof(expected_cn)))
+        noit_hash_store(&noit_ip_by_cn,
+                        strdup(expected_cn), strlen(expected_cn),
+                        strdup(address));
+    }
+  }
+  free(noit_configs);
+  pthread_mutex_unlock(&noit_ip_by_cn_lock);
+}
+void
 stratcon_jlog_streamer_reload(const char *toplevel) {
+  /* flush and repopulate the cn cache */
+  stratcon_jlog_streamer_recache_noit();
   if(!stratcon_datastore_get_enabled()) return;
   stratcon_streamer_connection(toplevel, NULL,
                                stratcon_jlog_recv_handler,
@@ -1028,6 +1070,10 @@
     xmlNodeAddContent(cnnode, (xmlChar *)cn);
     xmlAddChild(config, cnnode);
     xmlAddChild(newnoit, config);
+    pthread_mutex_lock(&noit_ip_by_cn_lock);
+    noit_hash_replace(&noit_ip_by_cn, strdup(cn), strlen(cn),
+                      strdup(target), free, free);
+    pthread_mutex_unlock(&noit_ip_by_cn_lock);
   }
   if(stratcon_datastore_get_enabled())
     stratcon_streamer_connection(NULL, target,
@@ -1060,6 +1106,14 @@
            "//noits//noit[@address=\"%s\" and @port=\"%d\"]", target, port);
   noit_configs = noit_conf_get_sections(NULL, path, &cnt);
   for(i=0; i<cnt; i++) {
+    char expected_cn[256];
+    if(noit_conf_get_stringbuf(noit_configs[i], "self::node()/config/cn",
+                               expected_cn, sizeof(expected_cn))) {
+      pthread_mutex_lock(&noit_ip_by_cn_lock);
+      noit_hash_delete(&noit_ip_by_cn, expected_cn, strlen(expected_cn),
+                       free, free);
+      pthread_mutex_unlock(&noit_ip_by_cn_lock);
+    }
     xmlUnlinkNode(noit_configs[i]);
     xmlFreeNode(noit_configs[i]);
     n = 0;
@@ -1185,6 +1239,7 @@
 void
 stratcon_jlog_streamer_init(const char *toplevel) {
   pthread_mutex_init(&noits_lock, NULL);
+  pthread_mutex_init(&noit_ip_by_cn_lock, NULL);
   eventer_name_callback("noit_connection_reinitiate",
                         noit_connection_reinitiate);
   eventer_name_callback("stratcon_jlog_recv_handler",

Modified: trunk/src/stratcon_jlog_streamer.h
===================================================================
--- trunk/src/stratcon_jlog_streamer.h	2010-02-11 16:57:22 UTC (rev 1214)
+++ trunk/src/stratcon_jlog_streamer.h	2010-02-12 16:12:02 UTC (rev 1215)
@@ -114,4 +114,16 @@
                                void *(*handler_alloc)(void), void *handler_ctx,
                                void (*handler_free)(void *));
 
+/*! \fn int stratcon_find_noit_ip_by_cn(const char *cn, char *ip, int len)
+    \brief find the remote IPv4 address for the cn if it is configured
+    \param cn the remote CN in which you are interested
+    \param ip the buffer where the IP will be stored if it is found
+    \param len the length of the passed buffer
+    \return 0 on success, -1 if the CN is not in the cache, > 0 represents the size needed if the supplied buffer is too short.
+ */
+
+API_EXPORT(int)
+  stratcon_find_noit_ip_by_cn(const char *cn, char *ip, int len);
+
+
 #endif



More information about the Reconnoiter-devel mailing list