Skip to content

Commit

Permalink
clusterer: fix loss of capabilities when doing clusterer_reload
Browse files Browse the repository at this point in the history
  • Loading branch information
rvlad-patrascu committed Jan 29, 2019
1 parent 2edf188 commit 0dc0ee5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
39 changes: 39 additions & 0 deletions modules/clusterer/clusterer.c
Expand Up @@ -2693,6 +2693,9 @@ int cl_register_cap(str *cap, cl_packet_cb_f packet_cb, cl_event_cb_f event_cb,
new_cl_cap->reg.packet_cb = packet_cb;
new_cl_cap->reg.event_cb = event_cb;

if (require_sync)
new_cl_cap->flags |= CAP_REQUIRE_SYNC;

if (cluster->current_node->flags & NODE_IS_SEED || !require_sync)
new_cl_cap->flags |= CAP_STATE_OK;

Expand All @@ -2706,6 +2709,42 @@ int cl_register_cap(str *cap, cl_packet_cb_f packet_cb, cl_event_cb_f event_cb,
return 0;
}

void preserve_reg_caps(cluster_info_t *new_info)
{
cluster_info_t *cl, *new_cl;
struct local_cap *cap;
struct buf_bin_pkt *buf_pkt, *tmp;

for (cl = *cluster_list; cl; cl = cl->next)
for (new_cl = new_info; new_cl; new_cl = new_cl->next)
if (new_cl->cluster_id == cl->cluster_id && cl->capabilities) {
new_cl->capabilities = cl->capabilities;

for (cap = new_cl->capabilities; cap; cap = cap->next) {
if (cap->flags & CAP_STATE_OK)
cap->flags &= ~CAP_STATE_OK;

if (new_cl->current_node->flags & NODE_IS_SEED ||
!(cap->flags & CAP_REQUIRE_SYNC))
cap->flags |= CAP_STATE_OK;

if (cap->flags & CAP_PKT_BUFFERING) {
cap->flags &= ~CAP_PKT_BUFFERING;

buf_pkt = cap->pkt_q_front;
while (buf_pkt) {
tmp = buf_pkt;
buf_pkt = buf_pkt->next;
shm_free(tmp->buf.s);
shm_free(tmp);
}
cap->pkt_q_front = NULL;
cap->pkt_q_back = NULL;
}
}
}
}

int gen_rcv_evs_init(void)
{
/* publish the events */
Expand Down
3 changes: 3 additions & 0 deletions modules/clusterer/clusterer.h
Expand Up @@ -51,6 +51,7 @@
#define CAP_STATE_OK (1<<0)
#define CAP_SYNC_PENDING (1<<1)
#define CAP_PKT_BUFFERING (1<<2)
#define CAP_REQUIRE_SYNC (1<<3)


typedef enum { CLUSTERER_PING, CLUSTERER_PONG,
Expand Down Expand Up @@ -158,6 +159,8 @@ cl_send_all_having(bin_packet_t *packet, int dst_cluster_id,
int cl_register_cap(str *cap, cl_packet_cb_f packet_cb, cl_event_cb_f event_cb,
int cluster_id, int require_sync, enum cl_node_match_op sync_cond);

void preserve_reg_caps(struct cluster_info *new_info);

struct mi_root *run_rcv_mi_cmd(str *cmd_name, str *cmd_params, int nr_params);

#endif /* CLUSTERER_H */
1 change: 1 addition & 0 deletions modules/clusterer/clusterer_mod.c
Expand Up @@ -456,6 +456,7 @@ static struct mi_root* clusterer_reload(struct mi_root* root, void *param)
}

lock_start_write(cl_list_lock);
preserve_reg_caps(new_info);
old_info = *cluster_list;
*cluster_list = new_info;
lock_stop_write(cl_list_lock);
Expand Down

0 comments on commit 0dc0ee5

Please sign in to comment.