From 5d14f5cada8d4bc43bfa1865ca95b0fd2213f8f3 Mon Sep 17 00:00:00 2001 From: Julien Chavanton Date: Sat, 18 Mar 2017 13:16:15 -0700 Subject: [PATCH] usrloc: adding params db_load: enable/disable loading from the database on mod_init db_insert_update: insert into table, update on duplicate key --- src/modules/usrloc/doc/usrloc_admin.xml | 42 +++++++++++++++++++++++++ src/modules/usrloc/ucontact.c | 16 +++++++--- src/modules/usrloc/usrloc_mod.c | 7 ++++- src/modules/usrloc/usrloc_mod.h | 1 + 4 files changed, 61 insertions(+), 5 deletions(-) diff --git a/src/modules/usrloc/doc/usrloc_admin.xml b/src/modules/usrloc/doc/usrloc_admin.xml index 34aebee5b9a..ac744ea27f4 100644 --- a/src/modules/usrloc/doc/usrloc_admin.xml +++ b/src/modules/usrloc/doc/usrloc_admin.xml @@ -687,6 +687,48 @@ modparam("usrloc", "db_mode", 2) +
+ <varname>db_load</varname> (integer) + + Determine if the usrloc module should load contacts from the database storage during module initialization + A value of 0 disable the loading from the database, this parameter is ignored if db_mode 4 is set + + + + Default value is 1. + + + + Set <varname>db_load</varname> parameter + +... +modparam("usrloc", "db_load", "0") +... + + +
+ +
+ <varname>db_insert_update</varname> (integer) + + Determine if the usrloc module should do an update when a duplicate key is found while inserting + A value of 1 will activate update on duplicate key + + + + Default value is 0. + + + + Set <varname>db_insert_update</varname> parameter + +... +modparam("usrloc", "db_insert_update", "1") +... + + +
+
<varname>matching_mode</varname> (integer) diff --git a/src/modules/usrloc/ucontact.c b/src/modules/usrloc/ucontact.c index 630a4bd8c57..54cac0e4e01 100644 --- a/src/modules/usrloc/ucontact.c +++ b/src/modules/usrloc/ucontact.c @@ -679,10 +679,18 @@ int db_insert_ucontact(ucontact_t* _c) return -1; } - if (ul_dbf.insert(ul_dbh, keys, vals, nr_cols) < 0) { - LM_ERR("inserting contact in db failed %.*s (%.*s)\n", - _c->aor->len, ZSW(_c->aor->s), _c->ruid.len, ZSW(_c->ruid.s)); - return -1; + if (db_insert_update && ul_dbf.insert_update) { + if (ul_dbf.insert_update(ul_dbh, keys, vals, nr_cols) < 0) { + LM_ERR("inserting with update contact in db failed %.*s (%.*s)\n", + _c->aor->len, ZSW(_c->aor->s), _c->ruid.len, ZSW(_c->ruid.s)); + return -1; + } + } else { + if (ul_dbf.insert(ul_dbh, keys, vals, nr_cols) < 0) { + LM_ERR("inserting contact in db failed %.*s (%.*s)\n", + _c->aor->len, ZSW(_c->aor->s), _c->ruid.len, ZSW(_c->ruid.s)); + return -1; + } } if (ul_xavp_contact_name.s) { diff --git a/src/modules/usrloc/usrloc_mod.c b/src/modules/usrloc/usrloc_mod.c index 81346de631f..3191e1bb1e6 100644 --- a/src/modules/usrloc/usrloc_mod.c +++ b/src/modules/usrloc/usrloc_mod.c @@ -155,6 +155,8 @@ str ulattrs_last_mod_col = str_init(ULATTRS_LAST_MOD_COL); /*!< Name of column c str db_url = str_init(DEFAULT_DB_URL); /*!< Database URL */ int timer_interval = 60; /*!< Timer interval in seconds */ int db_mode = 0; /*!< Database sync scheme: 0-no db, 1-write through, 2-write back, 3-only db */ +int db_load = 1; /*!< Database load after restart: 1- true, 0- false (only the db_mode allows it) */ +int db_insert_update = 0; /*!< Database : update on duplicate key instead of error */ int use_domain = 0; /*!< Whether usrloc should use domain part of aor */ int desc_time_order = 0; /*!< By default do not enable timestamp ordering */ int handle_lost_tcp = 0; /*!< By default do not remove contacts before expiration time */ @@ -202,6 +204,8 @@ static param_export_t params[] = { {"db_url", PARAM_STR, &db_url }, {"timer_interval", INT_PARAM, &timer_interval }, {"db_mode", INT_PARAM, &db_mode }, + {"db_load", INT_PARAM, &db_load }, + {"db_insert_update", INT_PARAM, &db_insert_update }, {"use_domain", INT_PARAM, &use_domain }, {"desc_time_order", INT_PARAM, &desc_time_order }, {"user_agent_column", PARAM_STR, &user_agent_col}, @@ -405,6 +409,7 @@ static int child_init(int _rank) break; case DB_READONLY: /* connect to db only from child 1 for preload */ + db_load=1; /* we always load from the db in this mode */ if(_rank!=PROC_SIPINIT) return 0; break; @@ -416,7 +421,7 @@ static int child_init(int _rank) return -1; } /* _rank==PROC_SIPINIT is used even when fork is disabled */ - if (_rank==PROC_SIPINIT && db_mode!=DB_ONLY) { + if (_rank==PROC_SIPINIT && db_mode!=DB_ONLY && db_load) { /* if cache is used, populate domains from DB */ for( ptr=root ; ptr ; ptr=ptr->next) { if (preload_udomain(ul_dbh, ptr->d) < 0) { diff --git a/src/modules/usrloc/usrloc_mod.h b/src/modules/usrloc/usrloc_mod.h index 72a5a10b210..ccd9540ecfd 100644 --- a/src/modules/usrloc/usrloc_mod.h +++ b/src/modules/usrloc/usrloc_mod.h @@ -76,6 +76,7 @@ extern str ulattrs_last_mod_col; extern str db_url; extern int timer_interval; extern int db_mode; +extern int db_insert_update; extern int use_domain; extern int desc_time_order; extern int cseq_delay;