[Asterisk-code-review] Sqlite3: make busy timeout configurable. (asterisk[master])

Martin Tomec asteriskteam at digium.com
Tue May 23 11:24:16 CDT 2017


Martin Tomec has uploaded a new change for review. ( 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, 32 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/95/5695/1

diff --git a/cdr/cdr_sqlite3_custom.c b/cdr/cdr_sqlite3_custom.c
index e8d763e..c320a8b 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,13 @@
 	} 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) {
+		busy_timeout = atoi(tmp);
+	} else {
+		busy_timeout = 1000;
 	}
 
 	/* Columns */
@@ -305,7 +313,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..4ebb6dd 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,13 @@
 	} 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) {
+		busy_timeout = atoi(tmp);
+	} else {
+		busy_timeout = 1000;
 	}
 
 	/* Columns */
@@ -306,7 +314,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..fca3d54 100644
--- a/configs/samples/res_config_sqlite3.conf.sample
+++ b/configs/samples/res_config_sqlite3.conf.sample
@@ -29,3 +29,5 @@
 ;
 ;batch=1000
 
+; busy timeout - timeout in miliseconds to stop waiting for locked database
+;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..2107e9d 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,8 @@
 			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")) {
+			db->busy_timeout = atoi(var->value);
 		}
 	}
 
@@ -454,6 +458,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: newchange
Gerrit-Change-Id: I8921a3aac3c335843be4cb17d2dd0a5c157a36da
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Martin Tomec <tomec.martin at gmail.com>



More information about the asterisk-code-review mailing list