Browse code

rtpengine: reworked build of rtpengine sockets to avoid serial initialization

- do not lock during startup, change of the list of rtpengines can be
done only upon reload, which is now disabled until all child processes
did the init
- do rtpengine testing (probing) only in one child, the status is stored
in shared memory, no need to do it from each process.

Daniel-Constantin Mierla authored on 28/12/2018 08:17:31
Showing 1 changed files
... ...
@@ -193,7 +193,7 @@ static struct rtpp_node *select_rtpp_node_new(str, str, int, struct rtpp_node **
193 193
 static struct rtpp_node *select_rtpp_node_old(str, str, int, enum rtpe_operation);
194 194
 static struct rtpp_node *select_rtpp_node(str, str, int, struct rtpp_node **, int, enum rtpe_operation);
195 195
 static int is_queried_node(struct rtpp_node *, struct rtpp_node **, int);
196
-static int build_rtpp_socks();
196
+static int build_rtpp_socks(int lmode, int rtest);
197 197
 static char *send_rtpp_command(struct rtpp_node *, bencode_item_t *, int *);
198 198
 static int get_extra_id(struct sip_msg* msg, str *id_str);
199 199
 
... ...
@@ -1174,6 +1174,10 @@ static void rtpengine_rpc_reload(rpc_t* rpc, void* ctx)
1174 1174
 		rpc->fault(ctx, 500, "No Database URL");
1175 1175
 		return;
1176 1176
 	}
1177
+	if(!sr_instance_ready()) {
1178
+		rpc->fault(ctx, 500, "Initializing - try later");
1179
+		return;
1180
+	}
1177 1181
 
1178 1182
 	if (init_rtpproxy_db() < 0) {
1179 1183
 		// fail reloading from database
... ...
@@ -1181,7 +1185,7 @@ static void rtpengine_rpc_reload(rpc_t* rpc, void* ctx)
1181 1185
 		return;
1182 1186
 	}
1183 1187
 
1184
-	if (build_rtpp_socks()) {
1188
+	if (build_rtpp_socks(1, 1)) {
1185 1189
 		rpc->fault(ctx, 500, "Out of memory");
1186 1190
 		return;
1187 1191
 	}
... ...
@@ -1195,7 +1199,12 @@ static int rtpengine_rpc_iterate(rpc_t* rpc, void* ctx, const str *rtpp_url,
1195 1199
 	int found = RPC_FOUND_NONE, err = 0;
1196 1200
 	int ret;
1197 1201
 
1198
-	if (build_rtpp_socks()) {
1202
+	if(!sr_instance_ready()) {
1203
+		rpc->fault(ctx, 500, "Initializing - try later");
1204
+		return -1;
1205
+	}
1206
+
1207
+	if (build_rtpp_socks(1, 1)) {
1199 1208
 		rpc->fault(ctx, 500, "Out of memory");
1200 1209
 		return -1;
1201 1210
 	}
... ...
@@ -1634,14 +1643,19 @@ mod_init(void)
1634 1643
 }
1635 1644
 
1636 1645
 #define rtpe_reload_lock_get(plock) do { \
1637
-	if (rtpp_db_url.s != NULL) lock_get(plock); \
1646
+	if (rtpp_db_url.s != NULL && lmode != 0) lock_get(plock); \
1638 1647
 } while(0)
1639 1648
 
1640 1649
 #define rtpe_reload_lock_release(plock) do { \
1641
-	if (rtpp_db_url.s != NULL) lock_release(plock); \
1650
+	if (rtpp_db_url.s != NULL && lmode != 0) lock_release(plock); \
1642 1651
 } while(0)
1643 1652
 
1644
-static int build_rtpp_socks() {
1653
+/**
1654
+ * build rtp enigne sockets
1655
+ * - lmode: locking mode (1 - lock if needed; 0 - no locking)
1656
+ * - rtest: rtpengine testing (1 - test if active; 0 - no test done)
1657
+ */
1658
+static int build_rtpp_socks(int lmode, int rtest) {
1645 1659
 	int n, i;
1646 1660
 	char *cp;
1647 1661
 	struct addrinfo hints, *res;
... ...
@@ -1768,7 +1782,7 @@ static int build_rtpp_socks() {
1768 1782
 
1769 1783
 			freeaddrinfo(res);
1770 1784
 rptest:
1771
-			pnode->rn_disabled = rtpp_test(pnode, 0, 1);
1785
+			if(rtest) pnode->rn_disabled = rtpp_test(pnode, 0, 1);
1772 1786
 		}
1773 1787
 		rtpe_reload_lock_release(rtpp_list->rset_lock);
1774 1788
 	}
... ...
@@ -1848,8 +1862,14 @@ child_init(int rank)
1848 1862
 	memset(queried_nodes_ptr, 0, MAX_RTPP_TRIED_NODES * sizeof(struct rtpp_node*));
1849 1863
 
1850 1864
 	/* Iterate known RTP proxies - create sockets */
1851
-	if (build_rtpp_socks())
1852
-		return -1;
1865
+	if(rank==PROC_SIPINIT) {
1866
+		/* probe rtpengines only in first worker */
1867
+		if (build_rtpp_socks(0, 1))
1868
+			return -1;
1869
+	} else {
1870
+		if (build_rtpp_socks(0, 0))
1871
+			return -1;
1872
+	}
1853 1873
 
1854 1874
 	return 0;
1855 1875
 }
... ...
@@ -2865,7 +2885,7 @@ select_rtpp_node(str callid, str viabranch, int do_test, struct rtpp_node **quer
2865 2885
 {
2866 2886
 	struct rtpp_node *node = NULL;
2867 2887
 
2868
-	if (build_rtpp_socks()) {
2888
+	if (build_rtpp_socks(1, 0)) {
2869 2889
 		LM_ERR("out of memory\n");
2870 2890
 		return NULL;
2871 2891
 	}