Changeset 44ff3960c287fb9db5673a83f1165dfe9a8ae96e

Show
Ignore:
Timestamp:
10/27/09 19:12:58 (5 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1256670778 +0000
git-parent:

[a905d08014f72c334b467899569fc812d9e5ca7e]

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

fixes on Solaris, fixes #203

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • configure.in

    r4790fc8 r44ff396  
    5656        fi 
    5757        if test "x$CC" != "xgcc" ; then 
    58                 CFLAGS="$CFLAGS -D_POSIX_PTHREAD_SEMANTICS -mt" 
     58                CFLAGS="$CFLAGS -mt" 
    5959        fi 
    6060        PICFLAGS="-Kpic" 
  • src/noit_defines.h

    r47a77d0 r44ff396  
    133133} 
    134134 
     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 
    135140#include "noitedit/strlcpy.h" 
    136141 
  • src/stratcon_datastore.c

    rd2dd72f r44ff396  
    450450  if(d->rv != PGRES_COMMAND_OK && \ 
    451451     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); \ 
    454455    PQclear(d->res); \ 
    455456    goto bad_row; \ 
     
    477478} while(0) 
    478479 
    479 static int 
    480 stratcon_datastore_asynch_drive_iep(eventer_t e, int mask, void *closure, 
    481                                     struct timeval *now) { 
     480static void * 
     481stratcon_datastore_check_loadall(void *vsn) { 
     482  storagenode_info *sn = vsn; 
    482483  ds_single_detail *d; 
    483484  int i, row_count = 0, good = 0; 
    484485  char buff[1024]; 
    485486  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  } 
    491498  d = calloc(1, sizeof(*d)); 
    492499  GET_QUERY(check_loadall); 
     
    525532    good++; 
    526533  } 
    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); 
    528536 bad_row: 
    529537  free_params((ds_single_detail *)d); 
    530538  free(d); 
    531539  release_conn_q(cq); 
     540  return (void *)good; 
     541} 
     542static int 
     543stratcon_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); 
    532580  return 0; 
    533581} 
     
    839887    if(PQstatus(cq->dbh) == CONNECTION_OK) return 0; 
    840888    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    } 
    841894    if(stratcon_database_post_connect(cq)) return -1; 
    842895    if(PQstatus(cq->dbh) == CONNECTION_OK) return 0; 
     
    848901  cq->dbh = PQconnectdb(dsn); 
    849902  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  } 
    850908  if(stratcon_database_post_connect(cq)) return -1; 
    851909  if(PQstatus(cq->dbh) == CONNECTION_OK) return 0; 
     
    11561214    ij->remote_str = strdup(remote_str); 
    11571215    ij->remote_cn = strdup(remote_cn); 
    1158     ij->fqdn = strdup(fqdn)
     1216    ij->fqdn = fqdn_in ? strdup(fqdn_in) : NULL
    11591217    ij->storagenode_id = storagenode_id; 
    11601218    ij->filename = strdup(jpath); 
     
    12351293    uuidinfo->sid = sid; 
    12361294    uuidinfo->uuid_str = strdup(uuid_str); 
     1295    uuidinfo->storagenode_id = storagenode_id; 
    12371296    uuidinfo->remote_cn = strdup(remote_cn); 
    12381297    noit_hash_store(&uuid_to_info_cache, 
     
    12981357  interim_journal_t *ij = NULL; 
    12991358  char uuid_str[UUID_STR_LEN+1], *cp; 
    1300   const char *fqdn, *dsn
     1359  const char *fqdn = NULL, *dsn = NULL
    13011360  int storagenode_id = 0; 
    13021361  uuid_t checkid; 
     
    14821541  root = opendir(path); 
    14831542  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; 
    14861547  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) { 
    14881549    if(i < cnt) { 
    14891550      entries[i++] = strdup(entry->d_name); 
     
    15901651    uuidinfo->uuid_str = strdup(uuid_str); 
    15911652    uuidinfo->remote_cn = strdup(remote_cn); 
     1653    uuidinfo->storagenode_id = storagenode_id; 
    15921654    uuidinfo->sid = sid; 
    15931655    noit_hash_store(&uuid_to_info_cache, 
  • src/stratcon_iep.c

    r47a77d0 r44ff396  
    519519  } 
    520520  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);  
    522522  } 
    523523  return 0; 
     
    663663                           &info->command)) { 
    664664    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); 
    667666    return; 
    668667  }