Browse code

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)

Daniel-Constantin Mierla authored on 24/03/2013 12:07:39
Showing 6 changed files
... ...
@@ -28,6 +28,7 @@ Daniel-Constantin Mierla
28 28
               3.1. ping_interval (integer)
29 29
               3.2. timeout_interval (integer)
30 30
               3.3. auto_reconnect (integer)
31
+              3.4. insert_delayed (integer)
31 32
 
32 33
         4. Functions
33 34
         5. Installation
... ...
@@ -38,9 +39,10 @@ Daniel-Constantin Mierla
38 39
    1.1. Set ping_interval parameter
39 40
    1.2. Set timeout_interval parameter
40 41
    1.3. Set auto_reconnect parameter
41
-   1.4. Set a my.cnf group in db_url parameter
42
-   1.5. Adding a kamailio group to my.cnf
43
-   1.6. Using [client] and specific group
42
+   1.4. Set insert_delayed parameter
43
+   1.5. Set a my.cnf group in db_url parameter
44
+   1.6. Adding a kamailio group to my.cnf
45
+   1.7. Using [client] and specific group
44 46
 
45 47
 Chapter 1. Admin Guide
46 48
 
... ...
@@ -57,6 +59,7 @@ Chapter 1. Admin Guide
57 59
         3.1. ping_interval (integer)
58 60
         3.2. timeout_interval (integer)
59 61
         3.3. auto_reconnect (integer)
62
+        3.4. insert_delayed (integer)
60 63
 
61 64
    4. Functions
62 65
    5. Installation
... ...
@@ -89,6 +92,7 @@ Chapter 1. Admin Guide
89 92
    3.1. ping_interval (integer)
90 93
    3.2. timeout_interval (integer)
91 94
    3.3. auto_reconnect (integer)
95
+   3.4. insert_delayed (integer)
92 96
 
93 97
 3.1. ping_interval (integer)
94 98
 
... ...
@@ -132,6 +136,18 @@ modparam("db_mysql", "timeout_interval", 2)
132 136
 modparam("db_mysql", "auto_reconnect", 0)
133 137
 ...
134 138
 
139
+3.4. insert_delayed (integer)
140
+
141
+   If set to 1, all INSERT SQL queries will be sent to MySQL server as
142
+   INSERT DELAYED.
143
+
144
+   Default value is 0 (1 - on / 0 - off).
145
+
146
+   Example 1.4. Set insert_delayed parameter
147
+...
148
+modparam("db_mysql", "insert_delayed", 1)
149
+...
150
+
135 151
 4. Functions
136 152
 
137 153
    No function exported to be used from configuration file.
... ...
@@ -158,12 +174,12 @@ modparam("db_mysql", "auto_reconnect", 0)
158 174
      * mysql://user:pass@[group]/db
159 175
      * mysql://[group]/db
160 176
 
161
-   Example 1.4. Set a my.cnf group in db_url parameter
177
+   Example 1.5. Set a my.cnf group in db_url parameter
162 178
 ...
163 179
 modparam("usrloc", "db_url", "mysql://[kamailio]/kamailio)
164 180
 ...
165 181
 
166
-   Example 1.5. Adding a kamailio group to my.cnf
182
+   Example 1.6. Adding a kamailio group to my.cnf
167 183
 ...
168 184
 [kamailio]
169 185
 socket = /path/to/mysql.sock
... ...
@@ -177,7 +193,7 @@ default-character-set = utf8
177 193
    both your specific group and the client group, then the value is taken
178 194
    from the last one.
179 195
 
180
-   Example 1.6. Using [client] and specific group
196
+   Example 1.7. Using [client] and specific group
181 197
 ...
182 198
 [client]
183 199
 socket = /var/run/mysql/mysqld.sock
... ...
@@ -118,6 +118,26 @@ modparam("db_mysql", "timeout_interval", 2)
118 118
 ...
119 119
 modparam("db_mysql", "auto_reconnect", 0)
120 120
 ...
121
+</programlisting>
122
+		</example>
123
+	</section>
124
+	<section id="db_mysql.p.insert_delayed">
125
+		<title><varname>insert_delayed</varname> (integer)</title>
126
+		<para>
127
+		If set to 1, all INSERT SQL queries will be sent to MySQL server as
128
+		INSERT DELAYED.
129
+		</para>
130
+		<para>
131
+		<emphasis>
132
+			Default value is 0 (1 - on / 0 - off).
133
+		</emphasis>
134
+		</para>
135
+		<example>
136
+		<title>Set <varname>insert_delayed</varname> parameter</title>
137
+		<programlisting format="linespecific">
138
+...
139
+modparam("db_mysql", "insert_delayed", 1)
140
+...
121 141
 </programlisting>
122 142
 		</example>
123 143
 	</section>
... ...
@@ -50,6 +50,7 @@
50 50
 
51 51
 unsigned int db_mysql_timeout_interval = 2;   /* Default is 6 seconds */
52 52
 unsigned int db_mysql_auto_reconnect = 1;     /* Default is enabled   */
53
+unsigned int db_mysql_insert_all_delayed = 0; /* Default is off */
53 54
 
54 55
 /* MODULE_VERSION */
55 56
 
... ...
@@ -42,6 +42,7 @@
42 42
 
43 43
 extern unsigned int db_mysql_timeout_interval;
44 44
 extern unsigned int db_mysql_auto_reconnect;
45
+extern unsigned int db_mysql_insert_all_delayed;
45 46
 
46 47
 int db_mysql_bind_api(db_func_t *dbb);
47 48
 
... ...
@@ -404,10 +404,15 @@ int db_mysql_raw_query(const db1_con_t* _h, const str* _s, db1_res_t** _r)
404 404
  * \param _n number of key=value pairs
405 405
  * \return zero on success, negative value on failure
406 406
  */
407
-int db_mysql_insert(const db1_con_t* _h, const db_key_t* _k, const db_val_t* _v, const int _n)
407
+int db_mysql_insert(const db1_con_t* _h, const db_key_t* _k, const db_val_t* _v,
408
+		const int _n)
408 409
 {
409
-	return db_do_insert(_h, _k, _v, _n, db_mysql_val2str,
410
-	db_mysql_submit_query);
410
+	if(unlikely(db_mysql_insert_all_delayed==1))
411
+		return db_do_insert_delayed(_h, _k, _v, _n, db_mysql_val2str,
412
+				db_mysql_submit_query);
413
+	else
414
+		return db_do_insert(_h, _k, _v, _n, db_mysql_val2str,
415
+				db_mysql_submit_query);
411 416
 }
412 417
 
413 418
 
... ...
@@ -107,6 +107,7 @@ static param_export_t params[] = {
107 107
 
108 108
 	{"timeout_interval", INT_PARAM, &db_mysql_timeout_interval},
109 109
 	{"auto_reconnect",   INT_PARAM, &db_mysql_auto_reconnect},
110
+	{"insert_delayed",   INT_PARAM, &db_mysql_insert_all_delayed},
110 111
 	{0, 0, 0}
111 112
 };
112 113