Changeset 3c6e7b2c6c3b65676bb51326a13b12d505806bce
- Timestamp:
- 02/12/10 16:12:02 (3 years ago)
- git-parent:
- Files:
-
- src/stratcon_datastore.c (modified) (3 diffs)
- src/stratcon_jlog_streamer.c (modified) (5 diffs)
- src/stratcon_jlog_streamer.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
src/stratcon_datastore.c
r5354092 r3c6e7b2 605 605 char uuid_str[UUID_STR_LEN+1]; 606 606 const char *fqdn, *dsn, *remote_cn; 607 char remote_ip[32]; 607 608 int storagenode_id; 608 609 … … 612 613 continue; 613 614 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 616 628 cq = get_conn_q_for_remote(NULL, remote_cn, fqdn, dsn); 617 629 stratcon_database_connect(cq); … … 622 634 row_count = PQntuples(d->res); 623 635 if(row_count != 1) { 636 noitL(noit_debug, "lookup (sid:%d): NOT THERE!\n", node->sid, val); 624 637 PQclear(d->res); 625 638 goto bad_row; 626 639 } 627 640 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 639 641 /* Get the remote_address (which noit owns this) */ 640 642 PG_GET_STR_COL(val, 0, "remote_address"); 641 643 if(!val) { 644 noitL(noit_debug, "lookup: %s -> NOT THERE!\n", remote_cn); 642 645 PQclear(d->res); 643 646 goto bad_row; 644 647 } 645 648 node->noit = strdup(val); 646 649 noitL(noit_debug, "lookup: %s -> %s\n", remote_cn, node->noit); 647 650 bad_row: 648 651 free_params((ds_single_detail *)d); src/stratcon_jlog_streamer.c
r3862f7e r3c6e7b2 56 56 pthread_mutex_t noits_lock; 57 57 noit_hash_table noits = NOIT_HASH_EMPTY; 58 pthread_mutex_t noit_ip_by_cn_lock; 59 noit_hash_table noit_ip_by_cn = NOIT_HASH_EMPTY; 58 60 59 61 static void noit_connection_initiate_connection(noit_connection_ctx_t *ctx); … … 788 790 free(noit_configs); 789 791 } 792 int 793 stratcon_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 } 808 void 809 stratcon_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 } 790 830 void 791 831 stratcon_jlog_streamer_reload(const char *toplevel) { 832 /* flush and repopulate the cn cache */ 833 stratcon_jlog_streamer_recache_noit(); 792 834 if(!stratcon_datastore_get_enabled()) return; 793 835 stratcon_streamer_connection(toplevel, NULL, … … 1029 1071 xmlAddChild(config, cnnode); 1030 1072 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); 1031 1077 } 1032 1078 if(stratcon_datastore_get_enabled()) … … 1061 1107 noit_configs = noit_conf_get_sections(NULL, path, &cnt); 1062 1108 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 } 1063 1117 xmlUnlinkNode(noit_configs[i]); 1064 1118 xmlFreeNode(noit_configs[i]); … … 1186 1240 stratcon_jlog_streamer_init(const char *toplevel) { 1187 1241 pthread_mutex_init(&noits_lock, NULL); 1242 pthread_mutex_init(&noit_ip_by_cn_lock, NULL); 1188 1243 eventer_name_callback("noit_connection_reinitiate", 1189 1244 noit_connection_reinitiate); src/stratcon_jlog_streamer.h
rd3656fe r3c6e7b2 115 115 void (*handler_free)(void *)); 116 116 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 125 API_EXPORT(int) 126 stratcon_find_noit_ip_by_cn(const char *cn, char *ip, int len); 127 128 117 129 #endif
