Changeset 44ff3960c287fb9db5673a83f1165dfe9a8ae96e
- Timestamp:
- 10/27/09 19:12:58 (4 years ago)
- git-parent:
- Files:
-
- configure.in (modified) (1 diff)
- src/noit_defines.h (modified) (1 diff)
- src/stratcon_datastore.c (modified) (10 diffs)
- src/stratcon_iep.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
configure.in
r4790fc8 r44ff396 56 56 fi 57 57 if test "x$CC" != "xgcc" ; then 58 CFLAGS="$CFLAGS - D_POSIX_PTHREAD_SEMANTICS -mt"58 CFLAGS="$CFLAGS -mt" 59 59 fi 60 60 PICFLAGS="-Kpic" src/noit_defines.h
r47a77d0 r44ff396 133 133 } 134 134 135 #if defined(__sun) 136 #define portable_readdir_r(a,b,c) ((*c) = readdir_r(a,b)) 137 #else 138 #define portable_readdir_r readdir_r 139 #endif 135 140 #include "noitedit/strlcpy.h" 136 141 src/stratcon_datastore.c
rd2dd72f r44ff396 450 450 if(d->rv != PGRES_COMMAND_OK && \ 451 451 d->rv != PGRES_TUPLES_OK) { \ 452 noitL(ds_err, "stratcon datasource bad (%d): %s\n'%s'\n", \ 453 d->rv, PQresultErrorMessage(d->res), cmd); \ 452 noitL(ds_err, "[%s] stratcon datasource bad (%d): %s\n'%s'\n", \ 453 cq->fqdn ? cq->fqdn : "metanode", d->rv, \ 454 PQresultErrorMessage(d->res), cmd); \ 454 455 PQclear(d->res); \ 455 456 goto bad_row; \ … … 477 478 } while(0) 478 479 479 static int480 stratcon_datastore_ asynch_drive_iep(eventer_t e, int mask, void *closure,481 struct timeval *now) {480 static void * 481 stratcon_datastore_check_loadall(void *vsn) { 482 storagenode_info *sn = vsn; 482 483 ds_single_detail *d; 483 484 int i, row_count = 0, good = 0; 484 485 char buff[1024]; 485 486 conn_q *cq; 486 if(!(mask & EVENTER_ASYNCH_WORK)) return 0; 487 if(mask & EVENTER_ASYNCH_CLEANUP) return 0; 488 489 cq = get_conn_q_for_metanode(); 490 stratcon_database_connect(cq); 487 488 cq = get_conn_q_for_remote(NULL,NULL,sn->fqdn,sn->dsn); 489 i = 0; 490 while(stratcon_database_connect(cq)) { 491 if(i++ > 4) { 492 noitL(noit_error, "giving up on storage node: %s\n", sn->fqdn); 493 release_conn_q(cq); 494 return (void *)good; 495 } 496 sleep(1); 497 } 491 498 d = calloc(1, sizeof(*d)); 492 499 GET_QUERY(check_loadall); … … 525 532 good++; 526 533 } 527 noitL(noit_error, "Staged %d/%d remembered checks into IEP\n", good, row_count); 534 noitL(noit_error, "Staged %d/%d remembered checks from %s into IEP\n", 535 good, sn->fqdn, row_count); 528 536 bad_row: 529 537 free_params((ds_single_detail *)d); 530 538 free(d); 531 539 release_conn_q(cq); 540 return (void *)good; 541 } 542 static int 543 stratcon_datastore_asynch_drive_iep(eventer_t e, int mask, void *closure, 544 struct timeval *now) { 545 storagenode_info self = { 0, NULL, NULL }, **sns = NULL; 546 pthread_t *jobs = NULL; 547 int nodes, i = 0, tcnt = 0; 548 if(!(mask & EVENTER_ASYNCH_WORK)) return 0; 549 if(mask & EVENTER_ASYNCH_CLEANUP) return 0; 550 551 pthread_mutex_lock(&storagenode_to_info_cache_lock); 552 nodes = storagenode_to_info_cache.size; 553 jobs = calloc(MAX(1,nodes), sizeof(*jobs)); 554 sns = calloc(MAX(1,nodes), sizeof(*sns)); 555 if(nodes == 0) sns[nodes++] = &self; 556 else { 557 noit_hash_iter iter = NOIT_HASH_ITER_ZERO; 558 const char *k; 559 void *v; 560 int klen; 561 while(noit_hash_next(&storagenode_to_info_cache, 562 &iter, &k, &klen, &v)) { 563 sns[i++] = (storagenode_info *)v; 564 } 565 } 566 pthread_mutex_unlock(&storagenode_to_info_cache_lock); 567 568 for(i=0; i<nodes; i++) { 569 if(pthread_create(&jobs[i], NULL, 570 stratcon_datastore_check_loadall, sns[i]) != 0) { 571 noitL(noit_error, "Failed to spawn thread: %s\n", strerror(errno)); 572 } 573 } 574 for(i=0; i<nodes; i++) { 575 void *good; 576 pthread_join(jobs[i], &good); 577 tcnt += (int)(vpsized_int)good; 578 } 579 noitL(noit_error, "Loaded all %d check states.\n", tcnt); 532 580 return 0; 533 581 } … … 839 887 if(PQstatus(cq->dbh) == CONNECTION_OK) return 0; 840 888 PQreset(cq->dbh); 889 if(PQstatus(cq->dbh) != CONNECTION_OK) { 890 noitL(noit_error, "Error reconnecting to database: '%s'\nError: %s\n", 891 dsn, PQerrorMessage(cq->dbh)); 892 return -1; 893 } 841 894 if(stratcon_database_post_connect(cq)) return -1; 842 895 if(PQstatus(cq->dbh) == CONNECTION_OK) return 0; … … 848 901 cq->dbh = PQconnectdb(dsn); 849 902 if(!cq->dbh) return -1; 903 if(PQstatus(cq->dbh) != CONNECTION_OK) { 904 noitL(noit_error, "Error reconnecting to database: '%s'\nError: %s\n", 905 dsn, PQerrorMessage(cq->dbh)); 906 return -1; 907 } 850 908 if(stratcon_database_post_connect(cq)) return -1; 851 909 if(PQstatus(cq->dbh) == CONNECTION_OK) return 0; … … 1156 1214 ij->remote_str = strdup(remote_str); 1157 1215 ij->remote_cn = strdup(remote_cn); 1158 ij->fqdn = strdup(fqdn);1216 ij->fqdn = fqdn_in ? strdup(fqdn_in) : NULL; 1159 1217 ij->storagenode_id = storagenode_id; 1160 1218 ij->filename = strdup(jpath); … … 1235 1293 uuidinfo->sid = sid; 1236 1294 uuidinfo->uuid_str = strdup(uuid_str); 1295 uuidinfo->storagenode_id = storagenode_id; 1237 1296 uuidinfo->remote_cn = strdup(remote_cn); 1238 1297 noit_hash_store(&uuid_to_info_cache, … … 1298 1357 interim_journal_t *ij = NULL; 1299 1358 char uuid_str[UUID_STR_LEN+1], *cp; 1300 const char *fqdn , *dsn;1359 const char *fqdn = NULL, *dsn = NULL; 1301 1360 int storagenode_id = 0; 1302 1361 uuid_t checkid; … … 1482 1541 root = opendir(path); 1483 1542 if(!root) return; 1484 while(readdir_r(root, &de, &entry) == 0 && entry != NULL) cnt++; 1485 rewinddir(root); 1543 while(portable_readdir_r(root, &de, &entry) == 0 && entry != NULL) cnt++; 1544 closedir(root); 1545 root = opendir(path); 1546 if(!root) return; 1486 1547 entries = malloc(sizeof(*entries) * cnt); 1487 while( readdir_r(root, &de, &entry) == 0 && entry != NULL) {1548 while(portable_readdir_r(root, &de, &entry) == 0 && entry != NULL) { 1488 1549 if(i < cnt) { 1489 1550 entries[i++] = strdup(entry->d_name); … … 1590 1651 uuidinfo->uuid_str = strdup(uuid_str); 1591 1652 uuidinfo->remote_cn = strdup(remote_cn); 1653 uuidinfo->storagenode_id = storagenode_id; 1592 1654 uuidinfo->sid = sid; 1593 1655 noit_hash_store(&uuid_to_info_cache, src/stratcon_iep.c
r47a77d0 r44ff396 519 519 } 520 520 else { 521 noitL(noit_iep, "no iep handler for: '%s'\n", job->line);521 noitL(noit_iep, "no iep connection, skipping line: '%s'\n", job->line); 522 522 } 523 523 return 0; … … 663 663 &info->command)) { 664 664 noitL(noit_error, "No IEP start command provided. You're on your own.\n"); 665 // goto bail; 666 // If you want to start it as a seperate process 665 setup_iep_connection_later(0); 667 666 return; 668 667 }
