diff --git a/.gitignore b/.gitignore index e11cb5f1775..fc30c3a7291 100644 --- a/.gitignore +++ b/.gitignore @@ -34,4 +34,4 @@ core.* out log *.log -*.html +*.html \ No newline at end of file diff --git a/modules/dispatcher/dispatch.c b/modules/dispatcher/dispatch.c index 8faef9700b8..331e27c5e66 100644 --- a/modules/dispatcher/dispatch.c +++ b/modules/dispatcher/dispatch.c @@ -1178,7 +1178,7 @@ static ds_data_t* ds_load_data(ds_partition_t *partition, int use_state_col) } -int ds_reload_db(ds_partition_t *partition, int initial) +int ds_reload_db(ds_partition_t *partition, int initial, int is_inherit_state) { ds_data_t *old_data; ds_data_t *new_data; @@ -1214,7 +1214,10 @@ int ds_reload_db(ds_partition_t *partition, int initial) if (old_data) { /* copy the state of the destinations from the old set * (for the matching ids) */ - ds_inherit_state( old_data, new_data); + if (is_inherit_state == INHERIT_STATE_YES) { + ds_inherit_state( old_data, new_data); + } + ds_destroy_data_set( old_data ); } diff --git a/modules/dispatcher/dispatch.h b/modules/dispatcher/dispatch.h index 3c8a6194fd7..b5c9505187a 100644 --- a/modules/dispatcher/dispatch.h +++ b/modules/dispatcher/dispatch.h @@ -61,6 +61,10 @@ #define MI_FULL_LISTING (1<<0) +#define INHERIT_STATE_YES 1 +#define INHERIT_STATE_NO 0 + + extern int ds_persistent_state; typedef struct _ds_dest @@ -211,7 +215,7 @@ extern void *ds_srg; int init_ds_db(ds_partition_t *partition); int ds_connect_db(ds_partition_t *partition); void ds_disconnect_db(ds_partition_t *partition); -int ds_reload_db(ds_partition_t *partition, int initial); +int ds_reload_db(ds_partition_t *partition, int initial, int is_inherit_state); int init_ds_data(ds_partition_t *partition); void ds_destroy_data(ds_partition_t *partition); diff --git a/modules/dispatcher/dispatcher.c b/modules/dispatcher/dispatcher.c index d015550659a..59bebd66dc3 100644 --- a/modules/dispatcher/dispatcher.c +++ b/modules/dispatcher/dispatcher.c @@ -348,7 +348,9 @@ static const mi_export_t mi_cmds[] = { }, { "ds_reload", 0, 0, mi_child_init, { {ds_mi_reload, {0}}, + {ds_mi_reload, {"inherit_state", 0}}, {ds_mi_reload_1, {"partition", 0}}, + {ds_mi_reload_1, {"partition", "inherit_state", 0}}, {EMPTY_MI_RECIPE}} }, { "ds_push_script_attrs", 0, 0, 0, { @@ -908,7 +910,7 @@ static int mod_init(void) } /* do the actual data load */ - if (ds_reload_db(partition, 1)!=0) { + if (ds_reload_db(partition, 1, INHERIT_STATE_YES)!=0) { LM_ERR("failed to load data from DB\n"); return -1; } @@ -1371,9 +1373,26 @@ mi_response_t *ds_mi_reload(const mi_params_t *params, struct mi_handler *async_hdl) { ds_partition_t *part_it; + str inherit_state; + int is_inherit_state = INHERIT_STATE_YES; + + if (get_mi_string_param(params, "inherit_state", &inherit_state.s, &inherit_state.len) >= 0) { + LM_DBG("inherit_state is: %s \n", inherit_state.s); + + if (inherit_state.s[0] == '0' || inherit_state.s[0] == 'n' || inherit_state.s[0] == 'N') { + is_inherit_state = INHERIT_STATE_NO; + } + else if (inherit_state.s[0] == '1' || inherit_state.s[0] == 'y' || inherit_state.s[0] == 'Y') { + is_inherit_state = INHERIT_STATE_YES; + } else { + LM_WARN("inherit_state values was not recognized, ignored \n"); + } + } + + LM_DBG("is_inherit_state is: %d \n", is_inherit_state); for (part_it = partitions; part_it; part_it = part_it->next) - if (ds_reload_db(part_it, 0)<0) + if (ds_reload_db(part_it, 0, is_inherit_state)<0) return init_mi_error(500, MI_SSTR(MI_ERR_RELOAD)); if (ds_cluster_id && ds_cluster_sync() < 0) @@ -1387,15 +1406,32 @@ mi_response_t *ds_mi_reload_1(const mi_params_t *params, { ds_partition_t *partition; str partname; + str inherit_state; + int is_inherit_state = INHERIT_STATE_YES; if (get_mi_string_param(params, "partition", &partname.s, &partname.len) < 0) - return init_mi_param_error(); + return init_mi_param_error(); + + if (get_mi_string_param(params, "inherit_state", &inherit_state.s, &inherit_state.len) >= 0) { + LM_DBG("inherit_state is: %s \n", inherit_state.s); + + if (inherit_state.s[0] == '0' || inherit_state.s[0] == 'n' || inherit_state.s[0] == 'N') { + is_inherit_state = INHERIT_STATE_NO; + } + else if (inherit_state.s[0] == '1' || inherit_state.s[0] == 'y' || inherit_state.s[0] == 'Y') { + is_inherit_state = INHERIT_STATE_YES; + } else { + LM_WARN("inherit_state values was not recognized, ignored \n"); + } + } + + LM_DBG("is_inherit_state is: %d \n", is_inherit_state); partition = find_partition_by_name(&partname); if (partition == NULL) return init_mi_error(500, MI_SSTR(MI_UNK_PARTITION)); - if (ds_reload_db(partition, 0) < 0) + if (ds_reload_db(partition, 0, is_inherit_state) < 0) return init_mi_error(500, MI_SSTR(MI_ERR_RELOAD)); if (ds_cluster_id && ds_cluster_sync() < 0) diff --git a/modules/dispatcher/doc/dispatcher_admin.xml b/modules/dispatcher/doc/dispatcher_admin.xml index 1e0c16aaa4f..e23d30ec54d 100644 --- a/modules/dispatcher/doc/dispatcher_admin.xml +++ b/modules/dispatcher/doc/dispatcher_admin.xml @@ -1700,14 +1700,23 @@ opensips-cli -x mi ds_list partition (optional) - name of - the partition to be reloaded. + the partition to be reloaded. default partition is "default". + + inherit_state (optional) : whether inherit old state of the destination , default is y. + + n: no inherit state + y: inherit state + + + MI FIFO Command Format: opensips-cli -x mi ds_reload +opensips-cli -x mi ds_reload inherit_state=n @@ -1913,4 +1922,3 @@ opensips-cli -x mi ds_reload -