Module: kamailio
Branch: master
Commit: 7fdbdd44c85bce7efbd19a3bdf5dcd52970e3197
URL: 
https://github.com/kamailio/kamailio/commit/7fdbdd44c85bce7efbd19a3bdf5dcd52970e3197

Author: Konstantin <piligrim...@mail.ru>
Committer: Daniel-Constantin Mierla <mico...@gmail.com>
Date: 2018-03-12T13:25:18+01:00

usrloc: cleanup by server_id. (#1480)

* usrloc: cleanup by server_id.

* usrloc: reverted README file changes.

* usrloc: moved server_id db request assignment under conditional command.

---

Modified: src/modules/usrloc/doc/usrloc_admin.xml
Modified: src/modules/usrloc/udomain.c
Modified: src/modules/usrloc/usrloc_mod.c
Modified: src/modules/usrloc/usrloc_mod.h

---

Diff:  
https://github.com/kamailio/kamailio/commit/7fdbdd44c85bce7efbd19a3bdf5dcd52970e3197.diff
Patch: 
https://github.com/kamailio/kamailio/commit/7fdbdd44c85bce7efbd19a3bdf5dcd52970e3197.patch

---

diff --git a/src/modules/usrloc/doc/usrloc_admin.xml 
b/src/modules/usrloc/doc/usrloc_admin.xml
index 5de9b82c08..2e9bdb3ff9 100644
--- a/src/modules/usrloc/doc/usrloc_admin.xml
+++ b/src/modules/usrloc/doc/usrloc_admin.xml
@@ -1201,7 +1201,9 @@ modparam("usrloc", "rm_expired_delay", 30)
        <section id="usrloc.p.server_id_filter">
                <title><varname>server_id_filter</varname> (int)</title>
                <para>
-                       Enable (1) or disable (0) filter records by server_id 
on load.
+                       Enable (1) or disable (0) filter records by server_id 
on load and during cleaning of expired db records.
+                        It could be usefull when you want to use the same 
location table for several kamailio instances which are configured to work in 
db_mode=1 or db_mode=2 (cache modes).
+                        Otherwise one instance of proxy cleans records made by 
another proxy and that breaks its cache.
                </para>
                <para>
                <emphasis>
diff --git a/src/modules/usrloc/udomain.c b/src/modules/usrloc/udomain.c
index 8f5bfe3061..aacca0513b 100644
--- a/src/modules/usrloc/udomain.c
+++ b/src/modules/usrloc/udomain.c
@@ -895,9 +895,10 @@ urecord_t* db_load_urecord_by_ruid(db1_con_t* _c, 
udomain_t* _d, str *_ruid)
  */
 int db_timer_udomain(udomain_t* _d)
 {
-       db_key_t keys[2];
-       db_op_t  ops[2];
-       db_val_t vals[2];
+       db_key_t keys[3];
+       db_op_t  ops[3];
+       db_val_t vals[3];
+       int key_num = 2;
 
        keys[0] = &expires_col;
        ops[0] = "<";
@@ -909,12 +910,21 @@ int db_timer_udomain(udomain_t* _d)
        vals[1].nul = 0;
        UL_DB_EXPIRES_SET(&vals[1], 0);
 
+       if (ul_db_srvid != 0) {
+               keys[2] = &srv_id_col;
+               ops[2] = OP_EQ;
+               vals[2].type = DB1_INT;
+               vals[2].nul = 0;
+               vals[2].val.int_val = server_id;
+               key_num = 3;
+       }
+
        if (ul_dbf.use_table(ul_dbh, _d->name) < 0) {
                LM_ERR("use_table failed\n");
                return -1;
        }
-
-       if (ul_dbf.delete(ul_dbh, keys, ops, vals, 2) < 0) {
+       
+       if (ul_dbf.delete(ul_dbh, keys, ops, vals, key_num) < 0) {
                LM_ERR("failed to delete from table %s\n",_d->name->s);
                return -1;
        }
diff --git a/src/modules/usrloc/usrloc_mod.c b/src/modules/usrloc/usrloc_mod.c
index cedc65a73d..50eb0cb888 100644
--- a/src/modules/usrloc/usrloc_mod.c
+++ b/src/modules/usrloc/usrloc_mod.c
@@ -176,7 +176,7 @@ unsigned int init_flag = 0;
 db1_con_t* ul_dbh = 0; /* Database connection handle */
 db_func_t ul_dbf;
 
-/* filter on load by server id */
+/* filter on load and during cleanup by server id */
 unsigned int ul_db_srvid = 0;
 
 /*! \brief
diff --git a/src/modules/usrloc/usrloc_mod.h b/src/modules/usrloc/usrloc_mod.h
index 5ac67d67ed..4b0fa35671 100644
--- a/src/modules/usrloc/usrloc_mod.h
+++ b/src/modules/usrloc/usrloc_mod.h
@@ -100,7 +100,7 @@ extern str ul_xavp_contact_name;
 extern db1_con_t* ul_dbh;   /* Database connection handle */
 extern db_func_t ul_dbf;
 
-/* filter on load by server id */
+/* filter on load and during cleanup by server id */
 extern unsigned int ul_db_srvid;
 
 /*


_______________________________________________
Kamailio (SER) - Development Mailing List
sr-dev@lists.kamailio.org
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to