Module: sip-router
Branch: master
Commit: 61c706ef813520ce0ac6767e6be7ef6e52bd6b3a
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=61c706e…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Sun Mar 24 13:07:39 2013 +0100
db_mysql: new module parameter - insert_delayed
- if set to 1, then all INSERT API queries will be converted in INSERT
DELAYED (only DB API insert, not for raw queries)
---
modules/db_mysql/README | 28 ++++++++++++++++++++++------
modules/db_mysql/doc/db_mysql_admin.xml | 20 ++++++++++++++++++++
modules/db_mysql/km_db_mysql.c | 1 +
modules/db_mysql/km_db_mysql.h | 1 +
modules/db_mysql/km_dbase.c | 11 ++++++++---
modules/db_mysql/mysql_mod.c | 1 +
6 files changed, 53 insertions(+), 9 deletions(-)
diff --git a/modules/db_mysql/README b/modules/db_mysql/README
index 13a578f..def06aa 100644
--- a/modules/db_mysql/README
+++ b/modules/db_mysql/README
@@ -28,6 +28,7 @@ Daniel-Constantin Mierla
3.1. ping_interval (integer)
3.2. timeout_interval (integer)
3.3. auto_reconnect (integer)
+ 3.4. insert_delayed (integer)
4. Functions
5. Installation
@@ -38,9 +39,10 @@ Daniel-Constantin Mierla
1.1. Set ping_interval parameter
1.2. Set timeout_interval parameter
1.3. Set auto_reconnect parameter
- 1.4. Set a my.cnf group in db_url parameter
- 1.5. Adding a kamailio group to my.cnf
- 1.6. Using [client] and specific group
+ 1.4. Set insert_delayed parameter
+ 1.5. Set a my.cnf group in db_url parameter
+ 1.6. Adding a kamailio group to my.cnf
+ 1.7. Using [client] and specific group
Chapter 1. Admin Guide
@@ -57,6 +59,7 @@ Chapter 1. Admin Guide
3.1. ping_interval (integer)
3.2. timeout_interval (integer)
3.3. auto_reconnect (integer)
+ 3.4. insert_delayed (integer)
4. Functions
5. Installation
@@ -89,6 +92,7 @@ Chapter 1. Admin Guide
3.1. ping_interval (integer)
3.2. timeout_interval (integer)
3.3. auto_reconnect (integer)
+ 3.4. insert_delayed (integer)
3.1. ping_interval (integer)
@@ -132,6 +136,18 @@ modparam("db_mysql", "timeout_interval", 2)
modparam("db_mysql", "auto_reconnect", 0)
...
+3.4. insert_delayed (integer)
+
+ If set to 1, all INSERT SQL queries will be sent to MySQL server as
+ INSERT DELAYED.
+
+ Default value is 0 (1 - on / 0 - off).
+
+ Example 1.4. Set insert_delayed parameter
+...
+modparam("db_mysql", "insert_delayed", 1)
+...
+
4. Functions
No function exported to be used from configuration file.
@@ -158,12 +174,12 @@ modparam("db_mysql", "auto_reconnect", 0)
* mysql://user:pass@[group]/db
* mysql://[group]/db
- Example 1.4. Set a my.cnf group in db_url parameter
+ Example 1.5. Set a my.cnf group in db_url parameter
...
modparam("usrloc", "db_url", "mysql://[kamailio]/kamailio)
...
- Example 1.5. Adding a kamailio group to my.cnf
+ Example 1.6. Adding a kamailio group to my.cnf
...
[kamailio]
socket = /path/to/mysql.sock
@@ -177,7 +193,7 @@ default-character-set = utf8
both your specific group and the client group, then the value is taken
from the last one.
- Example 1.6. Using [client] and specific group
+ Example 1.7. Using [client] and specific group
...
[client]
socket = /var/run/mysql/mysqld.sock
diff --git a/modules/db_mysql/doc/db_mysql_admin.xml
b/modules/db_mysql/doc/db_mysql_admin.xml
index 36ce140..738c464 100644
--- a/modules/db_mysql/doc/db_mysql_admin.xml
+++ b/modules/db_mysql/doc/db_mysql_admin.xml
@@ -121,6 +121,26 @@ modparam("db_mysql", "auto_reconnect", 0)
</programlisting>
</example>
</section>
+ <section id="db_mysql.p.insert_delayed">
+ <title><varname>insert_delayed</varname> (integer)</title>
+ <para>
+ If set to 1, all INSERT SQL queries will be sent to MySQL server as
+ INSERT DELAYED.
+ </para>
+ <para>
+ <emphasis>
+ Default value is 0 (1 - on / 0 - off).
+ </emphasis>
+ </para>
+ <example>
+ <title>Set <varname>insert_delayed</varname> parameter</title>
+ <programlisting format="linespecific">
+...
+modparam("db_mysql", "insert_delayed", 1)
+...
+</programlisting>
+ </example>
+ </section>
</section>
<section>
<title>Functions</title>
diff --git a/modules/db_mysql/km_db_mysql.c b/modules/db_mysql/km_db_mysql.c
index 462dc60..8a51f3d 100644
--- a/modules/db_mysql/km_db_mysql.c
+++ b/modules/db_mysql/km_db_mysql.c
@@ -50,6 +50,7 @@
unsigned int db_mysql_timeout_interval = 2; /* Default is 6 seconds */
unsigned int db_mysql_auto_reconnect = 1; /* Default is enabled */
+unsigned int db_mysql_insert_all_delayed = 0; /* Default is off */
/* MODULE_VERSION */
diff --git a/modules/db_mysql/km_db_mysql.h b/modules/db_mysql/km_db_mysql.h
index 9fd9747..09997f7 100644
--- a/modules/db_mysql/km_db_mysql.h
+++ b/modules/db_mysql/km_db_mysql.h
@@ -42,6 +42,7 @@
extern unsigned int db_mysql_timeout_interval;
extern unsigned int db_mysql_auto_reconnect;
+extern unsigned int db_mysql_insert_all_delayed;
int db_mysql_bind_api(db_func_t *dbb);
diff --git a/modules/db_mysql/km_dbase.c b/modules/db_mysql/km_dbase.c
index e1cce08..029a674 100644
--- a/modules/db_mysql/km_dbase.c
+++ b/modules/db_mysql/km_dbase.c
@@ -404,10 +404,15 @@ int db_mysql_raw_query(const db1_con_t* _h, const str* _s,
db1_res_t** _r)
* \param _n number of key=value pairs
* \return zero on success, negative value on failure
*/
-int db_mysql_insert(const db1_con_t* _h, const db_key_t* _k, const db_val_t* _v, const
int _n)
+int db_mysql_insert(const db1_con_t* _h, const db_key_t* _k, const db_val_t* _v,
+ const int _n)
{
- return db_do_insert(_h, _k, _v, _n, db_mysql_val2str,
- db_mysql_submit_query);
+ if(unlikely(db_mysql_insert_all_delayed==1))
+ return db_do_insert_delayed(_h, _k, _v, _n, db_mysql_val2str,
+ db_mysql_submit_query);
+ else
+ return db_do_insert(_h, _k, _v, _n, db_mysql_val2str,
+ db_mysql_submit_query);
}
diff --git a/modules/db_mysql/mysql_mod.c b/modules/db_mysql/mysql_mod.c
index 74c61af..328965d 100644
--- a/modules/db_mysql/mysql_mod.c
+++ b/modules/db_mysql/mysql_mod.c
@@ -107,6 +107,7 @@ static param_export_t params[] = {
{"timeout_interval", INT_PARAM, &db_mysql_timeout_interval},
{"auto_reconnect", INT_PARAM, &db_mysql_auto_reconnect},
+ {"insert_delayed", INT_PARAM, &db_mysql_insert_all_delayed},
{0, 0, 0}
};