Skip to content

Commit c465148

Browse files
authored
Merge pull request #3076 from wangduanduan/ds_reload_1
feat: add inherit_state to ds_reload
2 parents 6617ecc + 4c61984 commit c465148

File tree

5 files changed

+61
-10
lines changed

5 files changed

+61
-10
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ core.*
3434
out
3535
log
3636
*.log
37-
*.html
37+
*.html

modules/dispatcher/dispatch.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,7 @@ static ds_data_t* ds_load_data(ds_partition_t *partition, int use_state_col)
11781178
}
11791179

11801180

1181-
int ds_reload_db(ds_partition_t *partition, int initial)
1181+
int ds_reload_db(ds_partition_t *partition, int initial, int is_inherit_state)
11821182
{
11831183
ds_data_t *old_data;
11841184
ds_data_t *new_data;
@@ -1214,7 +1214,10 @@ int ds_reload_db(ds_partition_t *partition, int initial)
12141214
if (old_data) {
12151215
/* copy the state of the destinations from the old set
12161216
* (for the matching ids) */
1217-
ds_inherit_state( old_data, new_data);
1217+
if (is_inherit_state == INHERIT_STATE_YES) {
1218+
ds_inherit_state( old_data, new_data);
1219+
}
1220+
12181221
ds_destroy_data_set( old_data );
12191222
}
12201223

modules/dispatcher/dispatch.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@
6161
#define MI_FULL_LISTING (1<<0)
6262

6363

64+
#define INHERIT_STATE_YES 1
65+
#define INHERIT_STATE_NO 0
66+
67+
6468
extern int ds_persistent_state;
6569

6670
typedef struct _ds_dest
@@ -211,7 +215,7 @@ extern void *ds_srg;
211215
int init_ds_db(ds_partition_t *partition);
212216
int ds_connect_db(ds_partition_t *partition);
213217
void ds_disconnect_db(ds_partition_t *partition);
214-
int ds_reload_db(ds_partition_t *partition, int initial);
218+
int ds_reload_db(ds_partition_t *partition, int initial, int is_inherit_state);
215219

216220
int init_ds_data(ds_partition_t *partition);
217221
void ds_destroy_data(ds_partition_t *partition);

modules/dispatcher/dispatcher.c

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,9 @@ static const mi_export_t mi_cmds[] = {
348348
},
349349
{ "ds_reload", 0, 0, mi_child_init, {
350350
{ds_mi_reload, {0}},
351+
{ds_mi_reload, {"inherit_state", 0}},
351352
{ds_mi_reload_1, {"partition", 0}},
353+
{ds_mi_reload_1, {"partition", "inherit_state", 0}},
352354
{EMPTY_MI_RECIPE}}
353355
},
354356
{ "ds_push_script_attrs", 0, 0, 0, {
@@ -908,7 +910,7 @@ static int mod_init(void)
908910
}
909911

910912
/* do the actual data load */
911-
if (ds_reload_db(partition, 1)!=0) {
913+
if (ds_reload_db(partition, 1, INHERIT_STATE_YES)!=0) {
912914
LM_ERR("failed to load data from DB\n");
913915
return -1;
914916
}
@@ -1371,9 +1373,26 @@ mi_response_t *ds_mi_reload(const mi_params_t *params,
13711373
struct mi_handler *async_hdl)
13721374
{
13731375
ds_partition_t *part_it;
1376+
str inherit_state;
1377+
int is_inherit_state = INHERIT_STATE_YES;
1378+
1379+
if (get_mi_string_param(params, "inherit_state", &inherit_state.s, &inherit_state.len) >= 0) {
1380+
LM_DBG("inherit_state is: %s \n", inherit_state.s);
1381+
1382+
if (inherit_state.s[0] == '0' || inherit_state.s[0] == 'n' || inherit_state.s[0] == 'N') {
1383+
is_inherit_state = INHERIT_STATE_NO;
1384+
}
1385+
else if (inherit_state.s[0] == '1' || inherit_state.s[0] == 'y' || inherit_state.s[0] == 'Y') {
1386+
is_inherit_state = INHERIT_STATE_YES;
1387+
} else {
1388+
LM_WARN("inherit_state values was not recognized, ignored \n");
1389+
}
1390+
}
1391+
1392+
LM_DBG("is_inherit_state is: %d \n", is_inherit_state);
13741393

13751394
for (part_it = partitions; part_it; part_it = part_it->next)
1376-
if (ds_reload_db(part_it, 0)<0)
1395+
if (ds_reload_db(part_it, 0, is_inherit_state)<0)
13771396
return init_mi_error(500, MI_SSTR(MI_ERR_RELOAD));
13781397

13791398
if (ds_cluster_id && ds_cluster_sync() < 0)
@@ -1387,15 +1406,32 @@ mi_response_t *ds_mi_reload_1(const mi_params_t *params,
13871406
{
13881407
ds_partition_t *partition;
13891408
str partname;
1409+
str inherit_state;
1410+
int is_inherit_state = INHERIT_STATE_YES;
13901411

13911412
if (get_mi_string_param(params, "partition", &partname.s, &partname.len) < 0)
1392-
return init_mi_param_error();
1413+
return init_mi_param_error();
1414+
1415+
if (get_mi_string_param(params, "inherit_state", &inherit_state.s, &inherit_state.len) >= 0) {
1416+
LM_DBG("inherit_state is: %s \n", inherit_state.s);
1417+
1418+
if (inherit_state.s[0] == '0' || inherit_state.s[0] == 'n' || inherit_state.s[0] == 'N') {
1419+
is_inherit_state = INHERIT_STATE_NO;
1420+
}
1421+
else if (inherit_state.s[0] == '1' || inherit_state.s[0] == 'y' || inherit_state.s[0] == 'Y') {
1422+
is_inherit_state = INHERIT_STATE_YES;
1423+
} else {
1424+
LM_WARN("inherit_state values was not recognized, ignored \n");
1425+
}
1426+
}
1427+
1428+
LM_DBG("is_inherit_state is: %d \n", is_inherit_state);
13931429

13941430
partition = find_partition_by_name(&partname);
13951431

13961432
if (partition == NULL)
13971433
return init_mi_error(500, MI_SSTR(MI_UNK_PARTITION));
1398-
if (ds_reload_db(partition, 0) < 0)
1434+
if (ds_reload_db(partition, 0, is_inherit_state) < 0)
13991435
return init_mi_error(500, MI_SSTR(MI_ERR_RELOAD));
14001436

14011437
if (ds_cluster_id && ds_cluster_sync() < 0)

modules/dispatcher/doc/dispatcher_admin.xml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,14 +1700,23 @@ opensips-cli -x mi ds_list
17001700
<itemizedlist>
17011701
<listitem><para>
17021702
<emphasis>partition</emphasis> (optional) - name of
1703-
the partition to be reloaded.
1703+
the partition to be reloaded. default partition is "default".
17041704
</para></listitem>
1705+
1706+
<listitem><para><emphasis>inherit_state</emphasis> (optional) : whether inherit old state of the destination , default is y. </para>
1707+
<itemizedlist>
1708+
<listitem><para> <quote>n</quote>: no inherit state </para></listitem>
1709+
<listitem><para> <quote>y</quote>: inherit state </para></listitem>
1710+
</itemizedlist>
1711+
</listitem>
1712+
17051713
</itemizedlist>
17061714
<para>
17071715
MI FIFO Command Format:
17081716
</para>
17091717
<programlisting format="linespecific">
17101718
opensips-cli -x mi ds_reload
1719+
opensips-cli -x mi ds_reload inherit_state=n
17111720
</programlisting>
17121721
</section>
17131722

@@ -1913,4 +1922,3 @@ opensips-cli -x mi ds_reload
19131922
</section>
19141923
</section>
19151924
</chapter>
1916-

0 commit comments

Comments
 (0)