Module: kamailio Branch: master Commit: 653b7343ebcca5f53f56bace94772a982bf0f887 URL: https://github.com/kamailio/kamailio/commit/653b7343ebcca5f53f56bace94772a98...
Author: Lucian Balaceanu lucian.balaceanu@1and1.ro Committer: Lucian Balaceanu lucian.balaceanu@1and1.ro Date: 2017-05-08T19:10:00+03:00
p_usrloc: limit db writes of error count
- when db_errors_treshold limit is reached kamailio should stop increasing the errors field so as not to load mysql with no use
---
Modified: src/modules/p_usrloc/ul_db.c
---
Diff: https://github.com/kamailio/kamailio/commit/653b7343ebcca5f53f56bace94772a98... Patch: https://github.com/kamailio/kamailio/commit/653b7343ebcca5f53f56bace94772a98...
---
diff --git a/src/modules/p_usrloc/ul_db.c b/src/modules/p_usrloc/ul_db.c index a954259..cf1b940 100644 --- a/src/modules/p_usrloc/ul_db.c +++ b/src/modules/p_usrloc/ul_db.c @@ -162,26 +162,29 @@ int db_handle_error(ul_db_handle_t * handle, int no) { LM_ERR("can't get db.\n"); return -1; } - - if (sprintf(query, "UPDATE %.*s " - "SET %.*s=%.*s+1 " - "WHERE %.*s=%i " - "AND %.*s=%i", - reg_table.len, reg_table.s, - error_col.len, error_col.s, error_col.len, error_col.s, - id_col.len, id_col.s, handle->id, - num_col.len, num_col.s, db->no) < 0) { - LM_ERR("could not print the query\n"); - return -1; - } - tmp.s = query; - tmp.len = strlen(query);
- if (mdb.write.dbf.raw_query (mdb.write.dbh, &tmp, NULL)) { - LM_ERR("error in database update.\n"); - return -1; + if (db->errors < db_error_threshold) { + if (sprintf(query, "UPDATE %.*s " + "SET %.*s=%.*s+1 " + "WHERE %.*s=%i " + "AND %.*s=%i", + reg_table.len, reg_table.s, + error_col.len, error_col.s, error_col.len, error_col.s, + id_col.len, id_col.s, handle->id, + num_col.len, num_col.s, db->no) < 0) { + LM_ERR("could not print the query\n"); + return -1; + } + + tmp.s = query; + tmp.len = strlen(query); + + if (mdb.write.dbf.raw_query (mdb.write.dbh, &tmp, NULL)) { + LM_ERR("error in database update.\n"); + return -1; + } } - + for(i=0; i<DB_NUM; i++){ if (handle->db[i].dbh && handle->db[i].dbf.close){ handle->db[i].dbf.close(handle->db[i].dbh);