Browse code

dispatcher: added reload_delta parameter

- limit the frequency of rpc reload commands to try to avoid races of
parallel reload operations
- default value is 5 seconds (no more than one reload command every 5
seconds)

Daniel-Constantin Mierla authored on 20/05/2019 09:15:48
Showing 1 changed files
... ...
@@ -141,6 +141,9 @@ str ds_event_callback = STR_NULL;
141 141
 str ds_db_extra_attrs = STR_NULL;
142 142
 param_t *ds_db_extra_attrs_list = NULL;
143 143
 
144
+static int ds_reload_delta = 5;
145
+static time_t *ds_rpc_reload_time = NULL;
146
+
144 147
 /** module functions */
145 148
 static int mod_init(void);
146 149
 static int child_init(int);
... ...
@@ -271,6 +274,7 @@ static param_export_t params[]={
271 274
 	{"ds_attrs_none",      PARAM_INT, &ds_attrs_none},
272 275
 	{"ds_db_extra_attrs",  PARAM_STR, &ds_db_extra_attrs},
273 276
 	{"ds_load_mode",       PARAM_INT, &ds_load_mode},
277
+	{"reload_delta",       PARAM_INT, &ds_reload_delta },
274 278
 	{0,0,0}
275 279
 };
276 280
 
... ...
@@ -451,6 +455,14 @@ static int mod_init(void)
451 455
 		LM_ERR("invalid ds_latency_estimator_alpha must be between 0 and 1000,"
452 456
 				" using default[%.3f]\n", ds_latency_estimator_alpha);
453 457
 	}
458
+
459
+	ds_rpc_reload_time = shm_malloc(sizeof(time_t));
460
+	if(ds_rpc_reload_time == NULL) {
461
+		SHM_MEM_ERROR;
462
+		return -1;
463
+	}
464
+	*ds_rpc_reload_time = 0;
465
+
454 466
 	return 0;
455 467
 }
456 468
 
... ...
@@ -477,6 +489,10 @@ static void destroy(void)
477 489
 		shm_free(ds_ping_reply_codes);
478 490
 	if(ds_ping_reply_codes_cnt)
479 491
 		shm_free(ds_ping_reply_codes_cnt);
492
+	if(ds_rpc_reload_time!=NULL) {
493
+		shm_free(ds_rpc_reload_time);
494
+		ds_rpc_reload_time = 0;
495
+	}
480 496
 }
481 497
 
482 498
 #define GET_VALUE(param_name, param, i_value, s_value, value_flags)        \
... ...
@@ -1373,6 +1389,19 @@ static const char *dispatcher_rpc_reload_doc[2] = {
1373 1389
  */
1374 1390
 static void dispatcher_rpc_reload(rpc_t *rpc, void *ctx)
1375 1391
 {
1392
+
1393
+	if(ds_rpc_reload_time==NULL) {
1394
+		LM_ERR("not ready for reload\n");
1395
+		rpc->fault(ctx, 500, "Not ready for reload");
1396
+		return;
1397
+	}
1398
+	if(*ds_rpc_reload_time!=0 && *ds_rpc_reload_time > time(NULL) - ds_reload_delta) {
1399
+		LM_ERR("ongoing reload\n");
1400
+		rpc->fault(ctx, 500, "Ongoing reload");
1401
+		return;
1402
+	}
1403
+	*ds_rpc_reload_time = time(NULL);
1404
+
1376 1405
 	if(!ds_db_url.s) {
1377 1406
 		if(ds_load_list(dslistfile) != 0) {
1378 1407
 			rpc->fault(ctx, 500, "Reload Failed");