Enables runtime configuration of busy_timeout for sqlite databases.
Default timeout remains 1000ms.
ASTERISK-27014 #close
Change-Id: I8921a3aac3c335843be4cb17d2dd0a5c157a36da
static char table[80];
static char *columns;
+static int busy_timeout;
struct values {
AST_LIST_ENTRY(values) list;
strcpy(table, "cdr");
}
+ /* sqlite3_busy_timeout in miliseconds */
+ if ((tmp = ast_variable_retrieve(cfg, "master", "busy_timeout")) != NULL) {
+ if (ast_parse_arg(tmp, PARSE_INT32|PARSE_DEFAULT, &busy_timeout, 1000) != 0) {
+ ast_log(LOG_WARNING, "Invalid busy_timeout value '%s' specified. Using 1000 instead.\n", tmp);
+ }
+ } else {
+ busy_timeout = 1000;
+ }
+
/* Columns */
if (load_column_config(ast_variable_retrieve(cfg, "master", "columns"))) {
ast_config_destroy(cfg);
free_config(0);
return AST_MODULE_LOAD_DECLINE;
}
- sqlite3_busy_timeout(db, 1000);
+ sqlite3_busy_timeout(db, busy_timeout);
/* is the table there? */
sql = sqlite3_mprintf("SELECT COUNT(AcctId) FROM %q;", table);
res = sqlite3_exec(db, sql, NULL, NULL, NULL);
* \bug Handling of this var is crash prone on reloads
*/
static char *columns;
+static int busy_timeout;
struct values {
char *expression;
strcpy(table, "cel");
}
+ /* sqlite3_busy_timeout in miliseconds */
+ if ((tmp = ast_variable_retrieve(cfg, "master", "busy_timeout")) != NULL) {
+ if (ast_parse_arg(tmp, PARSE_INT32|PARSE_DEFAULT, &busy_timeout, 1000) != 0) {
+ ast_log(LOG_WARNING, "Invalid busy_timeout value '%s' specified. Using 1000 instead.\n", tmp);
+ }
+ } else {
+ busy_timeout = 1000;
+ }
+
/* Columns */
if (load_column_config(ast_variable_retrieve(cfg, "master", "columns"))) {
ast_config_destroy(cfg);
free_config();
return AST_MODULE_LOAD_DECLINE;
}
- sqlite3_busy_timeout(db, 1000);
+ sqlite3_busy_timeout(db, busy_timeout);
/* is the table there? */
sql = sqlite3_mprintf("SELECT COUNT(*) FROM %q;", table);
res = sqlite3_exec(db, sql, NULL, NULL, NULL);
;table => cdr
;columns => calldate, clid, dcontext, channel, dstchannel, lastapp, lastdata, duration, billsec, disposition, amaflags, accountcode, uniqueid, userfield, test
;values => '${CDR(start)}','${CDR(clid)}','${CDR(dcontext)}','${CDR(channel)}','${CDR(dstchannel)}','${CDR(lastapp)}','${CDR(lastdata)}','${CDR(duration)}','${CDR(billsec)}','${CDR(disposition)}','${CDR(amaflags)}','${CDR(accountcode)}','${CDR(uniqueid)}','${CDR(userfield)}','${CDR(test)}'
+;busy_timeout => 1000
;Enable High Resolution Times for billsec and duration fields
;values => '${CDR(start)}','${CDR(clid)}','${CDR(dcontext)}','${CDR(channel)}','${CDR(dstchannel)}','${CDR(lastapp)}','${CDR(lastdata)}','${CDR(duration,f)}','${CDR(billsec,f)}','${CDR(disposition)}','${CDR(amaflags)}','${CDR(accountcode)}','${CDR(uniqueid)}','${CDR(userfield)}','${CDR(test)}'
;table => cel
;columns => eventtype, eventtime, cidname, cidnum, cidani, cidrdnis, ciddnid, context, exten, channame, appname, appdata, amaflags, accountcode, uniqueid, userfield, peer, userdeftype, eventextra
;values => '${eventtype}','${eventtime}','${CALLERID(name)}','${CALLERID(num)}','${CALLERID(ANI)}','${CALLERID(RDNIS)}','${CALLERID(DNID)}','${CHANNEL(context)}','${CHANNEL(exten)}','${CHANNEL(channame)}','${CHANNEL(appname)}','${CHANNEL(appdata)}','${CHANNEL(amaflags)}','${CHANNEL(accountcode)}','${CHANNEL(uniqueid)}','${CHANNEL(userfield)}','${BRIDGEPEER}','${userdeftype}','${eventextra}'
+;busy_timeout => 1000
\ No newline at end of file
; to lock for writing.
;
;batch=1000
-
+;
+; busy timeout - timeout in miliseconds to stop waiting for locked database.
+; More info at https://www.sqlite.org/c3ref/busy_timeout.html
+;
+;busy_timeout=1000
\ No newline at end of file
unsigned int exiting:1;
unsigned int wakeup:1;
unsigned int batch;
+ int busy_timeout;
};
struct ao2_container *databases;
ao2_unlock(db);
return -1;
}
- sqlite3_busy_timeout(db->handle, 1000);
+ sqlite3_busy_timeout(db->handle, db->busy_timeout);
if (db->debug) {
sqlite3_trace(db->handle, trace_cb, db);
db->requirements = REALTIME_SQLITE3_REQ_WARN;
db->batch = 100;
ast_string_field_set(db, name, cat);
+ db->busy_timeout = 1000;
for (var = ast_variable_browse(config, cat); var; var = var->next) {
if (!strcasecmp(var->name, "dbfile")) {
ast_app_parse_timelen(var->value, (int *) &db->batch, TIMELEN_MILLISECONDS);
} else if (!strcasecmp(var->name, "debug")) {
db->debug = ast_true(var->value);
+ } else if (!strcasecmp(var->name, "busy_timeout")) {
+ if (ast_parse_arg(var->value, PARSE_INT32|PARSE_DEFAULT, &(db->busy_timeout), 1000) != 0) {
+ ast_log(LOG_WARNING, "Invalid busy_timeout value '%s' at res_config_sqlite3.conf:%d. Using 1000 instead.\n", var->value, var->lineno);
+ }
}
}
db_open(db); /* Also handles setting appropriate debug on new handle */
}
+ if (db->busy_timeout != new->busy_timeout) {
+ db->busy_timeout = new->busy_timeout;
+ sqlite3_busy_timeout(db->handle, db->busy_timeout);
+ }
+
if (db->batch != new->batch) {
if (db->batch == 0) {
db->batch = new->batch;