Skip to content

Commit e86b121

Browse files
committed
[dispatcher] fix resetting the persistent_state for default partition
The modparam (as per docs) must change the default partition settings only Fixes #3635, reported by @nikbyte
1 parent 0cad84b commit e86b121

1 file changed

Lines changed: 37 additions & 13 deletions

File tree

modules/dispatcher/dispatcher.c

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ static int mi_child_init(void);
221221

222222
static int set_partition_arguments(unsigned int type, void * val);
223223
static int set_probing_list(unsigned int type, void * val);
224+
static int set_df_persistent_state(unsigned int type, void * val);
224225

225226
static const cmd_export_t cmds[] = {
226227
{"ds_select_dst", (cmd_function)w_ds_select_dst, {
@@ -301,14 +302,14 @@ static const param_export_t params[]={
301302
{"weight_col", STR_PARAM, &ds_dest_weight_col.s},
302303
{"priority_col", STR_PARAM, &ds_dest_prio_col.s},
303304
{"attrs_col", STR_PARAM, &ds_dest_attrs_col.s},
304-
{"description_col", STR_PARAM, &ds_dest_description_col.s},
305-
{"probe_mode_col", STR_PARAM, &ds_dest_probe_mode_col.s},
305+
{"description_col", STR_PARAM, &ds_dest_description_col.s},
306+
{"probe_mode_col", STR_PARAM, &ds_dest_probe_mode_col.s},
306307
{"dst_avp", STR_PARAM, &default_db_head.dst_avp.s},
307308
{"grp_avp", STR_PARAM, &default_db_head.grp_avp.s},
308309
{"cnt_avp", STR_PARAM, &default_db_head.cnt_avp.s},
309310
{"sock_avp", STR_PARAM, &default_db_head.sock_avp.s},
310311
{"attrs_avp", STR_PARAM, &default_db_head.attrs_avp.s},
311-
{"script_attrs_avp", STR_PARAM, &default_db_head.script_attrs_avp.s},
312+
{"script_attrs_avp",STR_PARAM, &default_db_head.script_attrs_avp.s},
312313
{"algo_route", STR_PARAM, &algo_route_param.s},
313314
{"hash_pvar", STR_PARAM, &hash_pvar_param.s},
314315
{"setid_pvar", STR_PARAM, &ds_setid_pvname.s},
@@ -322,10 +323,12 @@ static const param_export_t params[]={
322323
{"ds_probing_mode", INT_PARAM, &ds_probing_mode},
323324
{"options_reply_codes", STR_PARAM, &options_reply_codes_str.s},
324325
{"ds_probing_sock", STR_PARAM, &probing_sock_s.s},
325-
{"ds_probing_list", STR_PARAM|USE_FUNC_PARAM, (void*)set_probing_list},
326+
{"ds_probing_list", STR_PARAM|USE_FUNC_PARAM,
327+
(void*)set_probing_list},
326328
{"ds_define_blacklist", STR_PARAM|USE_FUNC_PARAM, (void*)set_ds_bl},
327-
{"persistent_state", INT_PARAM, &ds_persistent_state},
328-
{"fetch_freeswitch_stats", INT_PARAM, &fetch_freeswitch_stats},
329+
{"persistent_state", INT_PARAM|USE_FUNC_PARAM,
330+
(void*)set_df_persistent_state},
331+
{"fetch_freeswitch_stats",INT_PARAM, &fetch_freeswitch_stats},
329332
{"max_freeswitch_weight", INT_PARAM, &max_freeswitch_weight},
330333
{"cluster_id", INT_PARAM, &ds_cluster_id },
331334
{"cluster_sharing_tag", STR_PARAM, &ds_cluster_shtag },
@@ -562,6 +565,21 @@ static int set_probing_list(unsigned int type, void *val) {
562565
}
563566

564567

568+
/* coverts the persistent state for the default partiton from int to str */
569+
static int set_df_persistent_state(unsigned int type, void * val)
570+
{
571+
if ( (int)(long)val == 0) {
572+
default_db_head.persistent_state.s = "0";
573+
default_db_head.persistent_state.len = 1;
574+
} else {
575+
default_db_head.persistent_state.s = "1";
576+
default_db_head.persistent_state.len = 1;
577+
}
578+
579+
return 0;
580+
}
581+
582+
565583
/* We parse the "partition" argument as: partition_name:arg1=val1; arg2=val2;*/
566584

567585
static int set_partition_arguments(unsigned int type, void *val)
@@ -643,6 +661,8 @@ static int set_partition_arguments(unsigned int type, void *val)
643661

644662
static int partition_init(ds_db_head_t *db_head, ds_partition_t *partition)
645663
{
664+
LM_DBG("initializing partition <%.*s>\n",
665+
db_head->partition_name.len, db_head->partition_name.s);
646666

647667
/* Load stuff from DB. URL cannot be null!*/
648668
if (db_head->db_url.s == NULL){
@@ -781,18 +801,18 @@ static int partition_init(ds_db_head_t *db_head, ds_partition_t *partition)
781801
}
782802
}
783803

784-
partition->persistent_state = ds_persistent_state;
785-
if (str_strcmp(&db_head->persistent_state, const_str("0")) == 0 ||
786-
str_strcmp(&db_head->persistent_state, const_str("no")) == 0 ||
787-
str_strcmp(&db_head->persistent_state, const_str("off")) == 0)
804+
if (str_strcmp(&db_head->persistent_state, const_str("0")) == 0 ||
805+
str_strcmp(&db_head->persistent_state, const_str("no")) == 0 ||
806+
str_strcmp(&db_head->persistent_state, const_str("off")) == 0)
788807
partition->persistent_state = 0;
789-
else if (str_strcmp(&db_head->persistent_state, const_str("1")) == 0 ||
790-
str_strcmp(&db_head->persistent_state, const_str("yes")) == 0 ||
791-
str_strcmp(&db_head->persistent_state, const_str("on")) == 0)
808+
else if (str_strcmp(&db_head->persistent_state, const_str("1")) == 0 ||
809+
str_strcmp(&db_head->persistent_state, const_str("yes")) == 0 ||
810+
str_strcmp(&db_head->persistent_state, const_str("on")) == 0)
792811
partition->persistent_state = 1;
793812

794813
if (partition->persistent_state)
795814
ds_persistent_state_enable = 1;
815+
796816
return 0;
797817
}
798818

@@ -1047,6 +1067,10 @@ static int mod_init(void)
10471067

10481068
}
10491069

1070+
LM_DBG("options are fetch_freeswitch_stats=%d, "
1071+
"ds_persistent_state_enable=%d\n",
1072+
fetch_freeswitch_stats, ds_persistent_state_enable);
1073+
10501074
/* Register the weight-recalculation timer */
10511075
if (fetch_freeswitch_stats &&
10521076
register_timer("ds-update-weights", ds_update_weights, NULL,

0 commit comments

Comments
 (0)