]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
We have faced situation when using CDR and CEL by sqlite3 modules. With system having...
authorIgor Goncharovskiy <igor.goncharovsky@gmail.com>
Mon, 16 Jun 2014 08:52:06 +0000 (08:52 +0000)
committerIgor Goncharovskiy <igor.goncharovsky@gmail.com>
Mon, 16 Jun 2014 08:52:06 +0000 (08:52 +0000)
#ASTERISK-23766 #close
Reported by: Igor Goncharovsky

Review: https://reviewboard.asterisk.org/r/3559/

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@416336 65c4cc65-6c06-0410-ace0-fbb531ad65f3

cdr/cdr_sqlite3_custom.c
cel/cel_sqlite3_custom.c

index 65ef5b8a2a8195a80e01a4729ac669f07a7291e7..7cb5f2f726c4c0ad614d17266609ed803cddc953 100644 (file)
@@ -229,7 +229,6 @@ static int write_cdr(struct ast_cdr *cdr)
        int res = 0;
        char *error = NULL;
        char *sql = NULL;
-       int count = 0;
 
        if (db == NULL) {
                /* Should not have loaded, but be failsafe. */
@@ -265,16 +264,7 @@ static int write_cdr(struct ast_cdr *cdr)
                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);
        }
@@ -316,7 +306,7 @@ static int load_module(void)
                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);
index 444df77d3154f26bf77a51e3c9ec26ce2588c58c..ce88be6f733e4acefd27c6df33e15ef3824533c3 100644 (file)
@@ -231,7 +231,6 @@ static void write_cel(const struct ast_event *event, void *userdata)
 {
        char *error = NULL;
        char *sql = NULL;
-       int count = 0;
 
        if (db == NULL) {
                /* Should not have loaded, but be failsafe. */
@@ -266,18 +265,7 @@ static void write_cel(const struct ast_event *event, void *userdata)
                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 @@ static void write_cel(const struct ast_event *event, void *userdata)
        if (sql) {
                sqlite3_free(sql);
        }
+       ast_mutex_unlock(&lock);
 
        return;
 }
@@ -319,7 +308,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);