From a1e0a5e4b07387bcc59afa7c0ab9f960a389ac15 Mon Sep 17 00:00:00 2001 From: Igor Goncharovskiy Date: Mon, 16 Jun 2014 09:04:05 +0000 Subject: 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 ........ Merged revisions 416337 from http://svn.asterisk.org/svn/asterisk/branches/11 ........ Merged revisions 416338 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@416339 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- cel/cel_sqlite3_custom.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'cel') diff --git a/cel/cel_sqlite3_custom.c b/cel/cel_sqlite3_custom.c index 8ff3bd702..110c8dc1c 100644 --- a/cel/cel_sqlite3_custom.c +++ b/cel/cel_sqlite3_custom.c @@ -234,7 +234,6 @@ static void write_cel(struct ast_event *event) { char *error = NULL; char *sql = NULL; - int count = 0; if (db == NULL) { /* Should not have loaded, but be failsafe. */ @@ -269,18 +268,7 @@ static void write_cel(struct ast_event *event) 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); } @@ -288,6 +276,7 @@ static void write_cel(struct ast_event *event) if (sql) { sqlite3_free(sql); } + ast_mutex_unlock(&lock); return; } @@ -320,7 +309,7 @@ static int load_module(void) 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); -- cgit v1.2.3