- The new parameter "mdb_availability_control" overwrites the "write_on_master_db" parameter based on the availability of master database.
<!-- Kamailio Pull Request Template -->
<!-- IMPORTANT: - for detailed contributing guidelines, read: https://github.com/kamailio/kamailio/blob/master/.github/CONTRIBUTING.md - pull requests must be done to master branch, unless they are backports of fixes from master branch to a stable branch - backports to stable branches must be done with 'git cherry-pick -x ...' - code is contributed under BSD for core and main components (tm, sl, auth, tls) - code is contributed GPLv2 or a compatible license for the other components - GPL code is contributed with OpenSSL licensing exception -->
#### Pre-Submission Checklist <!-- Go over all points below, and after creating the PR, tick all the checkboxes that apply --> <!-- All points should be verified, otherwise, read the CONTRIBUTING guidelines from above--> <!-- If you're unsure about any of these, don't hesitate to ask on sr-dev mailing list --> - [ ] Commit message has the format required by CONTRIBUTING guide - [ ] Commits are split per component (core, individual modules, libs, utils, ...) - [ ] Each component has a single commit (if not, squash them into one commit) - [ ] No commits to README files for modules (changes must be done to docbook files in `doc/` subfolder, the README file is autogenerated)
#### Type Of Change - [ ] Small bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds new functionality) - [ ] Breaking change (fix or feature that would change existing functionality)
#### Checklist: <!-- Go over all points below, and after creating the PR, tick the checkboxes that apply --> - [ ] PR should be backported to stable branches - [ ] Tested changes locally - [ ] Related to issue #XXXX (replace XXXX with an open issue number)
#### Description <!-- Describe your changes in detail -->
You can view, comment on, or merge this pull request online at:
https://github.com/kamailio/kamailio/pull/1529
-- Commit Summary --
* p_usrloc: new parameter "mdb_availability_control" has been created.
-- File Changes --
M src/modules/p_usrloc/doc/p_usrloc_admin.xml (20) M src/modules/p_usrloc/p_usrloc_mod.c (17) M src/modules/p_usrloc/p_usrloc_mod.h (6) M src/modules/p_usrloc/ul_db.c (34) M src/modules/p_usrloc/ul_db.h (1) M src/modules/p_usrloc/ul_db_watch.c (24) M src/modules/p_usrloc/ul_db_watch.h (2)
-- Patch Links --
https://github.com/kamailio/kamailio/pull/1529.patch https://github.com/kamailio/kamailio/pull/1529.diff
@lbalaceanu - any comments on this patch?
lbalaceanu commented on this pull request.
I will continue the review tomorrow.
@@ -307,6 +309,13 @@ static int mod_init(void)
} #endif
+ if((write_on_master_db_shared = shm_malloc(sizeof(dbm_write_t))) == NULL) {
Make sure to shm_free this allocated memory.
@@ -123,5 +123,11 @@ extern int connection_expires;
extern int alg_location;
extern int max_loc_nr; +typedef struct dbm_write {
Structure name must be a noun.
@@ -96,7 +96,10 @@ void check_dbs(unsigned int ticks, void *param){
ul_db_handle_list_t * tmp2, * new_element; int found; int i; - + + if(mdb_availability_control) {
mdb_availability_control is also checked inside check_master_db() function.
lbalaceanu commented on this pull request.
@@ -149,6 +152,25 @@ void check_dbs(unsigned int ticks, void *param){
lock_release(list_lock); }
+void check_master_db(int dbm_write_default) { + if(mdb_availability_control) { + if(mdb.write.dbh){
Is it necessary to close the connection each time when verifying it?
@@ -677,6 +677,26 @@ modparam("usrloc", "db_update_as_insert", 1)
... modparam("p_usrloc", "default_db_url", "mysql://ser:ser@localhost/ser") ... +</programlisting>
Since this is related to write_on_master_db, please move this documentation under the write_on_master_db parameter.
@@ -102,13 +102,16 @@ int ul_db_child_init(void) {
if(ul_db_child_locnr_init() == -1) return -1; LM_INFO("location number is %d\n", max_loc_nr); - if(db_master_write){ + lock_get(&write_on_master_db_shared->lock);
Check whether in ul_db_init() you need to acquire locks at all. It seems like this function is called one time only, before any fork is done, so most probably no synchronisation is needed. Same for lock release.
hdikme commented on this pull request.
@@ -149,6 +152,25 @@ void check_dbs(unsigned int ticks, void *param){
lock_release(list_lock); }
+void check_master_db(int dbm_write_default) { + if(mdb_availability_control) { + if(mdb.write.dbh){
There is unfortunately no other function other than "db_init_f init;" that could be used to check if the master db is available. Therefore each time a new mdb handler is created from the scratch and this requires first closing the existing mdb handler.
hdikme commented on this pull request.
@@ -96,7 +96,10 @@ void check_dbs(unsigned int ticks, void *param){
ul_db_handle_list_t * tmp2, * new_element; int found; int i; - + + if(mdb_availability_control) {
correct, i m removing the one inside the check_master_db() function.
hdikme commented on this pull request.
@@ -123,5 +123,11 @@ extern int connection_expires;
extern int alg_location;
extern int max_loc_nr; +typedef struct dbm_write {
has been changed with "db_shared_param".
hdikme commented on this pull request.
@@ -307,6 +309,13 @@ static int mod_init(void)
} #endif
+ if((write_on_master_db_shared = shm_malloc(sizeof(dbm_write_t))) == NULL) {
The parameter will be created once at the beginning of mod_init and used so long as the process runs, therefore i haven't freed it.
hdikme commented on this pull request.
@@ -677,6 +677,26 @@ modparam("usrloc", "db_update_as_insert", 1)
... modparam("p_usrloc", "default_db_url", "mysql://ser:ser@localhost/ser") ... +</programlisting>
Done!
hdikme commented on this pull request.
@@ -102,13 +102,16 @@ int ul_db_child_init(void) {
if(ul_db_child_locnr_init() == -1) return -1; LM_INFO("location number is %d\n", max_loc_nr); - if(db_master_write){ + lock_get(&write_on_master_db_shared->lock);
p_usrloc_mod.c: The fork() system call is triggered in the init_db_check() function, which takes place just before calling the ul_db_child_init() function where the above mentioned lock checking mechanism is used.
Merged #1529.
Thank you @hdikme. Closing the pull request.