Skip to content

Commit 57b28d8

Browse files
committed
dialog: do not replicate value if already received replicated
1 parent fd19fba commit 57b28d8

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed

modules/dialog/dlg_replication.c

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ str shtag_dlg_val = str_init("dlgX_shtag");
4848
char *dlg_sync_in_progress;
4949

5050
static int get_shtag_sync_status(struct dlg_cell *dlg);
51+
/*
52+
* indicates whether the dialog is in the process of receiving a replicated
53+
* dialog (update) - used to avoid cross-replicating the same value
54+
*/
55+
static int dlg_event_is_replicated = 0;
5156

5257
const static struct socket_info * fetch_socket_info(str *addr)
5358
{
@@ -744,10 +749,16 @@ int dlg_replicated_value(bin_packet_t *packet)
744749
DLG_BIN_POP(int, packet, h_id, malformed);
745750
DLG_BIN_POP(str, packet, name, malformed);
746751
DLG_BIN_POP(int, packet, type, malformed);
747-
if (type == DLG_VAL_TYPE_STR)
748-
DLG_BIN_POP(str, packet, val.s, malformed);
749-
else
750-
DLG_BIN_POP(int, packet, val.n, malformed);
752+
switch (type) {
753+
case DLG_VAL_TYPE_STR:
754+
DLG_BIN_POP(str, packet, val.s, malformed);
755+
break;
756+
case DLG_VAL_TYPE_INT:
757+
DLG_BIN_POP(int, packet, val.n, malformed);
758+
break;
759+
default:
760+
break;
761+
}
751762

752763
LM_DBG("Updating cseq for dialog with callid: %.*s\n", call_id.len, call_id.s);
753764
h_entry = dlg_hash(&call_id);
@@ -1045,6 +1056,9 @@ void replicate_dialog_value(struct dlg_cell *dlg, str *name, int_str *val, int t
10451056
{
10461057
bin_packet_t packet;
10471058

1059+
if (dlg_event_is_replicated)
1060+
return;
1061+
10481062
if (bin_init(&packet, &dlg_repl_cap, REPLICATION_DLG_VALUE,
10491063
BIN_VERSION, 512) != 0)
10501064
goto error;
@@ -1053,10 +1067,18 @@ void replicate_dialog_value(struct dlg_cell *dlg, str *name, int_str *val, int t
10531067
bin_push_int(&packet, dlg->h_id);
10541068
bin_push_str(&packet, name);
10551069
bin_push_int(&packet, type);
1056-
if (type == DLG_VAL_TYPE_STR)
1057-
bin_push_str(&packet, &val->s);
1058-
else
1059-
bin_push_int(&packet, val->n);
1070+
if (!val)
1071+
type = DLG_VAL_TYPE_NONE;
1072+
switch (type) {
1073+
case DLG_VAL_TYPE_STR:
1074+
bin_push_str(&packet, &val->s);
1075+
break;
1076+
case DLG_VAL_TYPE_INT:
1077+
bin_push_int(&packet, val->n);
1078+
break;
1079+
default:
1080+
break;
1081+
}
10601082

10611083
DLG_CLUSTER_SEND(packet, dialog_repl_cluster, error_free);
10621084

@@ -1081,41 +1103,48 @@ void receive_dlg_repl(bin_packet_t *pkt)
10811103
if (ver != DLG_BIN_V3)
10821104
ensure_bin_version(pkt, BIN_VERSION);
10831105

1106+
dlg_event_is_replicated = 1;
10841107
rc = dlg_replicated_create(pkt, NULL, NULL, NULL, 0, 0, 0);
10851108
if_update_stat(dlg_enable_stats, create_recv, 1);
10861109
break;
10871110
case REPLICATION_DLG_UPDATED:
10881111
if (ver != DLG_BIN_V3)
10891112
ensure_bin_version(pkt, BIN_VERSION);
10901113

1114+
dlg_event_is_replicated = 1;
10911115
rc = dlg_replicated_update(pkt);
10921116
if_update_stat(dlg_enable_stats, update_recv, 1);
10931117
break;
10941118
case REPLICATION_DLG_DELETED:
10951119
if (ver != DLG_BIN_V3)
10961120
ensure_bin_version(pkt, BIN_VERSION);
10971121

1122+
dlg_event_is_replicated = 1;
10981123
rc = dlg_replicated_delete(pkt);
10991124
if_update_stat(dlg_enable_stats, delete_recv, 1);
11001125
break;
11011126
case REPLICATION_DLG_CSEQ:
11021127
if (ver != DLG_BIN_V3)
11031128
ensure_bin_version(pkt, BIN_VERSION);
11041129

1130+
dlg_event_is_replicated = 1;
11051131
rc = dlg_replicated_cseq_updated(pkt);
11061132
break;
11071133
case REPLICATION_DLG_VALUE:
11081134
ensure_bin_version(pkt, BIN_VERSION);
11091135

1136+
dlg_event_is_replicated = 1;
11101137
rc = dlg_replicated_value(pkt);
11111138
break;
11121139
case SYNC_PACKET_TYPE:
11131140
if (ver != DLG_BIN_V3)
11141141
ensure_bin_version(pkt, BIN_VERSION);
11151142

1143+
dlg_event_is_replicated = 1;
11161144
while (clusterer_api.sync_chunk_iter(pkt))
11171145
if (dlg_replicated_create(pkt, NULL, NULL, NULL, 0, 0, 1) < 0) {
11181146
LM_ERR("Failed to process sync packet\n");
1147+
dlg_event_is_replicated = 0;
11191148
return;
11201149
}
11211150
break;
@@ -1128,6 +1157,7 @@ void receive_dlg_repl(bin_packet_t *pkt)
11281157

11291158
if (rc != 0)
11301159
LM_ERR("Failed to process a binary packet!\n");
1160+
dlg_event_is_replicated = 0;
11311161
}
11321162

11331163
static int receive_sync_request(int node_id)

0 commit comments

Comments
 (0)