[mirrorbrain-commits] r8256 - /trunk/mod_mirrorbrain/mod_mirrorbrain.c

From: <poeml_at_mirrorbrain.org>
Date: Tue, 13 Mar 2012 19:29:02 -0000
Author: poeml
Date: Tue Mar 13 20:29:02 2012
New Revision: 8256

URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain?rev=8256&view=rev
Log:
mod_mirrorbrain:
- Reworked error handling regarding the acquisition of database connections,
  including more detailed logging of errors.
- This fixes a crash that could happen when no database connection was
  available -- where the logging code wrongly tried to log details about the
  (unavailable) connection. (This affected only setups with
  MirrorBrainFallback configuration.)

Modified:
    trunk/mod_mirrorbrain/mod_mirrorbrain.c

Modified: trunk/mod_mirrorbrain/mod_mirrorbrain.c
URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/mod_mirrorbrain/mod_mirrorbrain.c?rev=8256&r1=8255&r2=8256&view=diff
==============================================================================
--- trunk/mod_mirrorbrain/mod_mirrorbrain.c	(original)
+++ trunk/mod_mirrorbrain/mod_mirrorbrain.c	Tue Mar 13 20:29:02 2012
_at_@ -1162,7 +1162,14 @@
     }
     if (dbd == NULL) {
         ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, 
-                "[mod_mirrorbrain] Don't have a database connection");
+                "[mod_mirrorbrain] Don't have a database connection for hashes");
+        return NULL;
+    }
+
+    if (!dbd->prepared) {
+        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, 
+            "[mod_mirrorbrain] dbd->prepared hash is NULL");
+        dbd = NULL; /* don't try to use again */
         return NULL;
     }
 
_at_@ -1172,7 +1179,7 @@
         ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, 
                       "[mod_mirrorbrain] Could not get prepared statement labelled '%s'",
                       scfg->query_hash_label);
-
+        dbd = NULL;
         return NULL;
     }
 
_at_@ -1889,9 +1896,19 @@
         ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, 
                 "[mod_mirrorbrain] Error acquiring database connection");
         if (apr_is_empty_array(cfg->fallbacks)) {
-            setenv_give(r, "file");
+            setenv_give(r, "file (database_not_reached)");
             return DECLINED; /* fail gracefully */
         }
+
+    }
+    if (dbd && !dbd->prepared) {
+        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, 
+            "[mod_mirrorbrain] dbd->prepared hash is NULL");
+        if (apr_is_empty_array(cfg->fallbacks)) {
+            setenv_give(r, "file (dbd_prepared_is_NULL)");
+            return DECLINED; /* fail gracefully */
+        }
+        dbd = NULL; /* stay away! */
     }
     debugLog(r, cfg, "Successfully acquired database connection.");
 
_at_@ -1942,34 +1959,37 @@
 
 
     if (dbd) {
+
         statement = apr_hash_get(dbd->prepared, scfg->query_label, APR_HASH_KEY_STRING);
-    }
-
-    if (!dbd || !statement) {
-        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, 
-                      "[mod_mirrorbrain] Could not get prepared statement labelled '%s'",
-                      scfg->query_label);
-
-        /* log existing prepared statements. It might help with figuring out
-         * misconfigurations */
-        ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, 
-                      "[mod_mirrorbrain] dbd->prepared hash contains %d key/value pairs", 
-                      apr_hash_count(dbd->prepared));
-
-        apr_hash_index_t *hi;
-        const char *label, *query;
-        for (hi = apr_hash_first(r->pool, dbd->prepared); hi; hi = apr_hash_next(hi)) {
-            apr_hash_this(hi, (void*) &label, NULL, (void*) &query);
+        if (!statement) {
+            ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, 
+                          "[mod_mirrorbrain] Could not get prepared statement labelled '%s'",
+                          scfg->query_label);
+
+            /* log existing prepared statements. It might help with figuring out
+             * misconfigurations */
             ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, 
-                          "[mod_mirrorbrain] dbd->prepared dump: key %s, value 0x%08lx", label, (long)query);
-        }
-
-        ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, 
-                      "[mod_mirrorbrain] Hint: connection strings defined with "
-                      "DBDParams must be unique. The same string cannot be used "
-                      "in two vhosts.");
-
+                          "[mod_mirrorbrain] dbd->prepared hash contains %d key/value pairs", 
+                          apr_hash_count(dbd->prepared));
+            apr_hash_index_t *hi;
+            const char *label, *query;
+            for (hi = apr_hash_first(r->pool, dbd->prepared); hi; hi = apr_hash_next(hi)) {
+                apr_hash_this(hi, (void*) &label, NULL, (void*) &query);
+                ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, 
+                              "[mod_mirrorbrain] dbd->prepared dump: key %s, value 0x%08lx", label, (long)query);
+            }
+
+            dbd = NULL; /* don't use */
+
+            if (apr_is_empty_array(cfg->fallbacks)) {
+                setenv_give(r, "file (dbd_statement_is_NULL)");
+                return DECLINED;
+            }
+        }
+
+    } else {
         if (apr_is_empty_array(cfg->fallbacks)) {
+            setenv_give(r, "file");
             return DECLINED;
         }
     }




_______________________________________________
mirrorbrain-commits mailing list
Archive: http://mirrorbrain.org/archive/mirrorbrain-commits/

Note: To remove yourself from this list, send a mail with the content
 	unsubscribe
to the address mirrorbrain-commits-request_at_mirrorbrain.org
Received on Tue Mar 13 2012 - 19:29:14 GMT

This archive was generated by hypermail 2.3.0 : Tue Mar 13 2012 - 19:32:02 GMT