Browse Source

modules/lcr: minor fix and improvement
- RPC command lcr.reload caused db tables to be loaded in some
situations more than once.
- If defunct column value of a gw is max UNIX timestamp value 4294967295
or greater, gw is considered currently unused and is not loaded into
memory at all.

Juha Heinanen 15 years ago
parent
commit
c96d8658da
4 changed files with 30 additions and 25 deletions
  1. 3 1
      modules/lcr/README
  2. 3 0
      modules/lcr/doc/lcr_admin.xml
  3. 22 19
      modules/lcr/lcr_mod.c
  4. 2 5
      modules/lcr/lcr_rpc.c

+ 3 - 1
modules/lcr/README

@@ -473,7 +473,9 @@ modparam("lcr", "flags_column", "gw_flags")
 3.15. defunct_column (string)
 
    Name of the column holding UNIX timestamp telling the time until which
-   the gw is considered as defunct.
+   the gw is considered as defunct. If timestamp value is 4294967295 (=
+   max UNIX timestamp value) or greater, gw is considered currently unused
+   and is not loaded into memory at all.
 
    Default value is “defunct”.
 

+ 3 - 0
modules/lcr/doc/lcr_admin.xml

@@ -438,6 +438,9 @@ modparam("lcr", "flags_column", "gw_flags")
 		<para>
 		Name of the column holding UNIX timestamp telling the
 		time until which the gw is considered as defunct.
+		If timestamp value is 4294967295 (= max UNIX timestamp value)
+		or greater, gw is considered currently unused and is not
+		loaded into memory at all.
 		</para>
 		<para>
 		<emphasis>

+ 22 - 19
modules/lcr/lcr_mod.c

@@ -1110,10 +1110,29 @@ int reload_tables()
 	    goto err;
 	}
 
-	null_gw_ip_addr = 0;
+	null_gw_ip_addr = gw_cnt = 0;
 
 	for (i = 0; i < RES_ROW_N(res); i++) {
 	    row = RES_ROWS(res) + i;
+	    if ((VAL_NULL(ROW_VALUES(row) + 11) == 1) ||
+		(VAL_TYPE(ROW_VALUES(row) + 11) != DB1_INT)) {
+		LM_ERR("lcr_gw id at row <%u> is null or not int\n", i);
+		goto err;
+	    }
+	    gw_id = (unsigned int)VAL_INT(ROW_VALUES(row) + 11);
+	    if (VAL_NULL(ROW_VALUES(row) + 10)) {
+		defunct_until = 0;
+	    } else {
+		if (VAL_TYPE(ROW_VALUES(row) + 10) != DB1_INT) {
+		    LM_ERR("lcr_gw defunct at row <%u> is not int\n", i);
+		    goto err;
+		}
+		defunct_until = (unsigned int)VAL_INT(ROW_VALUES(row) + 10);
+		if (defunct_until > 4294967294UL) {
+		    LM_DBG("skipping disabled gw <%u>\n", gw_id);
+		    continue;
+		}
+	    }
 	    if (!VAL_NULL(ROW_VALUES(row)) &&
 		(VAL_TYPE(ROW_VALUES(row)) != DB1_STRING)) {
 		LM_ERR("lcr_gw gw_name at row <%u> is not null or string\n", i);
@@ -1277,22 +1296,8 @@ int reload_tables()
 		goto err;
 	    }
 	    flags = (unsigned int)VAL_INT(ROW_VALUES(row) + 9);
-	    if (VAL_NULL(ROW_VALUES(row) + 10)) {
-		defunct_until = 0;
-	    } else {
-		if (VAL_TYPE(ROW_VALUES(row) + 10) != DB1_INT) {
-		    LM_ERR("lcr_gw defunct at row <%u> is not int\n", i);
-		    goto err;
-		}
-		defunct_until = (unsigned int)VAL_INT(ROW_VALUES(row) + 10);
-	    }
-	    if ((VAL_NULL(ROW_VALUES(row) + 11) == 1) ||
-		(VAL_TYPE(ROW_VALUES(row) + 11) != DB1_INT)) {
-		LM_ERR("lcr_gw id at row <%u> is null or not int\n", i);
-		goto err;
-	    }
-	    gw_id = (unsigned int)VAL_INT(ROW_VALUES(row) + 11);
-	    if (!insert_gw(gws, i + 1, gw_id, gw_name, gw_name_len,
+	    gw_cnt++;
+	    if (!insert_gw(gws, gw_cnt, gw_id, gw_name, gw_name_len,
 			   scheme, (unsigned int)ip_addr.s_addr, port,
 			   transport, params, params_len, hostname,
 			   hostname_len, ip_string, strip, tag, tag_len, flags,
@@ -1303,8 +1308,6 @@ int reload_tables()
 
 	lcr_dbf.free_result(dbh, res);
 	res = NULL;
-    
-	gw_cnt = i;
 
 	qsort(&(gws[1]), gw_cnt, sizeof(struct gw_info), comp_gws);
 	gws[0].ip_addr = gw_cnt;

+ 2 - 5
modules/lcr/lcr_rpc.c

@@ -46,12 +46,9 @@ static const char* reload_doc[2] = {
 
 static void reload(rpc_t* rpc, void* c)
 {
-    int i;
     lock_get(reload_lock);
-    for (i = 1; i <= lcr_count_param; i++) {
-	if (reload_tables(i) != 1)
-	    rpc->fault(c, 500, "LCR Module Reload Failed");
-    }
+    if (reload_tables() != 1)
+	rpc->fault(c, 500, "LCR Module Reload Failed");
     lock_release(reload_lock);
 }