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.


			
			
				changes/97/197/1
			
			
		
Igor Goncharovskiy 11 years ago
parent 8313964d72
commit a1e0a5e4b0

@ -228,7 +228,6 @@ static int write_cdr(struct ast_cdr *cdr)
int res = 0; int res = 0;
char *error = NULL; char *error = NULL;
char *sql = NULL; char *sql = NULL;
int count = 0;
if (db == NULL) { if (db == NULL) {
/* Should not have loaded, but be failsafe. */ /* Should not have loaded, but be failsafe. */
@ -264,16 +263,7 @@ static int write_cdr(struct ast_cdr *cdr)
ast_free(value_string); ast_free(value_string);
} }
/* XXX This seems awful arbitrary... */ if (sqlite3_exec(db, sql, NULL, NULL, &error) != SQLITE_OK) {
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) {
ast_log(LOG_ERROR, "%s. SQL: %s.\n", error, sql); ast_log(LOG_ERROR, "%s. SQL: %s.\n", error, sql);
sqlite3_free(error); sqlite3_free(error);
} }
@ -317,7 +307,7 @@ static int load_module(void)
free_config(0); free_config(0);
return AST_MODULE_LOAD_DECLINE; return AST_MODULE_LOAD_DECLINE;
} }
sqlite3_busy_timeout(db, 1000);
/* is the table there? */ /* is the table there? */
sql = sqlite3_mprintf("SELECT COUNT(AcctId) FROM %q;", table); sql = sqlite3_mprintf("SELECT COUNT(AcctId) FROM %q;", table);
res = sqlite3_exec(db, sql, NULL, NULL, NULL); res = sqlite3_exec(db, sql, NULL, NULL, NULL);

@ -234,7 +234,6 @@ static void write_cel(struct ast_event *event)
{ {
char *error = NULL; char *error = NULL;
char *sql = NULL; char *sql = NULL;
int count = 0;
if (db == NULL) { if (db == NULL) {
/* Should not have loaded, but be failsafe. */ /* Should not have loaded, but be failsafe. */
@ -269,18 +268,7 @@ static void write_cel(struct ast_event *event)
ast_free(value_string); ast_free(value_string);
} }
/* XXX This seems awful arbitrary... */ if (sqlite3_exec(db, sql, NULL, NULL, &error) != SQLITE_OK) {
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) {
ast_log(LOG_ERROR, "%s. SQL: %s.\n", error, sql); ast_log(LOG_ERROR, "%s. SQL: %s.\n", error, sql);
sqlite3_free(error); sqlite3_free(error);
} }
@ -288,6 +276,7 @@ static void write_cel(struct ast_event *event)
if (sql) { if (sql) {
sqlite3_free(sql); sqlite3_free(sql);
} }
ast_mutex_unlock(&lock);
return; return;
} }
@ -320,7 +309,7 @@ static int load_module(void)
free_config(); free_config();
return AST_MODULE_LOAD_DECLINE; return AST_MODULE_LOAD_DECLINE;
} }
sqlite3_busy_timeout(db, 1000);
/* is the table there? */ /* is the table there? */
sql = sqlite3_mprintf("SELECT COUNT(*) FROM %q;", table); sql = sqlite3_mprintf("SELECT COUNT(*) FROM %q;", table);
res = sqlite3_exec(db, sql, NULL, NULL, NULL); res = sqlite3_exec(db, sql, NULL, NULL, NULL);

@ -257,6 +257,7 @@ static int db_open(void)
ast_mutex_unlock(&dblock); ast_mutex_unlock(&dblock);
return -1; return -1;
} }
ast_mutex_unlock(&dblock); ast_mutex_unlock(&dblock);
return 0; return 0;
@ -283,9 +284,8 @@ static int db_execute_sql(const char *sql, int (*callback)(void *, int, char **,
char *errmsg = NULL; char *errmsg = NULL;
int res =0; int res =0;
sqlite3_exec(astdb, sql, callback, arg, &errmsg); if (sqlite3_exec(astdb, sql, callback, arg, &errmsg) != SQLITE_OK) {
if (errmsg) { ast_log(LOG_WARNING, "Error executing SQL (%s): %s\n", sql, errmsg);
ast_log(LOG_WARNING, "Error executing SQL: %s\n", errmsg);
sqlite3_free(errmsg); sqlite3_free(errmsg);
res = -1; res = -1;
} }

@ -324,6 +324,7 @@ static int db_open(struct realtime_sqlite3_db *db)
ao2_unlock(db); ao2_unlock(db);
return -1; return -1;
} }
sqlite3_busy_timeout(db->handle, 1000);
if (db->debug) { if (db->debug) {
sqlite3_trace(db->handle, trace_cb, db); sqlite3_trace(db->handle, trace_cb, db);

Loading…
Cancel
Save