瀏覽代碼

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.
Stefan Mititelu 9 年之前
父節點
當前提交
5ce6df2d3a

+ 8 - 3
modules/rtpengine/doc/rtpengine_admin.xml

@@ -221,6 +221,11 @@ modparam("rtpengine", "rtpengine_tout_ms", 2000)
 		This is <emphasis>useful</emphasis> when deactivating a node for maintanance and reject new sessions but allow current ones to finish.
 		</para>
 		<para>
+		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.
+		</para>
+		<para>
 		<emphasis>
 		Default value is <quote>0</quote> to keep the current behaviour.
 		</emphasis>
@@ -1261,9 +1266,9 @@ $ &ctltool; fifo nh_ping_rtpp all
 				Returns specific message related to success, failure and no db_url configured.
 			</para>
 			<para>
-				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.
 			</para>
 			<example>
 			<title>

+ 44 - 0
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 ||

+ 5 - 0
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);
 

+ 3 - 0
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);