Browse code

modules/db_mysql: Improved handling of driver error counter

Marius Zbihlei authored on 13/08/2010 11:39:49
Showing 1 changed files
... ...
@@ -104,7 +104,8 @@ static int db_mysql_submit_query(const db1_con_t* _h, const str* _s)
104 104
 	 * Thus the 3 in the loop count. Increasing the loop count over this
105 105
 	 * value shouldn't be needed, but it doesn't hurt either, since the loop
106 106
 	 * will most of the time stop at the second or sometimes at the third
107
-	 * iteration.
107
+	 * iteration. In the case of CR_SERVER_GONE_ERROR and CR_SERVER_LOST the
108
+	 * driver error counter is increased
108 109
 	 */
109 110
 	for (i=0; i < (db_mysql_auto_reconnect ? 3 : 1); i++) {
110 111
 		if (mysql_real_query(CON_CONNECTION(_h), _s->s, _s->len) == 0) {
... ...
@@ -114,12 +115,9 @@ static int db_mysql_submit_query(const db1_con_t* _h, const str* _s)
114 115
 		if (code != CR_SERVER_GONE_ERROR && code != CR_SERVER_LOST) {
115 116
 			break;
116 117
 		}
117
-	}
118
-	LM_ERR("driver error on query: %s\n", mysql_error(CON_CONNECTION(_h)));
119
-	/* Bad queries don't count */
120
-	if(code == CR_SERVER_GONE_ERROR || code == CR_SERVER_LOST) {
121 118
 		counter_inc(mysql_cnts_h.driver_err);
122 119
 	}
120
+	LM_ERR("driver error on query: %s\n", mysql_error(CON_CONNECTION(_h)));
123 121
 	return -2;
124 122
 }
125 123
 
... ...
@@ -157,6 +155,7 @@ void db_mysql_close(db1_con_t* _h)
157 155
  */
158 156
 static int db_mysql_store_result(const db1_con_t* _h, db1_res_t** _r)
159 157
 {
158
+	int code;
160 159
 	if ((!_h) || (!_r)) {
161 160
 		LM_ERR("invalid parameter value\n");
162 161
 		return -1;
... ...
@@ -176,6 +175,10 @@ static int db_mysql_store_result(const db1_con_t* _h, db1_res_t** _r)
176 175
 			goto done;
177 176
 		} else {
178 177
 			LM_ERR("driver error: %s\n", mysql_error(CON_CONNECTION(_h)));
178
+			code = mysql_errno(CON_CONNECTION(_h));
179
+			if (code == CR_SERVER_GONE_ERROR || code == CR_SERVER_LOST) {
180
+				counter_inc(mysql_cnts_h.driver_err);
181
+			}
179 182
 			db_free_result(*_r);
180 183
 			*_r = 0;
181 184
 			return -3;
... ...
@@ -274,7 +277,7 @@ int db_mysql_query(const db1_con_t* _h, const db_key_t* _k, const db_op_t* _op,
274 277
  */
275 278
 int db_mysql_fetch_result(const db1_con_t* _h, db1_res_t** _r, const int nrows)
276 279
 {
277
-	int rows, i;
280
+	int rows, i, code;
278 281
 
279 282
 	if (!_h || !_r || nrows < 0) {
280 283
 		LM_ERR("Invalid parameter value\n");
... ...
@@ -304,6 +307,10 @@ int db_mysql_fetch_result(const db1_con_t* _h, db1_res_t** _r, const int nrows)
304 307
 				return 0;
305 308
 			} else {
306 309
 				LM_ERR("driver error: %s\n", mysql_error(CON_CONNECTION(_h)));
310
+				code = mysql_errno(CON_CONNECTION(_h));
311
+				if (code == CR_SERVER_GONE_ERROR || code == CR_SERVER_LOST) {
312
+					counter_inc(mysql_cnts_h.driver_err);
313
+				}
307 314
 				db_free_result(*_r);
308 315
 				*_r = 0;
309 316
 				return -3;