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