Module: kamailio
Branch: master
Commit: 93b5d2e5098938e49831125622ee6a5a8ba002c4
URL:
https://github.com/kamailio/kamailio/commit/93b5d2e5098938e49831125622ee6a5…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2016-01-24T16:50:29+01:00
usrloc: option to clean up database on write back/through modes
- enabled by db_timer_clean parameter
- deletes expired records from database using secondary timer
- can be helpful if there was an error on db client after the db
operation was done on server, as reported by GH #30
---
Modified: modules/usrloc/dlist.c
Modified: modules/usrloc/dlist.h
Modified: modules/usrloc/udomain.c
Modified: modules/usrloc/ul_mod.c
---
Diff:
https://github.com/kamailio/kamailio/commit/93b5d2e5098938e49831125622ee6a5…
Patch:
https://github.com/kamailio/kamailio/commit/93b5d2e5098938e49831125622ee6a5…
---
diff --git a/modules/usrloc/dlist.c b/modules/usrloc/dlist.c
index 1081aad..65ea97b 100644
--- a/modules/usrloc/dlist.c
+++ b/modules/usrloc/dlist.c
@@ -764,6 +764,22 @@ int synchronize_all_udomains(int istart, int istep)
return res;
}
+/*!
+ * \brief Run timer handler to clean all domains in db
+ * \return 0 if all timer return 0, != 0 otherwise
+ */
+int ul_db_clean_udomains(void)
+{
+ int res = 0;
+ dlist_t* ptr;
+
+ get_act_time(); /* Get and save actual time */
+
+ for( ptr=root ; ptr ; ptr=ptr->next)
+ res |= db_timer_udomain(ptr->d);
+
+ return res;
+}
/*!
* \brief Find a particular domain, small wrapper around find_dlist
diff --git a/modules/usrloc/dlist.h b/modules/usrloc/dlist.h
index a210996..e293325 100644
--- a/modules/usrloc/dlist.h
+++ b/modules/usrloc/dlist.h
@@ -146,4 +146,6 @@ int find_domain(str* _d, udomain_t** _p);
*/
void ul_set_max_partition(unsigned int m);
+int ul_db_clean_udomains(void);
+
#endif
diff --git a/modules/usrloc/udomain.c b/modules/usrloc/udomain.c
index 3ef2803..d57f212 100644
--- a/modules/usrloc/udomain.c
+++ b/modules/usrloc/udomain.c
@@ -881,7 +881,8 @@ urecord_t* db_load_urecord_by_ruid(db1_con_t* _c, udomain_t* _d, str
*_ruid)
/*!
- * \brief Timer function to cleanup expired contacts, DB_ONLY db_mode
+ * \brief Timer function to cleanup expired contacts, db_mode: DB_ONLY
+ * and for WRITE_BACK, WRITE_THROUGH on config param
* \param _d cleaned domain
* \return 0 on success, -1 on failure
*/
diff --git a/modules/usrloc/ul_mod.c b/modules/usrloc/ul_mod.c
index 1b41f26..fa72e2b 100644
--- a/modules/usrloc/ul_mod.c
+++ b/modules/usrloc/ul_mod.c
@@ -95,6 +95,7 @@ static int mod_init(void); /*!< Module
initialization f
static void destroy(void); /*!< Module destroy function */
static void ul_core_timer(unsigned int ticks, void* param); /*!< Core timer handler
*/
static void ul_local_timer(unsigned int ticks, void* param); /*!< Local timer handler
*/
+static void ul_db_clean_timer(unsigned int ticks, void* param); /*!< DB clean timer
handler */
static int child_init(int rank); /*!< Per-child init function */
static int mi_child_init(void);
@@ -166,6 +167,7 @@ int skip_remote_socket = 0; /*!< By default do not skip remote
socket */
int ul_fetch_rows = 2000; /*!< number of rows to fetch from result */
int ul_hash_size = 10;
int ul_db_insert_null = 0;
+int ul_db_timer_clean = 0;
/* flags */
unsigned int nat_bflag = (unsigned int)-1;
@@ -233,6 +235,7 @@ static param_export_t params[] = {
{"db_raw_fetch_type", PARAM_INT, &ul_db_raw_fetch_type},
{"db_insert_null", PARAM_INT, &ul_db_insert_null},
{"server_id_filter", PARAM_INT, &ul_db_srvid},
+ {"db_timer_clean", PARAM_INT, &ul_db_timer_clean},
{0, 0, 0}
};
@@ -361,6 +364,11 @@ static int mod_init(void)
return -1;
}
}
+ if(db_mode==WRITE_THROUGH || db_mode==WRITE_BACK) {
+ if(ul_db_timer_clean!=0) {
+ sr_wtimer_add(ul_db_clean_timer, 0, timer_interval);
+ }
+ }
if (nat_bflag==(unsigned int)-1) {
nat_bflag = 0;
@@ -519,6 +527,14 @@ static void ul_local_timer(unsigned int ticks, void* param)
}
/*! \brief
+ * DB dlean timer handler
+ */
+static void ul_db_clean_timer(unsigned int ticks, void* param)
+{
+ ul_db_clean_udomains();
+}
+
+/*! \brief
* preload module parameter handler
*/
static int ul_preload_param(modparam_t type, void* val)