Changeset 3c6e7b2c6c3b65676bb51326a13b12d505806bce

Show
Ignore:
Timestamp:
02/12/10 16:12:02 (5 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1265991122 +0000
git-parent:

[d50e0629228ff7ed2cbc8b9e7f375dabc526956e]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1265991122 +0000
Message:

cache noits by cn if specified and use that as a short-circuit, refs #255

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/stratcon_datastore.c

    r5354092 r3c6e7b2  
    605605    char uuid_str[UUID_STR_LEN+1]; 
    606606    const char *fqdn, *dsn, *remote_cn; 
     607    char remote_ip[32]; 
    607608    int storagenode_id; 
    608609 
     
    612613      continue; 
    613614 
    614     noitL(noit_debug, "stratcon_datastore_find <- (%d, %s)\n", 
    615           node->sid, remote_cn ? remote_cn : "(null)"); 
     615    noitL(noit_debug, "stratcon_datastore_find <- (%d, %s) @ %s\n", 
     616          node->sid, remote_cn ? remote_cn : "(null)", dsn ? dsn : "(null)"); 
     617 
     618    /* We might be able to find the IP from our config if someone has 
     619     * specified the expected cn in the noit definition. 
     620     */ 
     621    if(stratcon_find_noit_ip_by_cn(remote_cn, 
     622                                   remote_ip, sizeof(remote_ip)) == 0) { 
     623      node->noit = strdup(remote_ip); 
     624      noitL(noit_debug, "lookup(cache): %s -> %s\n", remote_cn, node->noit); 
     625      continue; 
     626    } 
     627 
    616628    cq = get_conn_q_for_remote(NULL, remote_cn, fqdn, dsn); 
    617629    stratcon_database_connect(cq); 
     
    622634    row_count = PQntuples(d->res); 
    623635    if(row_count != 1) { 
     636      noitL(noit_debug, "lookup (sid:%d): NOT THERE!\n", node->sid, val); 
    624637      PQclear(d->res); 
    625638      goto bad_row; 
    626639    } 
    627640 
    628     /* Get the check uuid */ 
    629     PG_GET_STR_COL(val, 0, "id"); 
    630     if(!val) { 
    631       PQclear(d->res); 
    632       goto bad_row; 
    633     } 
    634     if(uuid_parse(val, node->checkid)) { 
    635       PQclear(d->res); 
    636       goto bad_row; 
    637     } 
    638    
    639641    /* Get the remote_address (which noit owns this) */ 
    640642    PG_GET_STR_COL(val, 0, "remote_address"); 
    641643    if(!val) { 
     644      noitL(noit_debug, "lookup: %s -> NOT THERE!\n", remote_cn); 
    642645      PQclear(d->res); 
    643646      goto bad_row; 
    644647    } 
    645648    node->noit = strdup(val); 
    646   
     649    noitL(noit_debug, "lookup: %s -> %s\n", remote_cn, node->noit); 
    647650   bad_row:  
    648651    free_params((ds_single_detail *)d); 
  • src/stratcon_jlog_streamer.c

    r3862f7e r3c6e7b2  
    5656pthread_mutex_t noits_lock; 
    5757noit_hash_table noits = NOIT_HASH_EMPTY; 
     58pthread_mutex_t noit_ip_by_cn_lock; 
     59noit_hash_table noit_ip_by_cn = NOIT_HASH_EMPTY; 
    5860 
    5961static void noit_connection_initiate_connection(noit_connection_ctx_t *ctx); 
     
    788790  free(noit_configs); 
    789791} 
     792int 
     793stratcon_find_noit_ip_by_cn(const char *cn, char *ip, int len) { 
     794  int rv = -1; 
     795  void *vip; 
     796  pthread_mutex_lock(&noit_ip_by_cn_lock); 
     797  if(noit_hash_retrieve(&noit_ip_by_cn, cn, strlen(cn), &vip)) { 
     798    int new_len; 
     799    char *new_ip = (char *)vip; 
     800    new_len = strlen(new_ip); 
     801    strlcpy(ip, new_ip, len); 
     802    if(new_len >= len) rv = new_len+1; 
     803    else rv = 0; 
     804  } 
     805  pthread_mutex_unlock(&noit_ip_by_cn_lock); 
     806  return rv; 
     807} 
     808void 
     809stratcon_jlog_streamer_recache_noit() { 
     810  int di, cnt; 
     811  noit_conf_section_t *noit_configs; 
     812  noit_configs = noit_conf_get_sections(NULL, "//noits//noit", &cnt); 
     813  pthread_mutex_lock(&noit_ip_by_cn_lock); 
     814  noit_hash_delete_all(&noit_ip_by_cn, free, free); 
     815  for(di=0; di<cnt; di++) { 
     816    char address[64]; 
     817    if(noit_conf_get_stringbuf(noit_configs[di], "self::node()/@address", 
     818                                 address, sizeof(address))) { 
     819      char expected_cn[256]; 
     820      if(noit_conf_get_stringbuf(noit_configs[di], "self::node()/config/cn", 
     821                                 expected_cn, sizeof(expected_cn))) 
     822        noit_hash_store(&noit_ip_by_cn, 
     823                        strdup(expected_cn), strlen(expected_cn), 
     824                        strdup(address)); 
     825    } 
     826  } 
     827  free(noit_configs); 
     828  pthread_mutex_unlock(&noit_ip_by_cn_lock); 
     829} 
    790830void 
    791831stratcon_jlog_streamer_reload(const char *toplevel) { 
     832  /* flush and repopulate the cn cache */ 
     833  stratcon_jlog_streamer_recache_noit(); 
    792834  if(!stratcon_datastore_get_enabled()) return; 
    793835  stratcon_streamer_connection(toplevel, NULL, 
     
    10291071    xmlAddChild(config, cnnode); 
    10301072    xmlAddChild(newnoit, config); 
     1073    pthread_mutex_lock(&noit_ip_by_cn_lock); 
     1074    noit_hash_replace(&noit_ip_by_cn, strdup(cn), strlen(cn), 
     1075                      strdup(target), free, free); 
     1076    pthread_mutex_unlock(&noit_ip_by_cn_lock); 
    10311077  } 
    10321078  if(stratcon_datastore_get_enabled()) 
     
    10611107  noit_configs = noit_conf_get_sections(NULL, path, &cnt); 
    10621108  for(i=0; i<cnt; i++) { 
     1109    char expected_cn[256]; 
     1110    if(noit_conf_get_stringbuf(noit_configs[i], "self::node()/config/cn", 
     1111                               expected_cn, sizeof(expected_cn))) { 
     1112      pthread_mutex_lock(&noit_ip_by_cn_lock); 
     1113      noit_hash_delete(&noit_ip_by_cn, expected_cn, strlen(expected_cn), 
     1114                       free, free); 
     1115      pthread_mutex_unlock(&noit_ip_by_cn_lock); 
     1116    } 
    10631117    xmlUnlinkNode(noit_configs[i]); 
    10641118    xmlFreeNode(noit_configs[i]); 
     
    11861240stratcon_jlog_streamer_init(const char *toplevel) { 
    11871241  pthread_mutex_init(&noits_lock, NULL); 
     1242  pthread_mutex_init(&noit_ip_by_cn_lock, NULL); 
    11881243  eventer_name_callback("noit_connection_reinitiate", 
    11891244                        noit_connection_reinitiate); 
  • src/stratcon_jlog_streamer.h

    rd3656fe r3c6e7b2  
    115115                               void (*handler_free)(void *)); 
    116116 
     117/*! \fn int stratcon_find_noit_ip_by_cn(const char *cn, char *ip, int len) 
     118    \brief find the remote IPv4 address for the cn if it is configured 
     119    \param cn the remote CN in which you are interested 
     120    \param ip the buffer where the IP will be stored if it is found 
     121    \param len the length of the passed buffer 
     122    \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. 
     123 */ 
     124 
     125API_EXPORT(int) 
     126  stratcon_find_noit_ip_by_cn(const char *cn, char *ip, int len); 
     127 
     128 
    117129#endif