summaryrefslogtreecommitdiff
path: root/res/res_config_sqlite3.c
diff options
context:
space:
mode:
authorMartin Tomec <tomec.martin@gmail.com>2017-05-23 18:07:53 +0200
committerMartin Tomec <tomec.martin@gmail.com>2017-05-25 10:02:42 +0200
commit44c5a144ce3194fb9cec02f42436d93853b33a86 (patch)
treefbcf4a29a26400cf73785785d4479a71fbe2d31d /res/res_config_sqlite3.c
parentdece2eb8929c11bad30616d8f3a236ed449c718c (diff)
Sqlite3: make busy_timeout configurable.
Enables runtime configuration of busy_timeout for sqlite databases. Default timeout remains 1000ms. ASTERISK-27014 #close Change-Id: I8921a3aac3c335843be4cb17d2dd0a5c157a36da
Diffstat (limited to 'res/res_config_sqlite3.c')
-rw-r--r--res/res_config_sqlite3.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/res/res_config_sqlite3.c b/res/res_config_sqlite3.c
index 0025548be..bbf6db211 100644
--- a/res/res_config_sqlite3.c
+++ b/res/res_config_sqlite3.c
@@ -103,6 +103,7 @@ struct realtime_sqlite3_db {
unsigned int exiting:1;
unsigned int wakeup:1;
unsigned int batch;
+ int busy_timeout;
};
struct ao2_container *databases;
@@ -342,7 +343,7 @@ static int db_open(struct realtime_sqlite3_db *db)
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 @@ static struct realtime_sqlite3_db *new_realtime_sqlite3_db(struct ast_config *co
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 @@ static struct realtime_sqlite3_db *new_realtime_sqlite3_db(struct ast_config *co
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 @@ static int update_realtime_sqlite3_db(struct realtime_sqlite3_db *db, struct ast
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;