[asterisk-commits] igorg: branch 11 r416337 - in /branches/11: ./ cdr/ cel/ main/ res/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Jun 16 04:00:27 CDT 2014
Author: igorg
Date: Mon Jun 16 04:00:18 2014
New Revision: 416337
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=416337
Log:
We have faced situation when using CDR and CEL by sqlite3 modules. With system having high load (~100 concurrent calls created by sipp) we found many cdr and cel records missed. There is special finction in sqlite3, that make able to fix this situation - sqlite3_wait_timeout, that also can replace awful code cdr_sqlite3 ad cel_sqlite3 modules. Also this function can be used for aastdb and res_config_sqlite3 to avoid missed writes to sqlite db.
#ASTERISK-23766 #close
Reported by: Igor Goncharovsky
Review: https://reviewboard.asterisk.org/r/3559/
........
Merged revisions 416336 from http://svn.asterisk.org/svn/asterisk/branches/1.8
Modified:
branches/11/ (props changed)
branches/11/cdr/cdr_sqlite3_custom.c
branches/11/cel/cel_sqlite3_custom.c
branches/11/main/db.c
branches/11/res/res_config_sqlite3.c
Propchange: branches/11/
------------------------------------------------------------------------------
Binary property 'branch-1.8-merged' - no diff available.
Modified: branches/11/cdr/cdr_sqlite3_custom.c
URL: http://svnview.digium.com/svn/asterisk/branches/11/cdr/cdr_sqlite3_custom.c?view=diff&rev=416337&r1=416336&r2=416337
==============================================================================
--- branches/11/cdr/cdr_sqlite3_custom.c (original)
+++ branches/11/cdr/cdr_sqlite3_custom.c Mon Jun 16 04:00:18 2014
@@ -228,7 +228,6 @@
int res = 0;
char *error = NULL;
char *sql = NULL;
- int count = 0;
if (db == NULL) {
/* Should not have loaded, but be failsafe. */
@@ -264,16 +263,7 @@
ast_free(value_string);
}
- /* XXX This seems awful arbitrary... */
- for (count = 0; count < 5; count++) {
- res = sqlite3_exec(db, sql, NULL, NULL, &error);
- if (res != SQLITE_BUSY && res != SQLITE_LOCKED) {
- break;
- }
- usleep(200);
- }
-
- if (error) {
+ if (sqlite3_exec(db, sql, NULL, NULL, &error) != SQLITE_OK) {
ast_log(LOG_ERROR, "%s. SQL: %s.\n", error, sql);
sqlite3_free(error);
}
@@ -315,7 +305,7 @@
free_config(0);
return AST_MODULE_LOAD_DECLINE;
}
-
+ sqlite3_busy_timeout(db, 1000);
/* is the table there? */
sql = sqlite3_mprintf("SELECT COUNT(AcctId) FROM %q;", table);
res = sqlite3_exec(db, sql, NULL, NULL, NULL);
Modified: branches/11/cel/cel_sqlite3_custom.c
URL: http://svnview.digium.com/svn/asterisk/branches/11/cel/cel_sqlite3_custom.c?view=diff&rev=416337&r1=416336&r2=416337
==============================================================================
--- branches/11/cel/cel_sqlite3_custom.c (original)
+++ branches/11/cel/cel_sqlite3_custom.c Mon Jun 16 04:00:18 2014
@@ -231,7 +231,6 @@
{
char *error = NULL;
char *sql = NULL;
- int count = 0;
if (db == NULL) {
/* Should not have loaded, but be failsafe. */
@@ -266,18 +265,7 @@
ast_free(value_string);
}
- /* XXX This seems awful arbitrary... */
- for (count = 0; count < 5; count++) {
- int res = sqlite3_exec(db, sql, NULL, NULL, &error);
- if (res != SQLITE_BUSY && res != SQLITE_LOCKED) {
- break;
- }
- usleep(200);
- }
-
- ast_mutex_unlock(&lock);
-
- if (error) {
+ if (sqlite3_exec(db, sql, NULL, NULL, &error) != SQLITE_OK) {
ast_log(LOG_ERROR, "%s. SQL: %s.\n", error, sql);
sqlite3_free(error);
}
@@ -285,6 +273,7 @@
if (sql) {
sqlite3_free(sql);
}
+ ast_mutex_unlock(&lock);
return;
}
@@ -319,7 +308,7 @@
free_config();
return AST_MODULE_LOAD_DECLINE;
}
-
+ sqlite3_busy_timeout(db, 1000);
/* is the table there? */
sql = sqlite3_mprintf("SELECT COUNT(*) FROM %q;", table);
res = sqlite3_exec(db, sql, NULL, NULL, NULL);
Modified: branches/11/main/db.c
URL: http://svnview.digium.com/svn/asterisk/branches/11/main/db.c?view=diff&rev=416337&r1=416336&r2=416337
==============================================================================
--- branches/11/main/db.c (original)
+++ branches/11/main/db.c Mon Jun 16 04:00:18 2014
@@ -257,6 +257,7 @@
ast_mutex_unlock(&dblock);
return -1;
}
+
ast_mutex_unlock(&dblock);
return 0;
@@ -283,9 +284,8 @@
char *errmsg = NULL;
int res =0;
- sqlite3_exec(astdb, sql, callback, arg, &errmsg);
- if (errmsg) {
- ast_log(LOG_WARNING, "Error executing SQL: %s\n", errmsg);
+ if (sqlite3_exec(astdb, sql, callback, arg, &errmsg) != SQLITE_OK) {
+ ast_log(LOG_WARNING, "Error executing SQL (%s): %s\n", sql, errmsg);
sqlite3_free(errmsg);
res = -1;
}
Modified: branches/11/res/res_config_sqlite3.c
URL: http://svnview.digium.com/svn/asterisk/branches/11/res/res_config_sqlite3.c?view=diff&rev=416337&r1=416336&r2=416337
==============================================================================
--- branches/11/res/res_config_sqlite3.c (original)
+++ branches/11/res/res_config_sqlite3.c Mon Jun 16 04:00:18 2014
@@ -315,6 +315,7 @@
ao2_unlock(db);
return -1;
}
+ sqlite3_busy_timeout(db->handle, 1000);
if (db->debug) {
sqlite3_trace(db->handle, trace_cb, db);
More information about the asterisk-commits
mailing list