Skip to content

Commit

Permalink
htable: replicate the operation rm with sw
Browse files Browse the repository at this point in the history
- GH #2573
  • Loading branch information
miconda committed Dec 3, 2020
1 parent c0f5382 commit 53664ba
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/modules/htable/ht_dmq.c
Expand Up @@ -350,7 +350,9 @@ int ht_dmq_handle_msg(struct sip_msg* msg, peer_reponse_t* resp, dmq_node_t* dmq
return 0;
}

int ht_dmq_replicate_action(ht_dmq_action_t action, str* htname, str* cname, int type, int_str* val, int mode) {
int ht_dmq_replicate_action(ht_dmq_action_t action, str* htname, str* cname,
int type, int_str* val, int mode)
{

srjson_doc_t jdoc;

Expand All @@ -370,7 +372,8 @@ int ht_dmq_replicate_action(ht_dmq_action_t action, str* htname, str* cname, int
srjson_AddStrToObject(&jdoc, jdoc.root, "cname", cname->s, cname->len);
}

if (action==HT_DMQ_SET_CELL || action==HT_DMQ_SET_CELL_EXPIRE || action==HT_DMQ_RM_CELL_RE) {
if (action==HT_DMQ_SET_CELL || action==HT_DMQ_SET_CELL_EXPIRE
|| action==HT_DMQ_RM_CELL_RE || action==HT_DMQ_RM_CELL_SW) {
srjson_AddNumberToObject(&jdoc, jdoc.root, "type", type);
if (type&AVP_VAL_STR) {
srjson_AddStrToObject(&jdoc, jdoc.root, "strval", val->s.s, val->s.len);
Expand Down Expand Up @@ -407,7 +410,8 @@ int ht_dmq_replicate_action(ht_dmq_action_t action, str* htname, str* cname, int
return -1;
}

int ht_dmq_replay_action(ht_dmq_action_t action, str* htname, str* cname, int type, int_str* val, int mode) {
int ht_dmq_replay_action(ht_dmq_action_t action, str* htname, str* cname,
int type, int_str* val, int mode) {

ht_t* ht;
ht = ht_get_table(htname);
Expand All @@ -416,7 +420,8 @@ int ht_dmq_replay_action(ht_dmq_action_t action, str* htname, str* cname, int ty
return -1;
}

LM_DBG("replaying action %d on %.*s=>%.*s...\n", action, htname->len, htname->s, cname->len, cname->s);
LM_DBG("replaying action %d on %.*s=>%.*s...\n", action,
htname->len, htname->s, cname->len, cname->s);

if (action==HT_DMQ_SET_CELL) {
return ht_set_cell(ht, cname, type, val, mode);
Expand All @@ -426,6 +431,8 @@ int ht_dmq_replay_action(ht_dmq_action_t action, str* htname, str* cname, int ty
return ht_del_cell(ht, cname);
} else if (action==HT_DMQ_RM_CELL_RE) {
return ht_rm_cell_re(&val->s, ht, mode);
} else if (action==HT_DMQ_RM_CELL_SW) {
return ht_rm_cell_op(&val->s, ht, mode, HT_RM_OP_SW);
} else {
LM_ERR("unrecognized action\n");
return -1;
Expand Down
3 changes: 2 additions & 1 deletion src/modules/htable/ht_dmq.h
Expand Up @@ -33,11 +33,12 @@ extern dmq_resp_cback_t ht_dmq_resp_callback;

typedef enum {
HT_DMQ_NONE,
HT_DMQ_SYNC,
HT_DMQ_SET_CELL,
HT_DMQ_SET_CELL_EXPIRE,
HT_DMQ_DEL_CELL,
HT_DMQ_RM_CELL_RE,
HT_DMQ_SYNC
HT_DMQ_RM_CELL_SW
} ht_dmq_action_t;

int ht_dmq_initialize();
Expand Down
4 changes: 4 additions & 0 deletions src/modules/htable/htable.c
Expand Up @@ -493,6 +493,10 @@ static int ht_rm_items(sip_msg_t* msg, str* hname, str* op, str *val,
}
return 1;
} else if(strncmp(op->s, "sw", 2)==0) {
if (ht_dmq_replicate_action(HT_DMQ_RM_CELL_SW, &ht->name, NULL,
AVP_VAL_STR, &isval, mkey)!=0) {
LM_ERR("dmq relication failed (op %d)\n", mkey);
}
if(ht_rm_cell_op(val, ht, mkey, HT_RM_OP_SW)<0) {
return -1;
}
Expand Down

0 comments on commit 53664ba

Please sign in to comment.