Explorar o código

usrloc: new parameter rm_expired_delay

- set how many seconds to delay the removal of an expired record
- for now works only in DB_ONLY mode
Daniel-Constantin Mierla %!s(int64=7) %!d(string=hai) anos
pai
achega
3de21172fa

+ 3 - 1
src/modules/usrloc/udomain.c

@@ -42,6 +42,8 @@
 #include "usrloc.h"
 #include "urecord.h"
 
+extern int ul_rm_expired_delay;
+
 #ifdef STATISTICS
 static char *build_stat_name( str* domain, char *var_name)
 {
@@ -900,7 +902,7 @@ int db_timer_udomain(udomain_t* _d)
 	keys[0] = &expires_col;
 	ops[0] = "<";
 	vals[0].nul = 0;
-	UL_DB_EXPIRES_SET(&vals[0], act_time + 1);
+	UL_DB_EXPIRES_SET(&vals[0], act_time + 1 + ul_rm_expired_delay);
 
 	keys[1] = &expires_col;
 	ops[1] = OP_NEQ;

+ 3 - 1
src/modules/usrloc/urecord.c

@@ -286,8 +286,10 @@ static inline void nodb_timer(urecord_t* _r)
 
 		if (!VALID_CONTACT(ptr, act_time)) {
 			/* run callbacks for EXPIRE event */
-			if (exists_ulcb_type(UL_CONTACT_EXPIRE))
+			if (!(ptr->flags&FL_EXPCLB) && exists_ulcb_type(UL_CONTACT_EXPIRE)) {
 				run_ul_callbacks( UL_CONTACT_EXPIRE, ptr);
+				ptr->flags |= FL_EXPCLB;
+			}
 
 			LM_DBG("Binding '%.*s','%.*s' has expired\n",
 				ptr->aor->len, ZSW(ptr->aor->s),

+ 1 - 0
src/modules/usrloc/usrloc.h

@@ -62,6 +62,7 @@ typedef enum flags {
 	FL_NONE        = 0,          /*!< No flags set */
 	FL_MEM         = 1 << 0,     /*!< Update memory only */
 	FL_DMQRPL      = 1 << 1,     /*!< DMQ replication */
+	FL_EXPCLB      = 1 << 2,     /*!< Expired callback executed */
 	FL_ALL         = (int)0xFFFFFFFF  /*!< All flags set */
 } flags_t;
 

+ 13 - 0
src/modules/usrloc/usrloc_mod.c

@@ -111,6 +111,7 @@ int ul_keepalive_timeout = 0;
 int ul_db_ops_ruid = 1;
 int ul_expires_type = 0;
 int ul_db_raw_fetch_type = 0;
+int ul_rm_expired_delay = 0;
 
 str ul_xavp_contact_name = {0};
 
@@ -238,6 +239,7 @@ static param_export_t params[] = {
 	{"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},
+	{"rm_expired_delay",    PARAM_INT, &ul_rm_expired_delay},
 	{0, 0, 0}
 };
 
@@ -272,6 +274,17 @@ static int mod_init(void)
 	int i;
 	udomain_t* d;
 
+	if(ul_rm_expired_delay!=0) {
+		if(db_mode != DB_ONLY) {
+			LM_ERR("rm expired delay feature is available for db only mode\n");
+			return -1;
+		}
+	}
+	if(ul_rm_expired_delay<0) {
+		LM_WARN("rm expired delay value is negative (%d) - setting it to 0\n",
+				ul_rm_expired_delay);
+		ul_rm_expired_delay = 0;
+	}
 	if(sruid_init(&_ul_sruid, '-', "ulcx", SRUID_INC)<0)
 		return -1;