diff options
author | David Teigland <teigland@redhat.com> | 2009-07-13 11:18:48 -0500 |
---|---|---|
committer | David Teigland <teigland@redhat.com> | 2009-07-13 11:18:48 -0500 |
commit | 9f1da99bd27429b7dbd8f94598903416b8eb0301 (patch) | |
tree | 54085b2f91c50a709bb404a8a69a990adac7f597 | |
parent | 0324c229024270c1dce85d15b0e62ad2b9da637f (diff) | |
download | dct-stuff-9f1da99bd27429b7dbd8f94598903416b8eb0301.tar.gz dct-stuff-9f1da99bd27429b7dbd8f94598903416b8eb0301.tar.xz dct-stuff-9f1da99bd27429b7dbd8f94598903416b8eb0301.zip |
cpgx: fix sync
the synced_nodes and sync_from weren't accounting for nodes that had
been removed. Problems here found by Honza.
Signed-off-by: David Teigland <teigland@redhat.com>
-rw-r--r-- | cpgx/cpgx.c | 67 |
1 files changed, 45 insertions, 22 deletions
diff --git a/cpgx/cpgx.c b/cpgx/cpgx.c index 12c824e..dd8c12a 100644 --- a/cpgx/cpgx.c +++ b/cpgx/cpgx.c @@ -237,10 +237,14 @@ static void _log_config(struct dct_config *c, uint32_t id, int error) for (i = 0; i < c->left_count; i++) off += sprintf(l_buf+off, " %u", c->left[i]); - if (error) + if (error == 1) log_error("%08u conf %u %u %u memb%s join%s left%s", id, c->memb_count, c->join_count, c->left_count, m_buf, j_buf, l_buf); + else if (error == 2) + log_debug("%08u conf %u %u %u memb%s join%s left%s", + id, c->memb_count, c->join_count, c->left_count, + m_buf, j_buf, l_buf); else log_history("%08u conf %u %u %u memb%s join%s left%s", id, c->memb_count, c->join_count, c->left_count, @@ -528,21 +532,6 @@ void update_nodes_list(struct dct_config *c, uint32_t id) uint8_t low = 0; int i, is_memb, is_join, is_left; - i = 0; - memset(&synced_nodes, 0, 8); - - list_for_each_entry(node, &nodes, list) { - if (!node->is_member) - continue; - if (node->needs_sync) - continue; - - synced_nodes[i++] = node->nodeid; - - if (!low || node->nodeid < low) - low = node->nodeid; - } - list_for_each_entry(node, &nodes, list) { is_memb = in_memb(c, node->nodeid); @@ -589,9 +578,7 @@ void update_nodes_list(struct dct_config *c, uint32_t id) node->is_member = 1; node->needs_sync = 1; - node->sync_from = low; node->join_eventid = id; - memcpy(&node->synced_nodes, &synced_nodes, 8); continue; } @@ -600,6 +587,36 @@ void update_nodes_list(struct dct_config *c, uint32_t id) node->is_member, node->nodeid); } + /* figure out who should send syncs and what synced_nodes are */ + + i = 0; + memset(&synced_nodes, 0, 8); + + list_for_each_entry(node, &nodes, list) { + if (!node->is_member) + continue; + if (node->needs_sync) + continue; + + synced_nodes[i++] = node->nodeid; + + if (!low || node->nodeid < low) + low = node->nodeid; + } + + if (!low) + log_error("update_nodes_list no synced nodeid"); + + /* old nodes that have joined again */ + + list_for_each_entry(node, &nodes, list) { + if (node->is_member && node->needs_sync && + node->join_eventid == id) { + node->sync_from = low; + memcpy(&node->synced_nodes, &synced_nodes, 8); + } + } + /* add new node we've not seen before */ for (i = 0; i < c->memb_count; i++) { @@ -610,15 +627,15 @@ void update_nodes_list(struct dct_config *c, uint32_t id) node = add_node(c->memb[i]); node->is_member = 1; node->needs_sync = 1; - node->sync_from = low; node->join_eventid = id; + node->sync_from = low; memcpy(&node->synced_nodes, &synced_nodes, 8); is_join = in_join(c, node->nodeid); if (!is_join) log_error("join list off %d", node->nodeid); } - + log_debug("update_nodes_list"); print_nodes_list(); } @@ -992,6 +1009,8 @@ void save_message(struct dct_header *hd, int len, int type) memcpy(&se->buf, hd, len); list_add_tail(&se->list, &saved_events); + + log_debug("save_message"); } void save_confchg(struct dct_config *c, int we_join) @@ -1013,6 +1032,9 @@ void save_confchg(struct dct_config *c, int we_join) memcpy(&se->buf, c, sizeof(struct dct_config)); list_add_tail(&se->list, &saved_events); + + log_debug("save_confchg"); + log_config(c, 2); } static int nodeid_compare(const void *va, const void *vb) @@ -1095,7 +1117,6 @@ static void confchg_cb(cpg_handle_t handle, const struct cpg_name *group_name, cpg_finalize(our_cpg_handle); client_dead(our_cpg_client); add_history_confchg(&c); - update_nodes_list(last_config, last_config_eventid); return; } @@ -1598,8 +1619,10 @@ void loop(void) } } - if (timeout_sec && (time(NULL) - last_dispatch > timeout_sec)) + if (timeout_sec && (time(NULL) - last_dispatch > timeout_sec)) { log_error("no cpg dispatch in %d sec", timeout_sec); + print_nodes_list(); + } if (got_error) { dump_write(); |