From 5ce6df2d3aee023f0e2d4f9cad14d6e560557ae2 Mon Sep 17 00:00:00 2001 From: Stefan Mititelu Date: Thu, 10 Dec 2015 16:59:30 +0200 Subject: [PATCH] rtpengine: Add hiding of deleted table nodes 'kamctl fifo nh_show_rtpp all' reflects the rtpengine table state. When node is deleted from the table the node itself isn't freed but disabled permanent and hidden for display. This is mainly because one might want the current session to finish for the deleted table nodes (see allow_op modparam). Hiding the nodes and not freeing them will spare time deciding if there are any sessions left for the deleted rtpengine. --- modules/rtpengine/doc/rtpengine_admin.xml | 11 ++++-- modules/rtpengine/rtpengine.c | 44 +++++++++++++++++++++++ modules/rtpengine/rtpengine.h | 5 +++ modules/rtpengine/rtpengine_db.c | 3 ++ 4 files changed, 60 insertions(+), 3 deletions(-) diff --git a/modules/rtpengine/doc/rtpengine_admin.xml b/modules/rtpengine/doc/rtpengine_admin.xml index 699a6efcf5d..6875e5fa35b 100644 --- a/modules/rtpengine/doc/rtpengine_admin.xml +++ b/modules/rtpengine/doc/rtpengine_admin.xml @@ -221,6 +221,11 @@ modparam("rtpengine", "rtpengine_tout_ms", 2000) This is useful when deactivating a node for maintanance and reject new sessions but allow current ones to finish. + The behaviour is the same for a rtpengine deleted table node. + When the node is deleted from the table and the table reloaded (see nh_reload_rtpp) the node actually is disabled(permanent) and hidden for display. + Next time the same node will be added in the table, and the content reloaded, it will be updated and re-displayed. + + Default value is 0 to keep the current behaviour. @@ -1261,9 +1266,9 @@ $ &ctltool; fifo nh_ping_rtpp all Returns specific message related to success, failure and no db_url configured. - NOTE: The current behaviour updates the nodes state or creates new ones, - based on the database content. Old nodes are not deleted if they are deleted - from database. This may require locking on the global nodes list. + NOTE: The current behaviour updates the nodes state or creates new ones or + hides old ones, based on the database content. If allow_op modparam is enabled, + the sessions are still allowed to finish for the hidden old nodes. diff --git a/modules/rtpengine/rtpengine.c b/modules/rtpengine/rtpengine.c index b6c7b9a30f6..908260680c5 100644 --- a/modules/rtpengine/rtpengine.c +++ b/modules/rtpengine/rtpengine.c @@ -387,6 +387,45 @@ struct module_exports exports = { child_init }; +/* hide the node from display and disable it permanent */ +int rtpengine_delete_node(struct rtpp_node *rtpp_node) +{ + rtpp_node->rn_displayed = 0; + rtpp_node->rn_disabled = MI_MAX_RECHECK_TICKS; + + return 1; +} + + +int rtpengine_delete_node_set(struct rtpp_set *rtpp_list) +{ + struct rtpp_node *rtpp_node; + + for(rtpp_node = rtpp_list->rn_first; rtpp_node != NULL; + rtpp_node = rtpp_node->rn_next) { + rtpengine_delete_node(rtpp_node); + } + + return 1; +} + + +int rtpengine_delete_node_all() +{ + struct rtpp_set *rtpp_list; + + if (!rtpp_set_list) { + return 1; + } + + for(rtpp_list = rtpp_set_list->rset_first; rtpp_list != NULL; + rtpp_list = rtpp_list->rset_next) { + rtpengine_delete_node_set(rtpp_list); + } + + return 1; +} + static int get_ip_type(char *str_addr) { @@ -732,6 +771,7 @@ int add_rtpengine_socks(struct rtpp_set * rtpp_list, char * rtpproxy, pnode->rn_weight = local_weight; pnode->rn_umode = 0; pnode->rn_disabled = disabled; + pnode->rn_displayed = 1; pnode->rn_url.s = shm_malloc(p2 - p1 + 1); if (pnode->rn_url.s == NULL) { rtpp_no--; @@ -785,6 +825,7 @@ int add_rtpengine_socks(struct rtpp_set * rtpp_list, char * rtpproxy, rtpp_node = get_rtpp_node(rtpp_list, &pnode->rn_url); if (rtpp_node) { rtpp_node->rn_disabled = pnode->rn_disabled; + rtpp_node->rn_displayed = pnode->rn_displayed; rtpp_node->rn_recheck_ticks = pnode->rn_recheck_ticks; rtpp_node->rn_weight = pnode->rn_weight; @@ -1265,6 +1306,9 @@ static struct mi_root* mi_show_rtp_proxy(struct mi_root* cmd_tree, void* param) for(crt_rtpp = rtpp_list->rn_first; crt_rtpp != NULL; crt_rtpp = crt_rtpp->rn_next) { + if (!crt_rtpp->rn_displayed) { + continue; + } /* found a matching rtpp - show it */ if (found == MI_FOUND_ALL || diff --git a/modules/rtpengine/rtpengine.h b/modules/rtpengine/rtpengine.h index f29c9cc1969..45a7401be45 100644 --- a/modules/rtpengine/rtpengine.h +++ b/modules/rtpengine/rtpengine.h @@ -36,6 +36,7 @@ struct rtpp_node { char *rn_address; /* substring of rn_url */ int rn_disabled; /* found unaccessible? */ unsigned rn_weight; /* for load balancing */ + unsigned int rn_displayed; /* for delete at db reload */ unsigned int rn_recheck_ticks; int rn_rep_supported; int rn_ptl_supported; @@ -65,6 +66,10 @@ struct rtpp_node *get_rtpp_node(struct rtpp_set *rtpp_list, str *url); struct rtpp_set *get_rtpp_set(int set_id); int add_rtpengine_socks(struct rtpp_set * rtpp_list, char * rtpproxy, unsigned int weight, int disabled, unsigned int ticks, int isDB); +int rtpengine_delete_node(struct rtpp_node *rtpp_node); +int rtpengine_delete_node_set(struct rtpp_set *rtpp_list); +int rtpengine_delete_node_all(); + int init_rtpproxy_db(void); diff --git a/modules/rtpengine/rtpengine_db.c b/modules/rtpengine/rtpengine_db.c index e91b3cbce6a..eda7bbb2463 100644 --- a/modules/rtpengine/rtpengine_db.c +++ b/modules/rtpengine/rtpengine_db.c @@ -98,6 +98,9 @@ static int rtpp_load_db(void) LM_WARN("No rtpproxy instances in database\n"); return 0; } + + rtpengine_delete_node_all(); + for (i=0; i<n_rows; i++) { values = ROW_VALUES(rows + i);