Skip to content

Commit

Permalink
dialog: don't update DB when replication tag is backup
Browse files Browse the repository at this point in the history
  • Loading branch information
rvlad-patrascu committed Mar 27, 2018
1 parent fab7633 commit 9372447
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 18 deletions.
18 changes: 11 additions & 7 deletions modules/dialog/dialog.c
Expand Up @@ -1015,6 +1015,11 @@ static void mod_destroy(void)
{
struct dlg_repl_tag *tag, *tag_tmp;

if (dlg_db_mode != DB_MODE_NONE) {
dialog_update_db(0, 0/*do not do locking*/);
destroy_dlg_db();
}

if (repltags_list) {
if (*repltags_list) {
for (tag = *repltags_list; tag; ) {
Expand All @@ -1032,10 +1037,6 @@ static void mod_destroy(void)
repltags_lock = NULL;
}

if (dlg_db_mode != DB_MODE_NONE) {
dialog_update_db(0, 0/*do not do locking*/);
destroy_dlg_db();
}
/* no DB interaction from now on */
dlg_db_mode = DB_MODE_NONE;
destroy_dlg_table();
Expand Down Expand Up @@ -1889,6 +1890,7 @@ int pv_set_dlg_timeout(struct sip_msg *msg, pv_param_t *param,
{
struct dlg_cell *dlg;
int timeout, db_update = 0, timer_update = 0;
int do_actions = 1;

if (val==NULL || val->flags & PV_VAL_NULL) {
LM_ERR("cannot assign dialog timeout to NULL\n");
Expand Down Expand Up @@ -1924,10 +1926,12 @@ int pv_set_dlg_timeout(struct sip_msg *msg, pv_param_t *param,

dlg_unlock_dlg(dlg);

if (db_update)
update_dialog_timeout_info(dlg);
if (dialog_repl_cluster)
do_actions = get_repltag_state(dlg) != REPLTAG_STATE_BACKUP;

if (dialog_repl_cluster && get_repltag_state(dlg) != REPLTAG_STATE_BACKUP)
if (do_actions && db_update)
update_dialog_timeout_info(dlg);
if (dialog_repl_cluster && do_actions)
replicate_dialog_updated(dlg);

if (timer_update) {
Expand Down
18 changes: 17 additions & 1 deletion modules/dialog/dlg_db_handler.c
Expand Up @@ -42,6 +42,7 @@
#include "dlg_db_handler.h"
#include "dlg_cb.h"
#include "dlg_profile.h"
#include "dlg_replication.h"

str dlg_id_column = str_init(DLG_ID_COL);
str call_id_column = str_init(CALL_ID_COL);
Expand Down Expand Up @@ -1321,7 +1322,22 @@ void dialog_update_db(unsigned int ticks, void *do_lock)
if (do_lock)
dlg_lock( d_table, entry);

for(cell = entry->first; cell != NULL;){
for (cell = entry->first; cell != NULL; ) {
if (dialog_repl_cluster &&
get_repltag_state(cell) == REPLTAG_STATE_BACKUP) {
next_cell = cell->next;
if ((cell->flags & DLG_FLAG_NEW) != 0 &&
cell->state == DLG_STATE_DELETED &&
!(cell->flags & DLG_FLAG_DB_DELETED)) {
/* mark it as deleted so as we don't deal with it later */
cell->flags |= DLG_FLAG_DB_DELETED;
/* timer is done with this dialog */
unref_dlg_unsafe(cell,1,entry);
}
cell = next_cell;
continue;
}

callee_leg = callee_idx(cell);

if( (cell->flags & DLG_FLAG_NEW) != 0 ) {
Expand Down
19 changes: 10 additions & 9 deletions modules/dialog/dlg_handlers.c
Expand Up @@ -431,13 +431,14 @@ static void dlg_onreply(struct cell* t, int type, struct tmcb_params *param)
str mangled_from = {0,0};
str mangled_to = {0,0};
str *req_out_buff;
int replicate_events = 1;
int do_actions = 1;

dlg = (struct dlg_cell *)(*param->param);
if (shutdown_done || dlg==0)
return;

replicate_events = get_repltag_state(dlg) != REPLTAG_STATE_BACKUP;
if (dialog_repl_cluster)
do_actions = get_repltag_state(dlg) != REPLTAG_STATE_BACKUP;

rpl = param->rpl;
req = param->req;
Expand Down Expand Up @@ -486,7 +487,7 @@ static void dlg_onreply(struct cell* t, int type, struct tmcb_params *param)
}
if (type==TMCB_RESPONSE_OUT) {
if (dlg->state == DLG_STATE_CONFIRMED_NA && dialog_repl_cluster &&
replicate_events && param->code >= 200 && param->code < 300)
do_actions && param->code >= 200 && param->code < 300)
replicate_dialog_created(dlg);
return;
}
Expand All @@ -505,7 +506,7 @@ static void dlg_onreply(struct cell* t, int type, struct tmcb_params *param)
}

next_state_dlg(dlg, event, DLG_DIR_UPSTREAM, &old_state, &new_state,
&unref, DLG_CALLER_LEG, replicate_events);
&unref, DLG_CALLER_LEG, do_actions);

if (new_state==DLG_STATE_EARLY && old_state!=DLG_STATE_EARLY) {
run_dlg_callbacks(DLGCB_EARLY, dlg, rpl, DLG_DIR_UPSTREAM, NULL, 0);
Expand Down Expand Up @@ -538,7 +539,7 @@ static void dlg_onreply(struct cell* t, int type, struct tmcb_params *param)
* if realtime saving mode configured- save dialog now
* else: the next time the timer will fire the update*/
dlg->flags |= DLG_FLAG_NEW;
if ( dlg_db_mode==DB_MODE_REALTIME )
if (do_actions && dlg_db_mode == DB_MODE_REALTIME)
update_dialog_dbinfo(dlg);

/* dialog confirmed */
Expand Down Expand Up @@ -1631,7 +1632,7 @@ void dlg_onroute(struct sip_msg* req, str *route_params, void *param)
run_dlg_callbacks( DLGCB_TERMINATED, dlg, req, dir, NULL, 0);

/* delete the dialog from DB */
if (should_remove_dlg_db())
if (is_active && should_remove_dlg_db())
remove_dialog_from_db(dlg);

/* destroy dialog */
Expand Down Expand Up @@ -1750,7 +1751,7 @@ void dlg_onroute(struct sip_msg* req, str *route_params, void *param)

if (ok) {
dlg->flags |= DLG_FLAG_CHANGED;
if ( dlg_db_mode==DB_MODE_REALTIME )
if (is_active && dlg_db_mode==DB_MODE_REALTIME )
update_dialog_dbinfo(dlg);

if (dialog_repl_cluster && is_active)
Expand Down Expand Up @@ -1863,7 +1864,7 @@ void dlg_onroute(struct sip_msg* req, str *route_params, void *param)

if(new_state==DLG_STATE_CONFIRMED && old_state==DLG_STATE_CONFIRMED_NA){
dlg->flags |= DLG_FLAG_CHANGED;
if(dlg_db_mode == DB_MODE_REALTIME)
if (is_active && dlg_db_mode == DB_MODE_REALTIME)
update_dialog_dbinfo(dlg);

if (dialog_repl_cluster && is_active)
Expand Down Expand Up @@ -1986,7 +1987,7 @@ void dlg_ontimeout(struct dlg_tl *tl)
}

/* delete the dialog from DB */
if (should_remove_dlg_db())
if (do_expire_actions && should_remove_dlg_db())
remove_dialog_from_db(dlg);

unref_dlg(dlg, unref + 1 /*timer list*/);
Expand Down
2 changes: 1 addition & 1 deletion modules/dialog/dlg_req_within.c
Expand Up @@ -294,7 +294,7 @@ static void dual_bye_event(struct dlg_cell* dlg, struct sip_msg *req,
/* trash the dialog from DB and memory */
LM_DBG("second final reply\n");
/* delete the dialog from DB */
if (should_remove_dlg_db())
if (is_active && should_remove_dlg_db())
remove_dialog_from_db(dlg);
/* force delete from mem */
unref_dlg(dlg, unref);
Expand Down

0 comments on commit 9372447

Please sign in to comment.