| 1 |
p_usrloc - Distributed databases |
| 2 |
|
| 3 |
Henning Westerholt |
| 4 |
|
| 5 |
1&1 Internet AG |
| 6 |
|
| 7 |
Edited by |
| 8 |
|
| 9 |
Patric Marschall |
| 10 |
|
| 11 |
1&1 Internet AG |
| 12 |
|
| 13 |
Copyright © 2007 1&1 Internet AG |
| 14 |
__________________________________________________________________ |
| 15 |
|
| 16 |
Table of Contents |
| 17 |
|
| 18 |
1. User's Guide |
| 19 |
|
| 20 |
1. Overview |
| 21 |
2. Dependencies |
| 22 |
|
| 23 |
2.1. Kamailio Modules |
| 24 |
2.2. External Libraries or Applications |
| 25 |
|
| 26 |
3. Parameters |
| 27 |
|
| 28 |
3.1. write_db_url (string) |
| 29 |
3.2. read_db_url (string) |
| 30 |
3.3. reg_db_table (string) |
| 31 |
3.4. id_column (string) |
| 32 |
3.5. num_column (string) |
| 33 |
3.6. url_column (string) |
| 34 |
3.7. status_column (string) |
| 35 |
3.8. failover_time_column (string) |
| 36 |
3.9. spare_flag_column (string) |
| 37 |
3.10. error_column (string) |
| 38 |
3.11. risk_group_column (string) |
| 39 |
3.12. expire_time (int) |
| 40 |
3.13. db_err_threshold (int) |
| 41 |
3.14. failover_level (int) |
| 42 |
3.15. db_retry_interval (int) |
| 43 |
3.16. db_use_transactions (int) |
| 44 |
3.17. db_transaction_level (string) |
| 45 |
3.18. write_on_master_db (int) |
| 46 |
3.19. mdb_availability_control(str) |
| 47 |
3.20. write_on_db (int) |
| 48 |
3.21. connection_expires (int) |
| 49 |
3.22. alg_location (int) |
| 50 |
3.23. domain_db(str) |
| 51 |
3.24. default_db_type(str) |
| 52 |
3.25. db_ops_ruid (int) |
| 53 |
3.26. db_update_as_insert (string) |
| 54 |
3.27. default_db_url(str) |
| 55 |
3.28. matching_mode(int) |
| 56 |
3.29. UTC_timestamps(int) |
| 57 |
3.30. use_domain_crc32(str) |
| 58 |
|
| 59 |
4. Changes from usrloc module |
| 60 |
|
| 61 |
4.1. db_mode (integer) |
| 62 |
4.2. db_url |
| 63 |
|
| 64 |
5. Installation & Running |
| 65 |
|
| 66 |
5.1. Database setup |
| 67 |
|
| 68 |
5.1.1. Configuration Table |
| 69 |
|
| 70 |
5.2. Maintenance |
| 71 |
5.3. Additional configuration |
| 72 |
|
| 73 |
2. Developer's Guide |
| 74 |
|
| 75 |
1. load_ul_db_api(ul_db_api_t * api) |
| 76 |
2. int (* ul_db_insert_t) (str * table, str * first, str * second, |
| 77 |
db_key_t* _k, db_val_t* _v, int _n) |
| 78 |
|
| 79 |
3. int (* ul_db_update_t) (str * table, str * first, str * second, |
| 80 |
db_key_t* _k, db_op_t * _op, db_val_t* _v, db_key_t* _uk, |
| 81 |
db_val_t* _uv, int _n, int _un); |
| 82 |
|
| 83 |
4. int (* ul_db_insert_update_t) (str * table, str * first, str * |
| 84 |
second, db_key_t* _k, db_val_t* _v, int _n) |
| 85 |
|
| 86 |
5. int (* ul_db_replace_t) (str * table, str * first, str * |
| 87 |
second, db_key_t* _k, db_val_t* _v, int _n) |
| 88 |
|
| 89 |
6. int (* ul_db_delete_t) (str * table, str * first, str * second, |
| 90 |
db_key_t* _k, db_op_t* _o, db_val_t* _v, int _n) |
| 91 |
|
| 92 |
7. int (* ul_db_query_t) (str * table, str * first, str * second, |
| 93 |
db_con_t *** _r_h, db_key_t* _k, db_op_t* _op, db_val_t* |
| 94 |
_v, db_key_t* _c, int _n, int _nc, db_key_t _o, db_res_t** |
| 95 |
_r); |
| 96 |
|
| 97 |
8. int (* ul_db_free_result_t)(db_con_t ** dbh, db_res_t * res); |
| 98 |
|
| 99 |
List of Examples |
| 100 |
|
| 101 |
1.1. Set write_db_url parameter |
| 102 |
1.2. Set read_db_url parameter |
| 103 |
1.3. Set reg_db_table parameter |
| 104 |
1.4. Set id_column parameter |
| 105 |
1.5. Set num_column parameter |
| 106 |
1.6. Set url_column parameter |
| 107 |
1.7. Set status_column parameter |
| 108 |
1.8. Set failover_time_column parameter |
| 109 |
1.9. Set spare_flag_column parameter |
| 110 |
1.10. Set error_column parameter |
| 111 |
1.11. Set risk_group_column parameter |
| 112 |
1.12. Set expire_time parameter |
| 113 |
1.13. Set db_err_threshold parameter |
| 114 |
1.14. Set failover_level parameter |
| 115 |
1.15. Set db_retry_interval parameter |
| 116 |
1.16. Set db_use_transactions parameter |
| 117 |
1.17. Set db_transaction_level parameter |
| 118 |
1.18. Set write_on_master_db parameter |
| 119 |
1.19. Set mdb_availability_control parameter |
| 120 |
1.20. Set write_on_db parameter |
| 121 |
1.21. Set connection_expires parameter |
| 122 |
1.22. Set alg_location parameter |
| 123 |
1.23. Set domain_db parameter |
| 124 |
1.24. Set default_db_type parameter |
| 125 |
1.25. Set db_ops_ruid parameter |
| 126 |
1.26. Set db_update_as_insert parameter |
| 127 |
1.27. Set default_db_type parameter |
| 128 |
1.28. Set matching_mode parameter |
| 129 |
1.29. Set UTC_timestamps parameter |
| 130 |
1.30. Set use_domain_crc32 parameter |
| 131 |
1.31. Set db_mode parameter |
| 132 |
1.32. Example database content - reg_table (locdb) table |
| 133 |
|
| 134 |
Chapter 1. User's Guide |
| 135 |
|
| 136 |
Table of Contents |
| 137 |
|
| 138 |
1. Overview |
| 139 |
2. Dependencies |
| 140 |
|
| 141 |
2.1. Kamailio Modules |
| 142 |
2.2. External Libraries or Applications |
| 143 |
|
| 144 |
3. Parameters |
| 145 |
|
| 146 |
3.1. write_db_url (string) |
| 147 |
3.2. read_db_url (string) |
| 148 |
3.3. reg_db_table (string) |
| 149 |
3.4. id_column (string) |
| 150 |
3.5. num_column (string) |
| 151 |
3.6. url_column (string) |
| 152 |
3.7. status_column (string) |
| 153 |
3.8. failover_time_column (string) |
| 154 |
3.9. spare_flag_column (string) |
| 155 |
3.10. error_column (string) |
| 156 |
3.11. risk_group_column (string) |
| 157 |
3.12. expire_time (int) |
| 158 |
3.13. db_err_threshold (int) |
| 159 |
3.14. failover_level (int) |
| 160 |
3.15. db_retry_interval (int) |
| 161 |
3.16. db_use_transactions (int) |
| 162 |
3.17. db_transaction_level (string) |
| 163 |
3.18. write_on_master_db (int) |
| 164 |
3.19. mdb_availability_control(str) |
| 165 |
3.20. write_on_db (int) |
| 166 |
3.21. connection_expires (int) |
| 167 |
3.22. alg_location (int) |
| 168 |
3.23. domain_db(str) |
| 169 |
3.24. default_db_type(str) |
| 170 |
3.25. db_ops_ruid (int) |
| 171 |
3.26. db_update_as_insert (string) |
| 172 |
3.27. default_db_url(str) |
| 173 |
3.28. matching_mode(int) |
| 174 |
3.29. UTC_timestamps(int) |
| 175 |
3.30. use_domain_crc32(str) |
| 176 |
|
| 177 |
4. Changes from usrloc module |
| 178 |
|
| 179 |
4.1. db_mode (integer) |
| 180 |
4.2. db_url |
| 181 |
|
| 182 |
5. Installation & Running |
| 183 |
|
| 184 |
5.1. Database setup |
| 185 |
|
| 186 |
5.1.1. Configuration Table |
| 187 |
|
| 188 |
5.2. Maintenance |
| 189 |
5.3. Additional configuration |
| 190 |
|
| 191 |
1. Overview |
| 192 |
|
| 193 |
The p_usrloc module is built upon the usrloc module and provides the |
| 194 |
same usrloc export to the registrar module (for example). The usrloc |
| 195 |
module must not be loaded at the same time with the p_usrloc module. |
| 196 |
The parameters and the interface for the p_usrloc module are thus |
| 197 |
almost the same, so in this document only extra parameters (specific |
| 198 |
only to p_usrloc module) and differences are noted. For a complete |
| 199 |
description of the parameters that are inherited from usrloc see the |
| 200 |
page here. Note that the modparam statement must still refer to the |
| 201 |
p_usrloc module. |
| 202 |
|
| 203 |
The goal of the p_usrloc module is to provide partitioned user location |
| 204 |
service to Kamailio/SER. This provides three major benefits: |
| 205 |
* Redundancy Failure of a location database does not mean that the |
| 206 |
location service is down |
| 207 |
* Load Balancing DB performance is greatly increased as queries are |
| 208 |
automatically split on a pool of ID(number configurable at |
| 209 |
runtime). Furthermore, a read only db handler can be used to |
| 210 |
further increase the spread of the "select" queries. |
| 211 |
* Failover A faulty DB server is detected and taken out. When it |
| 212 |
recovers, the module makes sure that no stale contacts are returned |
| 213 |
from it. |
| 214 |
|
| 215 |
Write queries are replicated to two or more databases, depending on |
| 216 |
some distribution keys, e.g. the username and domain the subscribers. |
| 217 |
The number of databases used for replication is configurable at compile |
| 218 |
time by modifying the DB_NUM define. Its main field of application is |
| 219 |
for storing and retrieving location data. The actual database for this |
| 220 |
subscriber is chosen from a set that is specified in the master |
| 221 |
database. Read queries are executed on one database of the set. If this |
| 222 |
database is not available, the other database would be used. This |
| 223 |
failure is recorded in the master database. |
| 224 |
|
| 225 |
Connections to the distributed databases are set up prior the actual |
| 226 |
query is executed. The module maintains a cache of the database handles |
| 227 |
to provide better performance. This handles are periodically checked if |
| 228 |
there are still valid and if needed updated from the master database. |
| 229 |
As default only one key is used for the database lookup, but the |
| 230 |
additional usage of a second one is possible. |
| 231 |
|
| 232 |
Changes in the master database are autodetected. For better performance |
| 233 |
it is possible to use one read-only instance, that is locally |
| 234 |
installed, and write only errors and other status information to a |
| 235 |
central master database. It is also possible to specify different |
| 236 |
failover schemas and even use transaction to provide additional data |
| 237 |
safety. This module could further try to minimize the impact of a |
| 238 |
database error with the usage of spare databases that are automatically |
| 239 |
activated. It also supports the manual deactivation of redundant |
| 240 |
databases for maintenance purposes. |
| 241 |
|
| 242 |
Warning |
| 243 |
|
| 244 |
The p_usrloc module still has some missing feature, like automatic |
| 245 |
expiry of contacts and dumping of all users via the fifo cmd. |
| 246 |
|
| 247 |
2. Dependencies |
| 248 |
|
| 249 |
2.1. Kamailio Modules |
| 250 |
2.2. External Libraries or Applications |
| 251 |
|
| 252 |
2.1. Kamailio Modules |
| 253 |
|
| 254 |
The following modules must be loaded before this module: |
| 255 |
* a database module necessary to connect to the master database and |
| 256 |
to the distributed databases. |
| 257 |
|
| 258 |
2.2. External Libraries or Applications |
| 259 |
|
| 260 |
The following libraries or applications must be installed before |
| 261 |
running Kamailio with this module loaded: |
| 262 |
* None. |
| 263 |
|
| 264 |
3. Parameters |
| 265 |
|
| 266 |
3.1. write_db_url (string) |
| 267 |
3.2. read_db_url (string) |
| 268 |
3.3. reg_db_table (string) |
| 269 |
3.4. id_column (string) |
| 270 |
3.5. num_column (string) |
| 271 |
3.6. url_column (string) |
| 272 |
3.7. status_column (string) |
| 273 |
3.8. failover_time_column (string) |
| 274 |
3.9. spare_flag_column (string) |
| 275 |
3.10. error_column (string) |
| 276 |
3.11. risk_group_column (string) |
| 277 |
3.12. expire_time (int) |
| 278 |
3.13. db_err_threshold (int) |
| 279 |
3.14. failover_level (int) |
| 280 |
3.15. db_retry_interval (int) |
| 281 |
3.16. db_use_transactions (int) |
| 282 |
3.17. db_transaction_level (string) |
| 283 |
3.18. write_on_master_db (int) |
| 284 |
3.19. mdb_availability_control(str) |
| 285 |
3.20. write_on_db (int) |
| 286 |
3.21. connection_expires (int) |
| 287 |
3.22. alg_location (int) |
| 288 |
3.23. domain_db(str) |
| 289 |
3.24. default_db_type(str) |
| 290 |
3.25. db_ops_ruid (int) |
| 291 |
3.26. db_update_as_insert (string) |
| 292 |
3.27. default_db_url(str) |
| 293 |
3.28. matching_mode(int) |
| 294 |
3.29. UTC_timestamps(int) |
| 295 |
3.30. use_domain_crc32(str) |
| 296 |
|
| 297 |
3.1. write_db_url (string) |
| 298 |
|
| 299 |
The url to the master database where errors are written to. |
| 300 |
|
| 301 |
Default value is “mysql://kamailio:kamailiorw@localhost/kamailio” |
| 302 |
|
| 303 |
Example 1.1. Set write_db_url parameter |
| 304 |
... |
| 305 |
modparam("p_usrloc", "write_db_url", "mysql://username:password@localhost/databa |
| 306 |
sename") |
| 307 |
... |
| 308 |
|
| 309 |
3.2. read_db_url (string) |
| 310 |
|
| 311 |
The url to the master database where the distribution data is read |
| 312 |
from. It is separated from write access, so for better performance, a |
| 313 |
local replicate can be used for read access. |
| 314 |
|
| 315 |
Default value is mysql://kamailio:kamailiorw@localhost/kamailio . |
| 316 |
|
| 317 |
Example 1.2. Set read_db_url parameter |
| 318 |
... |
| 319 |
modparam("p_usrloc", "read_db_url", "mysql://user:passwd@localhost/db") |
| 320 |
... |
| 321 |
|
| 322 |
3.3. reg_db_table (string) |
| 323 |
|
| 324 |
Specifies the table where the information about the distributed |
| 325 |
databases is stored. |
| 326 |
|
| 327 |
Default value is “locdb”. |
| 328 |
|
| 329 |
Example 1.3. Set reg_db_table parameter |
| 330 |
... |
| 331 |
modparam("p_usrloc", "reg_db_table", "locdb") |
| 332 |
... |
| 333 |
|
| 334 |
3.4. id_column (string) |
| 335 |
|
| 336 |
Specifies the column where the id of a distributed database is stored. |
| 337 |
|
| 338 |
Default value is “id”. |
| 339 |
|
| 340 |
Example 1.4. Set id_column parameter |
| 341 |
... |
| 342 |
modparam("p_usrloc", "id_column", "id") |
| 343 |
... |
| 344 |
|
| 345 |
3.5. num_column (string) |
| 346 |
|
| 347 |
Specifies the column where the associated number of the distributed |
| 348 |
database is stored. For each distributed database ID there must be at |
| 349 |
least two databases available, the databases above the second are |
| 350 |
ignored. |
| 351 |
|
| 352 |
Default value is “no”. |
| 353 |
|
| 354 |
Example 1.5. Set num_column parameter |
| 355 |
... |
| 356 |
modparam("p_usrloc", "num_column", "nr") |
| 357 |
... |
| 358 |
|
| 359 |
3.6. url_column (string) |
| 360 |
|
| 361 |
Specifies the column where the url of the distributed database is |
| 362 |
stored. |
| 363 |
|
| 364 |
Default value is “url”. |
| 365 |
|
| 366 |
Example 1.6. Set url_column parameter |
| 367 |
... |
| 368 |
modparam("p_usrloc", "url_column", "url") |
| 369 |
... |
| 370 |
|
| 371 |
3.7. status_column (string) |
| 372 |
|
| 373 |
Specifies the column where the status of the distributed database is |
| 374 |
stored. |
| 375 |
|
| 376 |
Default value is “status”. |
| 377 |
|
| 378 |
Example 1.7. Set status_column parameter |
| 379 |
... |
| 380 |
modparam("p_usrloc", "status_column", "status") |
| 381 |
... |
| 382 |
|
| 383 |
3.8. failover_time_column (string) |
| 384 |
|
| 385 |
Specifies the column where the failover time of the location databases |
| 386 |
is stored. This field is set to the current time when a databases is |
| 387 |
turned off or turned on. |
| 388 |
|
| 389 |
Default value is “failover”. |
| 390 |
|
| 391 |
Example 1.8. Set failover_time_column parameter |
| 392 |
... |
| 393 |
modparam("p_usrloc", "failover_time_column", "fail") |
| 394 |
... |
| 395 |
|
| 396 |
3.9. spare_flag_column (string) |
| 397 |
|
| 398 |
Specifies the column where the spare flag of the location databases is |
| 399 |
stored. It is possible to declare an entry in the p_usrloc table as |
| 400 |
spare which is used in a failover. Due to the fact that the data is |
| 401 |
stored in two databases and it takes the spare the complete expire time |
| 402 |
to be up to date, it is not very useful. |
| 403 |
|
| 404 |
Default value is “spare”. |
| 405 |
|
| 406 |
Example 1.9. Set spare_flag_column parameter |
| 407 |
... |
| 408 |
modparam("p_usrloc", "spare_flag_column", "spare") |
| 409 |
... |
| 410 |
|
| 411 |
3.10. error_column (string) |
| 412 |
|
| 413 |
Specifies the column where the errors of the distributed databases are |
| 414 |
stored. Each call to db_handle_error increases the error counter. After |
| 415 |
exceeding the error threshold, the database's status is set to off. |
| 416 |
|
| 417 |
Default value is “errors”. |
| 418 |
|
| 419 |
Example 1.10. Set error_column parameter |
| 420 |
... |
| 421 |
modparam("p_usrloc", "error_column", "error") |
| 422 |
... |
| 423 |
|
| 424 |
3.11. risk_group_column (string) |
| 425 |
|
| 426 |
Specifies the column where the risk group of the distributed databases |
| 427 |
is stored. All databases on one host are in the same risk group. This |
| 428 |
is only useful when using spares and prevents the module from taking a |
| 429 |
spare which shares the same risk as the broken database. |
| 430 |
|
| 431 |
Default value is “rg”. |
| 432 |
|
| 433 |
Example 1.11. Set risk_group_column parameter |
| 434 |
... |
| 435 |
modparam("p_usrloc", "risk_group_column", "rg") |
| 436 |
... |
| 437 |
|
| 438 |
3.12. expire_time (int) |
| 439 |
|
| 440 |
Specifies the time (in seconds) when a contact expires, used for |
| 441 |
resetting the failover time of a reactivated database. It should be |
| 442 |
equal or greater than the contact expiration time of the registrar |
| 443 |
module. |
| 444 |
|
| 445 |
Default value is “3600”. |
| 446 |
|
| 447 |
Can be set at runtime, e.g.: |
| 448 |
$ kamcmd cfg.set_now_int p_usrloc expire_time 7200 |
| 449 |
|
| 450 |
Example 1.12. Set expire_time parameter |
| 451 |
... |
| 452 |
modparam("p_usrloc", "expire_time", "3600") |
| 453 |
... |
| 454 |
|
| 455 |
3.13. db_err_threshold (int) |
| 456 |
|
| 457 |
Specifies the error value on which a database shall be turned of. |
| 458 |
|
| 459 |
Default value is “50”. |
| 460 |
|
| 461 |
Can be set at runtime, e.g.: |
| 462 |
$ kamcmd cfg.set_now_int p_usrloc db_err_threshold 20 |
| 463 |
|
| 464 |
Example 1.13. Set db_err_threshold parameter |
| 465 |
... |
| 466 |
modparam("p_usrloc", "db_err_threshold", "50") |
| 467 |
... |
| 468 |
|
| 469 |
3.14. failover_level (int) |
| 470 |
|
| 471 |
Specifies the manner a failover is done. Following modes are supported: |
| 472 |
* 1 - Just turn off the broken database |
| 473 |
* 2 - Try to find a spare, if none found, just turn off the broken |
| 474 |
database |
| 475 |
|
| 476 |
Default value is “1”. |
| 477 |
|
| 478 |
Can be set at runtime, e.g.: |
| 479 |
$ kamcmd cfg.set_now_int p_usrloc failover_level 2 |
| 480 |
|
| 481 |
Example 1.14. Set failover_level parameter |
| 482 |
... |
| 483 |
modparam("p_usrloc", "failover_level", "1") |
| 484 |
... |
| 485 |
|
| 486 |
3.15. db_retry_interval (int) |
| 487 |
|
| 488 |
Specifies the interval (in seconds) in which a timer process shall |
| 489 |
check the availability of the databases and try to reconnect to broken |
| 490 |
ones. It doesn't make sense to choose a lower value as 10. It's |
| 491 |
necessary to provide a writeable master database, otherwise this check |
| 492 |
stays disabled. |
| 493 |
|
| 494 |
Default value is “10”. |
| 495 |
|
| 496 |
Example 1.15. Set db_retry_interval parameter |
| 497 |
... |
| 498 |
modparam("p_usrloc", "db_retry_interval", "10") |
| 499 |
... |
| 500 |
|
| 501 |
3.16. db_use_transactions (int) |
| 502 |
|
| 503 |
Specifies if transactions should be used (set to 1) to reach a higher |
| 504 |
data consistency. Keep in mind that this will probably decrease |
| 505 |
performance. |
| 506 |
|
| 507 |
Default value is “0”. |
| 508 |
|
| 509 |
Example 1.16. Set db_use_transactions parameter |
| 510 |
... |
| 511 |
modparam("p_usrloc", "db_use_transactions", "0") |
| 512 |
... |
| 513 |
|
| 514 |
3.17. db_transaction_level (string) |
| 515 |
|
| 516 |
Specifies the isolation level on which transactions are performed. |
| 517 |
Possible values: Modes supported by the database backend. In order to |
| 518 |
activate transaction the db_use_transactions parameter must be also |
| 519 |
set. |
| 520 |
|
| 521 |
Default value is “READ UNCOMMITTED”. |
| 522 |
|
| 523 |
Example 1.17. Set db_transaction_level parameter |
| 524 |
... |
| 525 |
modparam("p_usrloc", "db_transaction_level", "READ UNCOMMITTED") |
| 526 |
... |
| 527 |
|
| 528 |
3.18. write_on_master_db (int) |
| 529 |
|
| 530 |
Sets the write access to the master database. If set to 0, no write |
| 531 |
operations are permitted on the master database. |
| 532 |
|
| 533 |
Default value is “0”. |
| 534 |
|
| 535 |
Example 1.18. Set write_on_master_db parameter |
| 536 |
... |
| 537 |
modparam("p_usrloc", "write_on_master_db", "0") |
| 538 |
... |
| 539 |
|
| 540 |
3.19. mdb_availability_control(str) |
| 541 |
|
| 542 |
Checks the master database in certain time intervals specified by the |
| 543 |
“retry_interval” parameter. Overwrites the “write_on_master_db” |
| 544 |
parameter based on the reachability of master database. If the master |
| 545 |
db is unavailable then the aforementioned parameter will be |
| 546 |
deactivated. |
| 547 |
|
| 548 |
Default value is “0”. |
| 549 |
|
| 550 |
Example 1.19. Set mdb_availability_control parameter |
| 551 |
... |
| 552 |
modparam("p_usrloc", "mdb_availability_control", 1) |
| 553 |
... |
| 554 |
|
| 555 |
3.20. write_on_db (int) |
| 556 |
|
| 557 |
Sets the write access to the distributed databases. If set to 0, no |
| 558 |
write operations are permitted on the databases. |
| 559 |
|
| 560 |
Default value is “0”. |
| 561 |
|
| 562 |
Example 1.20. Set write_on_db parameter |
| 563 |
... |
| 564 |
modparam("p_usrloc", "write_on_db", "0") |
| 565 |
... |
| 566 |
|
| 567 |
3.21. connection_expires (int) |
| 568 |
|
| 569 |
Specifies the period (in seconds) after a database connection expires. |
| 570 |
Usage of a too small value will probably decrease the performance. |
| 571 |
|
| 572 |
Default value is “300”. |
| 573 |
|
| 574 |
Example 1.21. Set connection_expires parameter |
| 575 |
... |
| 576 |
modparam("p_usrloc", "connection_expires", "300") |
| 577 |
... |
| 578 |
|
| 579 |
3.22. alg_location (int) |
| 580 |
|
| 581 |
Specify the way the distribution of the subscriptions are computed. At |
| 582 |
the moment the only way is to use the CRC32 algorithm to compute the |
| 583 |
location ID. Any integer value is fine. |
| 584 |
|
| 585 |
Default value is “0”. |
| 586 |
|
| 587 |
Example 1.22. Set alg_location parameter |
| 588 |
... |
| 589 |
modparam("p_usrloc", "alg_location", 1) |
| 590 |
... |
| 591 |
|
| 592 |
3.23. domain_db(str) |
| 593 |
|
| 594 |
Specify the way the lookup is made. In can be either partitioned or |
| 595 |
single. For example, if you have a location table that is large and |
| 596 |
needs to be partitioned, and a smaller table cfa that is ok to be on |
| 597 |
only the master db(so there is no need to have it distributed), you can |
| 598 |
set this parameter to “location=cluster,cfa=single”. This means that a |
| 599 |
call to |
| 600 |
lookup(location) |
| 601 |
|
| 602 |
will be done via the partition databases configured via the |
| 603 |
reg_db_table parameter, but a call to |
| 604 |
lookup(cfa) |
| 605 |
|
| 606 |
will be done on only the master database (as with usrloc module) |
| 607 |
|
| 608 |
Default value is “location=cluster,cfa=single”. |
| 609 |
|
| 610 |
Example 1.23. Set domain_db parameter |
| 611 |
... |
| 612 |
modparam("p_usrloc", "domain_db", "location=cluster,cfa=single") |
| 613 |
... |
| 614 |
|
| 615 |
3.24. default_db_type(str) |
| 616 |
|
| 617 |
In case a domain (like location,cfa) is not matched by a domain_db |
| 618 |
definition, the type is configured by using this parameter. Accepted |
| 619 |
values are single and cluster. |
| 620 |
|
| 621 |
Default value is “single”. |
| 622 |
|
| 623 |
Example 1.24. Set default_db_type parameter |
| 624 |
... |
| 625 |
modparam("p_usrloc", "default_db_type", "cluster") |
| 626 |
... |
| 627 |
|
| 628 |
3.25. db_ops_ruid (int) |
| 629 |
|
| 630 |
Defines how database queries are done: |
| 631 |
* 0 uses the old style using aor, contact and call-id |
| 632 |
* 1 uses ruid value |
| 633 |
* 2 uses the new style using aor, contact and call-id |
| 634 |
* 3 uses contact uniq value + ruid value |
| 635 |
|
| 636 |
Default value is 0 |
| 637 |
|
| 638 |
Can be set at runtime, e.g.: |
| 639 |
$ kamcmd cfg.set_now_int p_usrloc db_ops_ruid 1 |
| 640 |
|
| 641 |
Example 1.25. Set db_ops_ruid parameter |
| 642 |
... |
| 643 |
modparam("p_usrloc", "db_ops_ruid", 2) |
| 644 |
... |
| 645 |
|
| 646 |
3.26. db_update_as_insert (string) |
| 647 |
|
| 648 |
Set this parameter if you want to do INSERT DB operations instead of |
| 649 |
UPDATE DB operations. It is recommended to set this parameter if you |
| 650 |
use Cassandra as a DB backend. |
| 651 |
|
| 652 |
Default value is “1”. |
| 653 |
|
| 654 |
Can be set at runtime, e.g.: |
| 655 |
$ kamcmd cfg.set_now_int p_usrloc db_update_as_insert 1 |
| 656 |
|
| 657 |
Example 1.26. Set db_update_as_insert parameter |
| 658 |
... |
| 659 |
modparam("usrloc", "db_update_as_insert", 1) |
| 660 |
... |
| 661 |
|
| 662 |
3.27. default_db_url(str) |
| 663 |
|
| 664 |
The URL of the default database for Location domains (for domains that |
| 665 |
are single). This must be configured if they are use. |
| 666 |
|
| 667 |
Default value is “DEFAULT_DB_URL”. |
| 668 |
|
| 669 |
Example 1.27. Set default_db_type parameter |
| 670 |
... |
| 671 |
modparam("p_usrloc", "default_db_url", "mysql://ser:ser@localhost/ser") |
| 672 |
... |
| 673 |
|
| 674 |
3.28. matching_mode(int) |
| 675 |
|
| 676 |
Defines the matching algorithm. Possible values are: |
| 677 |
* 0 (CONTACT_ONLY) |
| 678 |
* 1 (CONTACT_CALLID) |
| 679 |
* 2 (CONTACT_PATH) |
| 680 |
|
| 681 |
Default value is “0” (CONTACT_ONLY). |
| 682 |
|
| 683 |
Example 1.28. Set matching_mode parameter |
| 684 |
... |
| 685 |
modparam("p_usrloc", "matching_mode", 1) |
| 686 |
modparam("p_usrloc", "matching_mode", 2) |
| 687 |
... |
| 688 |
|
| 689 |
kamctl rpc cfg.set_now_int p_usrloc matching_mode 2 |
| 690 |
kamctl rpc cfg.get p_usrloc matching_mode |
| 691 |
|
| 692 |
3.29. UTC_timestamps(int) |
| 693 |
|
| 694 |
Enables UTC timestamps for expires and last_modified columns. It can be |
| 695 |
changed at runtime via rpc command. |
| 696 |
|
| 697 |
Default value is 0 (disabled). |
| 698 |
|
| 699 |
Example 1.29. Set UTC_timestamps parameter |
| 700 |
... |
| 701 |
modparam("p_usrloc", "UTC_timestamps", 1) |
| 702 |
... |
| 703 |
|
| 704 |
3.30. use_domain_crc32(str) |
| 705 |
|
| 706 |
Enables or disables the crc32 of domain part for user@domain. If |
| 707 |
disabled, will calculate crc32 only for user part. |
| 708 |
|
| 709 |
Default value is “1” (enabled). |
| 710 |
|
| 711 |
Example 1.30. Set use_domain_crc32 parameter |
| 712 |
... |
| 713 |
modparam("p_usrloc", "use_domain_crc32", "0") |
| 714 |
... |
| 715 |
|
| 716 |
4. Changes from usrloc module |
| 717 |
|
| 718 |
4.1. db_mode (integer) |
| 719 |
4.2. db_url |
| 720 |
|
| 721 |
4.1. db_mode (integer) |
| 722 |
|
| 723 |
The p_usrloc module must utilize database for persistent contact |
| 724 |
storage. Only mode 3 is possible at this time. Because of the way other |
| 725 |
matching mode work, they make no sense on a distributed environment. |
| 726 |
* 3 - DB-Only scheme. No memory cache is kept, all operations being |
| 727 |
directly performed with the database. The timer deletes all expired |
| 728 |
contacts from database - cleans after clients that didn't |
| 729 |
un-register or re-register. The mode is useful if you configure |
| 730 |
more servers sharing the same DB without any replication at SIP |
| 731 |
level. The mode may be slower due the high number of DB operation. |
| 732 |
For example NAT pinging is a killer since during each ping cycle |
| 733 |
all nated contact are loaded from the DB; The lack of memory |
| 734 |
caching also disable the statistics exports. |
| 735 |
|
| 736 |
Default value is 3. |
| 737 |
|
| 738 |
Example 1.31. Set db_mode parameter |
| 739 |
... |
| 740 |
modparam("p_usrloc", "db_mode", 2) |
| 741 |
... |
| 742 |
|
| 743 |
4.2. db_url |
| 744 |
|
| 745 |
This parameters is now obsolete, and replaced by specific p_usrloc |
| 746 |
parameters |
| 747 |
|
| 748 |
5. Installation & Running |
| 749 |
|
| 750 |
5.1. Database setup |
| 751 |
|
| 752 |
5.1.1. Configuration Table |
| 753 |
|
| 754 |
5.2. Maintenance |
| 755 |
5.3. Additional configuration |
| 756 |
|
| 757 |
5.1. Database setup |
| 758 |
|
| 759 |
5.1.1. Configuration Table |
| 760 |
|
| 761 |
Before running Kamailio with p_usrloc, you have to set up the master |
| 762 |
database table where the module will find data about the distributed |
| 763 |
databases. For that, if the table was not created by the installation |
| 764 |
script or you choose to install everything by yourself you can use the |
| 765 |
p_usrloc-create.sql SQL script in the database directories in the |
| 766 |
utils/kamctl/mysql/ folder as template. Database and table name can be |
| 767 |
set with module parameters so they can be changed, but the name of the |
| 768 |
columns must be as they are in the SQL script. You can also find the |
| 769 |
complete database documentation on the project webpage, |
| 770 |
https://www.kamailio.org/docs/db-tables/kamailio-db-devel.html. |
| 771 |
|
| 772 |
Example 1.32. Example database content - reg_table (locdb) table |
| 773 |
... |
| 774 |
+----+----+------+--------+--------+---------------------+-------+----+ |
| 775 |
| id | no | url | status | errors | failover | spare | rg | |
| 776 |
+----+----+------+--------+--------+---------------------+-------+----+ |
| 777 |
| 1 | 1 | URL1 | 1 | 0 | 1900-01-01 00:00:01 | 0 | 0 | |
| 778 |
| 1 | 2 | URL2 | 1 | 0 | 1900-01-01 00:00:01 | 0 | 0 | |
| 779 |
| 2 | 1 | URL3 | 1 | 0 | 1900-01-01 00:00:01 | 0 | 0 | |
| 780 |
| 2 | 2 | URL4 | 1 | 0 | 1900-01-01 00:00:01 | 0 | 0 | |
| 781 |
+----+----+------+--------+--------+---------------------+-------+----+ |
| 782 |
... |
| 783 |
|
| 784 |
The URLs are omitted for a better overview, but you can use standard |
| 785 |
Kamailio database URLs like |
| 786 |
mysql://kamailio:kamailiorw@localhost/kamailio Databases don't need to |
| 787 |
be on different hosts, e.g. for testing purposes. |
| 788 |
|
| 789 |
This table contains two database groups. The first with id one, and the |
| 790 |
second with the id two. |
| 791 |
|
| 792 |
5.2. Maintenance |
| 793 |
|
| 794 |
The module supports the deactivation of redundant databases for |
| 795 |
maintenance reasons. This can be done by setting the status column of |
| 796 |
the respective database in the p_usrloc to the value “2”. This setting |
| 797 |
is autodetected from all modules on the server cluster. Changes in the |
| 798 |
locdb table are periodically polled with help of a timer process. After |
| 799 |
one minute all the read and write traffic is removed from the |
| 800 |
deactivated database, and maintenance can be done. |
| 801 |
|
| 802 |
In order to activate the database again, after the maintenance has been |
| 803 |
finished, the respective status column needs to be set to “0”. This is |
| 804 |
autodetected as well, the first module that noticed the change will set |
| 805 |
the status column to “1” and setting the failover column to the current |
| 806 |
time and date. Write requests are now transferred again to the |
| 807 |
database, but no reads are done yet. |
| 808 |
|
| 809 |
After the configured expire_time has been passed, i.e. every contact |
| 810 |
has been inserted at least one time in the database the respective |
| 811 |
failover time column is set to the default value again. The database is |
| 812 |
then also used to read contacts from, the cluster is in normal |
| 813 |
operation with full redundancy again. |
| 814 |
|
| 815 |
5.3. Additional configuration |
| 816 |
|
| 817 |
As this module is only used internally from other modules, there is no |
| 818 |
additional configuration except for the module parameter setup |
| 819 |
necessary. |
| 820 |
|
| 821 |
Chapter 2. Developer's Guide |
| 822 |
|
| 823 |
Table of Contents |
| 824 |
|
| 825 |
1. load_ul_db_api(ul_db_api_t * api) |
| 826 |
2. int (* ul_db_insert_t) (str * table, str * first, str * second, |
| 827 |
db_key_t* _k, db_val_t* _v, int _n) |
| 828 |
|
| 829 |
3. int (* ul_db_update_t) (str * table, str * first, str * second, |
| 830 |
db_key_t* _k, db_op_t * _op, db_val_t* _v, db_key_t* _uk, |
| 831 |
db_val_t* _uv, int _n, int _un); |
| 832 |
|
| 833 |
4. int (* ul_db_insert_update_t) (str * table, str * first, str * |
| 834 |
second, db_key_t* _k, db_val_t* _v, int _n) |
| 835 |
|
| 836 |
5. int (* ul_db_replace_t) (str * table, str * first, str * second, |
| 837 |
db_key_t* _k, db_val_t* _v, int _n) |
| 838 |
|
| 839 |
6. int (* ul_db_delete_t) (str * table, str * first, str * second, |
| 840 |
db_key_t* _k, db_op_t* _o, db_val_t* _v, int _n) |
| 841 |
|
| 842 |
7. int (* ul_db_query_t) (str * table, str * first, str * second, |
| 843 |
db_con_t *** _r_h, db_key_t* _k, db_op_t* _op, db_val_t* _v, |
| 844 |
db_key_t* _c, int _n, int _nc, db_key_t _o, db_res_t** _r); |
| 845 |
|
| 846 |
8. int (* ul_db_free_result_t)(db_con_t ** dbh, db_res_t * res); |
| 847 |
|
| 848 |
These are the primary functions that are used to perform the SQL |
| 849 |
queries. |
| 850 |
|
| 851 |
1. load_ul_db_api(ul_db_api_t * api) |
| 852 |
|
| 853 |
Import the dbd API, set up the master database connection. |
| 854 |
|
| 855 |
Meaning of the parameters is as follows: |
| 856 |
* api - Pointer to distributed database API structure |
| 857 |
|
| 858 |
2. int (* ul_db_insert_t) (str * table, str * first, str * second, db_key_t* |
| 859 |
_k, db_val_t* _v, int _n) |
| 860 |
|
| 861 |
Lookup the first and if needed the second key, and insert the given |
| 862 |
values into the chosen databases. |
| 863 |
|
| 864 |
Meaning of the parameters is as follows: |
| 865 |
* table - Pointer to the table name. |
| 866 |
* first - Pointer to the first key. |
| 867 |
* second - Pointer to the second key. |
| 868 |
* _k - Pointer to the inserted db keys. |
| 869 |
* _v - Pointer to the inserted db values. |
| 870 |
* _n - Number of key-value pairs in _k and _v parameters. |
| 871 |
|
| 872 |
3. int (* ul_db_update_t) (str * table, str * first, str * second, db_key_t* |
| 873 |
_k, db_op_t * _op, db_val_t* _v, db_key_t* _uk, db_val_t* _uv, int _n, int |
| 874 |
_un); |
| 875 |
|
| 876 |
Lookup the first and if needed the second key, and update the given |
| 877 |
values in the chosen databases. |
| 878 |
|
| 879 |
Meaning of the parameters is as follows: |
| 880 |
* table - Pointer to the table name. |
| 881 |
* first - Pointer to the first key. |
| 882 |
* second - Pointer to the second key. |
| 883 |
* _k - Pointer to the db keys that will be matched. |
| 884 |
* _op - Pointer to the db options for this operation. |
| 885 |
* _v - Pointer to the db values that will be matched. |
| 886 |
* _uk - Pointer to the updated db keys. |
| 887 |
* _uv - Pointer to the updated db values. |
| 888 |
* _n - Number of key-value pairs in _k and _v parameters. |
| 889 |
* _un - Number of key-value pairs in _uk and _uv parameters. |
| 890 |
|
| 891 |
4. int (* ul_db_insert_update_t) (str * table, str * first, str * second, |
| 892 |
db_key_t* _k, db_val_t* _v, int _n) |
| 893 |
|
| 894 |
Lookup the first and if needed the second key, and insert on duplicate |
| 895 |
key update the given values in the chosen databases. This is like an |
| 896 |
insert, but update if the key already exist. |
| 897 |
|
| 898 |
Meaning of the parameters is as follows: |
| 899 |
* table - Pointer to the table name. |
| 900 |
* first - Pointer to the first key. |
| 901 |
* second - Pointer to the second key. |
| 902 |
* _k - Pointer to the inserted or updated db keys. |
| 903 |
* _v - Pointer to the inserted or updated db values. |
| 904 |
* _n - Number of key-value pairs in _k and _v parameters. |
| 905 |
|
| 906 |
5. int (* ul_db_replace_t) (str * table, str * first, str * second, |
| 907 |
db_key_t* _k, db_val_t* _v, int _n) |
| 908 |
|
| 909 |
Lookup the first and if needed the second key, and replace the given |
| 910 |
values in the chosen databases. |
| 911 |
|
| 912 |
Meaning of the parameters is as follows: |
| 913 |
* table - Pointer to the table name. |
| 914 |
* first - Pointer to the first key. |
| 915 |
* second - Pointer to the second key. |
| 916 |
* _k - Pointer to the replaced db keys. |
| 917 |
* _v - Pointer to the replaced db values. |
| 918 |
* _n - Number of key-value pairs in _k and _v parameters. |
| 919 |
|
| 920 |
6. int (* ul_db_delete_t) (str * table, str * first, str * second, db_key_t* |
| 921 |
_k, db_op_t* _o, db_val_t* _v, int _n) |
| 922 |
|
| 923 |
Lookup the first and if needed the second key, and delete the given |
| 924 |
values into the chosen databases. |
| 925 |
|
| 926 |
Meaning of the parameters is as follows: |
| 927 |
* table - Pointer to the table name. |
| 928 |
* first - Pointer to the first key. |
| 929 |
* second - Pointer to the second key. |
| 930 |
* _k - Pointer to the deleted db keys. |
| 931 |
* _op - Pointer to the db options for this operation. |
| 932 |
* _v - Pointer to the deleted db values. |
| 933 |
* _n - Number of key-value pairs in _k and _v parameters. |
| 934 |
|
| 935 |
7. int (* ul_db_query_t) (str * table, str * first, str * second, db_con_t |
| 936 |
*** _r_h, db_key_t* _k, db_op_t* _op, db_val_t* _v, db_key_t* _c, int _n, int |
| 937 |
_nc, db_key_t _o, db_res_t** _r); |
| 938 |
|
| 939 |
Lookup the first and if needed the second key, and performs a query in |
| 940 |
one of the chosen databases. The returned handle _r_h must be used to |
| 941 |
free the result set after the usage of the returned database entries, |
| 942 |
otherwise a memory leak will occur. You must call ul_db_free_result |
| 943 |
before you can call ul_db_query again! |
| 944 |
|
| 945 |
Meaning of the parameters is as follows: |
| 946 |
* table - Pointer to the table name. |
| 947 |
* first - Pointer to the first key. |
| 948 |
* second - Pointer to the second key. |
| 949 |
* _r_h - Pointer to the result handle, to free the result. |
| 950 |
* _op - Pointer to the db options for this operation. |
| 951 |
* _k - Pointer to the queried db keys. |
| 952 |
* _v - Pointer to the queried db values. |
| 953 |
* _c - Pointer to the db keys that should be returned. |
| 954 |
* _n - Number of key-value pairs in _k and _v parameters. |
| 955 |
* _nc - Number of key-value pairs in _c parameter. |
| 956 |
* _o - Order by options for the query. |
| 957 |
* _nc - Pointer to the result set. |
| 958 |
|
| 959 |
8. int (* ul_db_free_result_t)(db_con_t ** dbh, db_res_t * res); |
| 960 |
|
| 961 |
Frees the given result set, . |
| 962 |
|
| 963 |
Meaning of the parameters is as follows: |
| 964 |
* dbh - Pointer to the result handle. |
| 965 |
* res - Pointer to the result. |