[asterisk-commits] Sqlite3: make busy timeout configurable. (asterisk[master])
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Jun 1 09:31:25 CDT 2017
Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/5695 )
Change subject: Sqlite3: make busy_timeout configurable.
......................................................................
Sqlite3: make busy_timeout configurable.
Enables runtime configuration of busy_timeout for sqlite databases.
Default timeout remains 1000ms.
ASTERISK-27014 #close
Change-Id: I8921a3aac3c335843be4cb17d2dd0a5c157a36da
---
M cdr/cdr_sqlite3_custom.c
M cel/cel_sqlite3_custom.c
M configs/samples/cdr_sqlite3_custom.conf.sample
M configs/samples/cel_sqlite3_custom.conf.sample
M configs/samples/res_config_sqlite3.conf.sample
M res/res_config_sqlite3.c
6 files changed, 41 insertions(+), 4 deletions(-)
Approvals:
George Joseph: Looks good to me, approved
Jenkins2: Approved for Submit
Sean Bright: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, but someone else must approve
diff --git a/cdr/cdr_sqlite3_custom.c b/cdr/cdr_sqlite3_custom.c
index e8d763e..2212d04 100644
--- a/cdr/cdr_sqlite3_custom.c
+++ b/cdr/cdr_sqlite3_custom.c
@@ -61,6 +61,7 @@
static char table[80];
static char *columns;
+static int busy_timeout;
struct values {
AST_LIST_ENTRY(values) list;
@@ -179,6 +180,15 @@
} else {
ast_log(LOG_WARNING, "Table name not specified. Assuming cdr.\n");
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 */
@@ -305,7 +315,7 @@
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);
diff --git a/cel/cel_sqlite3_custom.c b/cel/cel_sqlite3_custom.c
index 6075b8a..5675da6 100644
--- a/cel/cel_sqlite3_custom.c
+++ b/cel/cel_sqlite3_custom.c
@@ -68,6 +68,7 @@
* \bug Handling of this var is crash prone on reloads
*/
static char *columns;
+static int busy_timeout;
struct values {
char *expression;
@@ -185,6 +186,15 @@
} else {
ast_log(LOG_WARNING, "Table name not specified. Assuming cel.\n");
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 */
@@ -306,7 +316,7 @@
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);
diff --git a/configs/samples/cdr_sqlite3_custom.conf.sample b/configs/samples/cdr_sqlite3_custom.conf.sample
index 0d5dc09..4b88d58 100644
--- a/configs/samples/cdr_sqlite3_custom.conf.sample
+++ b/configs/samples/cdr_sqlite3_custom.conf.sample
@@ -5,6 +5,7 @@
;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)}'
diff --git a/configs/samples/cel_sqlite3_custom.conf.sample b/configs/samples/cel_sqlite3_custom.conf.sample
index 2d9a24f..aa908a4 100644
--- a/configs/samples/cel_sqlite3_custom.conf.sample
+++ b/configs/samples/cel_sqlite3_custom.conf.sample
@@ -22,3 +22,4 @@
;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
diff --git a/configs/samples/res_config_sqlite3.conf.sample b/configs/samples/res_config_sqlite3.conf.sample
index 5416c80..2588b26 100644
--- a/configs/samples/res_config_sqlite3.conf.sample
+++ b/configs/samples/res_config_sqlite3.conf.sample
@@ -28,4 +28,8 @@
; 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
diff --git a/res/res_config_sqlite3.c b/res/res_config_sqlite3.c
index 0025548..bbf6db2 100644
--- a/res/res_config_sqlite3.c
+++ b/res/res_config_sqlite3.c
@@ -103,6 +103,7 @@
unsigned int exiting:1;
unsigned int wakeup:1;
unsigned int batch;
+ int busy_timeout;
};
struct ao2_container *databases;
@@ -342,7 +343,7 @@
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);
@@ -400,6 +401,7 @@
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")) {
@@ -410,6 +412,10 @@
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);
+ }
}
}
@@ -454,6 +460,11 @@
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;
--
To view, visit https://gerrit.asterisk.org/5695
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8921a3aac3c335843be4cb17d2dd0a5c157a36da
Gerrit-PatchSet: 4
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Martin Tomec <tomec.martin at gmail.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Martin Tomec <tomec.martin at gmail.com>
Gerrit-Reviewer: Sean Bright <sean.bright at gmail.com>
More information about the asterisk-commits
mailing list