Hi guys:

Another backport request.  This is already fixed in trunk, and I would
like this to be backported to 3.0.x tree.  Please refer to the
attached patch.

Patch includes changes from revisions 1122, 1138, 1142, 1152, 1154 and
1158 from trunk.

Cheers,

Bernard
Index: gmetad/process_xml.c
===================================================================
--- gmetad/process_xml.c	(revision 1139)
+++ gmetad/process_xml.c	(working copy)
@@ -216,7 +216,7 @@
                source->ds = xmldata->ds;
 
                /* Initialize the partial sum lock */
-               source->sum_finished = (pthread_mutex_t*) 
+               source->sum_finished = (pthread_mutex_t *) 
                        malloc(sizeof(pthread_mutex_t));
                pthread_mutex_init(source->sum_finished, NULL);
 
@@ -228,13 +228,14 @@
             {  /* Found Cluster. Put into our Source buffer in xmldata. */
                memcpy(source, hash_datum->data, hash_datum->size);
                datum_free(hash_datum);
-               source->hosts_up = 0;
-               source->hosts_down = 0;
 
                /* Grab the "partial sum" mutex until we are finished
                 * summarizing. Needs to be done asap.*/
                pthread_mutex_lock(source->sum_finished);
 
+               source->hosts_up = 0;
+               source->hosts_down = 0;
+
                hash_foreach(source->metric_summary, zero_out_summary, NULL);
             }
 
@@ -332,7 +333,7 @@
          source->ds = xmldata->ds;
          
          /* Initialize the partial sum lock */
-         source->sum_finished = (pthread_mutex_t*) 
+         source->sum_finished = (pthread_mutex_t *) 
                  malloc(sizeof(pthread_mutex_t));
          pthread_mutex_init(source->sum_finished, NULL);
 
@@ -344,12 +345,12 @@
          memcpy(source, hash_datum->data, hash_datum->size);
          datum_free(hash_datum);
 
-         source->hosts_up = 0;
-         source->hosts_down = 0;
-
          /* We need this lock before zeroing metric sums. */
          pthread_mutex_lock(source->sum_finished);
 
+         source->hosts_up = 0;
+         source->hosts_down = 0;
+
          hash_foreach(source->metric_summary, zero_out_summary, NULL);
       }
 
@@ -946,7 +947,11 @@
 endElement_GRID(void *data, const char *el)
 {
    xmldata_t *xmldata = (xmldata_t *) data;
+   Source_t *source = &xmldata->source;
 
+   /*release the partial sum mutex */
+   pthread_mutex_unlock(source->sum_finished);
+
    if (gmetad_config.scalable_mode)
       {
          xmldata->grid_depth--;
@@ -984,7 +989,6 @@
 
          /* We insert here to get an accurate hosts up/down value. */
          rdatum = hash_insert( &hashkey, &hashval, xmldata->root);
-         source->sum_finished = NULL; /* remember that we released the lock */
          if (!rdatum) {
                err_msg("Could not insert source %s", xmldata->sourcename);
                return 1;
@@ -1060,14 +1064,6 @@
          xmldata.rval = 1;
       }
 
-   /* Release lock again for good measure (required under certain errors). */
-   if (xmldata.source.sum_finished)
-      {
-         rval = pthread_mutex_unlock(xmldata.source.sum_finished);
-         if (rval!=0)
-            err_msg("Could not release summary lock for %s", d->name);
-      }
-
    /* Free memory that might have been allocated in xmldata */
    if (xmldata.sourcename)
       free(xmldata.sourcename);
Index: gmetad/gmetad.c
===================================================================
--- gmetad/gmetad.c	(revision 1139)
+++ gmetad/gmetad.c	(working copy)
@@ -191,8 +191,6 @@
    /* Need to be sure the source has a complete sum for its metrics. */
    pthread_mutex_lock(source->sum_finished);
 
-    /* err_msg("Doing root summary for source %s", source->ds->name); */
-
    /* We know that all these metrics are numeric. */
    rc = hash_foreach(source->metric_summary, sum_metrics, arg);
 
@@ -200,6 +198,7 @@
    root.hosts_up += source->hosts_up;
    root.hosts_down += source->hosts_down;
 
+   /* summary completed for source */
    pthread_mutex_unlock(source->sum_finished);
 
    return rc;
@@ -393,6 +392,11 @@
       }
    debug_msg("interactive xml listening on port %d", c->interactive_port);
 
+   /* initialize summary mutex */
+   root.sum_finished = (pthread_mutex_t *) 
+                          malloc(sizeof(pthread_mutex_t));
+   pthread_mutex_init(root.sum_finished, NULL);
+
    pthread_attr_init( &attr );
    pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED );
 
@@ -417,6 +421,9 @@
          sleep_time = 10 + ((30-10)*1.0) * rand()/(RAND_MAX + 1.0);
          sleep(sleep_time);
 
+         /* Need to be sure root is locked while doing summary */
+         pthread_mutex_lock(root.sum_finished);
+
          /* Flush the old values */
          hash_foreach(root.metric_summary, zero_out_summary, NULL);
          root.hosts_up = 0;
@@ -425,10 +432,12 @@
          /* Sum the new values */
          hash_foreach(root.authority, do_root_summary, NULL );
 
+	 /* summary completed */
+         pthread_mutex_unlock(root.sum_finished);
+
          /* Save them to RRD */
          hash_foreach(root.metric_summary, write_root_summary, NULL);
       }
 
    return 0;
 }
-
Index: gmetad/server.c
===================================================================
--- gmetad/server.c	(revision 1139)
+++ gmetad/server.c	(working copy)
@@ -106,7 +106,15 @@
       source->hosts_up, source->hosts_down);
    if (rc) return 1;
 
-   return hash_foreach(source->metric_summary, metric_summary, (void*) client);
+   pthread_mutex_unlock(root.sum_finished);
+   if (source->ds) {
+      pthread_mutex_lock(source->sum_finished);
+      rc = hash_foreach(source->metric_summary, metric_summary, (void*) client);
+      pthread_mutex_unlock(source->sum_finished);
+   }
+   pthread_mutex_unlock(root.sum_finished);
+   
+   return rc;
 }
 
 
@@ -254,7 +262,6 @@
    return 0;
 }
 
-
 int
 applyfilter(client_t *client, Generic_t *node)
 {
@@ -273,7 +280,7 @@
          return 0;
 
       case SUMMARY:
-         return source_summary((Source_t*) node, client);
+	 return source_summary((Source_t*) node, client);
 
       default:
          break;
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Ganglia-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ganglia-developers

Reply via email to