From: Liu Yuan <tailai.ly at taobao.com> And in passing fix one minor status check logic in update_cluster_info() for newly joined node. Signed-off-by: Liu Yuan <tailai.ly at taobao.com> --- sheep/group.c | 65 +++++++++++++++++++++++++++----------------------------- 1 files changed, 31 insertions(+), 34 deletions(-) diff --git a/sheep/group.c b/sheep/group.c index 401dfcb..a03f709 100644 --- a/sheep/group.c +++ b/sheep/group.c @@ -294,6 +294,7 @@ void cluster_queue_request(struct work *work, int idx) struct vdi_op_message *msg; struct epoch_log *log; int ret = SD_RES_SUCCESS, i, max_logs, epoch; + uint32_t sys_stat = sys_stat_get(); eprintf("%p %x\n", req, hdr->opcode); @@ -329,7 +330,7 @@ void cluster_queue_request(struct work *work, int idx) epoch--; } - switch (sys->status) { + switch (sys_stat) { case SD_STATUS_OK: ret = SD_RES_SUCCESS; break; @@ -545,8 +546,7 @@ static int cluster_sanity_check(struct sheepdog_node_list_entry *entries, struct sheepdog_node_list_entry local_entries[SD_MAX_NODES]; uint32_t lepoch; - if (sys->status == SD_STATUS_WAIT_FOR_FORMAT || - sys->status == SD_STATUS_SHUTDOWN) + if (sys_stat_wait_format() || sys_stat_shutdown()) goto out; /* When the joinning node is newly created, we need to check nothing. */ if (nr_entries == 0) @@ -563,7 +563,7 @@ static int cluster_sanity_check(struct sheepdog_node_list_entry *entries, goto out; } - if (sys->status == SD_STATUS_OK || sys->status == SD_STATUS_HALT) + if (sys_can_recover()) goto out; if (epoch < lepoch) { @@ -594,8 +594,9 @@ static int get_cluster_status(struct sheepdog_node_list_entry *from, struct sheepdog_node_list_entry local_entries[SD_MAX_NODES]; struct node *node; char str[256]; + uint32_t sys_stat = sys_stat_get(); - *status = sys->status; + *status = sys_stat; if (inc_epoch) *inc_epoch = 0; @@ -603,7 +604,7 @@ static int get_cluster_status(struct sheepdog_node_list_entry *from, if (ret) goto out; - switch (sys->status) { + switch (sys_stat) { case SD_STATUS_HALT: case SD_STATUS_OK: if (inc_epoch) @@ -803,7 +804,7 @@ static void update_cluster_info(struct join_message *msg) return; } - if (sys->status == SD_STATUS_JOIN_FAILED) + if (sys_stat_join_failed()) return; if (sys->join_finished) @@ -851,9 +852,8 @@ join_finished: update_epoch_log(sys->epoch); update_epoch_store(sys->epoch); } - - if (sys->status != SD_STATUS_OK || - sys->status != SD_STATUS_HALT) { + /* Fresh node */ + if (!sys_stat_ok() && !sys_stat_halt()) { set_global_nr_copies(sys->nr_sobjs); set_cluster_flags(sys->flags); set_cluster_ctime(msg->ctime); @@ -862,7 +862,7 @@ join_finished: print_node_list(&sys->sd_node_list); - sys->status = msg->cluster_status; + sys_stat_set(msg->cluster_status); return; } @@ -987,18 +987,18 @@ static void vdi_op_done(struct vdi_op_message *msg) set_cluster_flags(sys->flags); if (sys_flag_nohalt()) - sys->status = SD_STATUS_OK; + sys_stat_set(SD_STATUS_OK); else { int nr_zones = get_zones_nr_from(&sys->sd_node_list); if (nr_zones >= sys->nr_sobjs) - sys->status = SD_STATUS_OK; + sys_stat_set(SD_STATUS_OK); else - sys->status = SD_STATUS_HALT; + sys_stat_set(SD_STATUS_HALT); } break; case SD_OP_SHUTDOWN: - sys->status = SD_STATUS_SHUTDOWN; + sys_stat_set(SD_STATUS_SHUTDOWN); break; default: eprintf("unknown operation %d\n", hdr->opcode); @@ -1067,7 +1067,7 @@ static void __sd_notify(struct cpg_event *cevent) switch (m->op) { case SD_MSG_JOIN: if (((struct join_message *)m)->cluster_status == SD_STATUS_OK) - if (sys->status != SD_STATUS_OK) { + if (!sys_stat_ok()) { struct join_message *msg = (struct join_message *)m; int i; @@ -1152,7 +1152,7 @@ static void __sd_notify_done(struct cpg_event *cevent) list_del(&node->list); free(node); - if (sys->status == SD_STATUS_OK) { + if (sys_stat_ok()) { sys->epoch++; update_epoch_log(sys->epoch); update_epoch_store(sys->epoch); @@ -1160,7 +1160,7 @@ static void __sd_notify_done(struct cpg_event *cevent) } /* fall through */ case SD_MSG_MASTER_TRANSFER: - if (sys->status == SD_STATUS_WAIT_FOR_JOIN) { + if (sys_stat_wait_join()) { add_node_to_leave_list(m); /* Sheep needs this to identify itself as master. @@ -1178,7 +1178,7 @@ static void __sd_notify_done(struct cpg_event *cevent) dprintf("%d == %d + %d \n", nr_local, nr, nr_leave); if (nr_local == nr + nr_leave) { - sys->status = SD_STATUS_OK; + sys_stat_set(SD_STATUS_OK); update_epoch_log(sys->epoch); update_epoch_store(sys->epoch); } @@ -1215,19 +1215,18 @@ static void __sd_notify_done(struct cpg_event *cevent) } } - if (do_recovery && - (sys->status == SD_STATUS_OK || sys->status == SD_STATUS_HALT)) { + if (do_recovery && sys_can_recover()) { list_for_each_entry_safe(node, t, &sys->leave_list, list) { list_del(&node->list); } start_recovery(sys->epoch); } - if (sys->status == SD_STATUS_HALT) { + if (sys_stat_halt()) { int nr_zones = get_zones_nr_from(&sys->sd_node_list); if (nr_zones >= sys->nr_sobjs) - sys->status = SD_STATUS_OK; + sys_stat_set(SD_STATUS_OK); } } @@ -1295,8 +1294,7 @@ static int del_node(struct sheepid *id) list_del(&node->list); free(node); - if (sys->status == SD_STATUS_OK || - sys->status == SD_STATUS_HALT) { + if (sys_can_recover()) { nr = get_ordered_sd_node_list(e); dprintf("update epoch, %d, %d\n", sys->epoch + 1, nr); epoch_log_write(sys->epoch + 1, (char *)e, @@ -1447,7 +1445,7 @@ static void __sd_join_done(struct cpg_event *cevent) update_cluster_info(&msg); - if (sys->status == SD_STATUS_OK) /* sheepdog starts with one node */ + if (sys_stat_ok()) /* sheepdog starts with one node */ start_recovery(sys->epoch); return; @@ -1468,15 +1466,14 @@ static void __sd_leave_done(struct cpg_event *cevent) print_node_list(&sys->sd_node_list); - if (node_left && - (sys->status == SD_STATUS_OK || sys->status == SD_STATUS_HALT)) + if (node_left && sys_can_recover()) start_recovery(sys->epoch); - if (sys->status == SD_STATUS_OK && !sys_flag_nohalt()) { + if (sys_can_halt()) { int nr_zones = get_zones_nr_from(&sys->sd_node_list); if (nr_zones < sys->nr_sobjs) - sys->status = SD_STATUS_HALT; + sys_stat_set(SD_STATUS_HALT); } } @@ -1860,7 +1857,7 @@ static void sd_join_handler(struct sheepid *joined, struct sheepid *members, for (i = 0; i < nr_members; i++) dprintf("[%x] %s\n", i, sheepid_to_str(members + i)); - if (sys->status == SD_STATUS_SHUTDOWN) + if (sys_stat_shutdown()) return; w = zalloc(sizeof(*w)); @@ -1906,7 +1903,7 @@ static void sd_leave_handler(struct sheepid *left, struct sheepid *members, for (i = 0; i < nr_members; i++) dprintf("[%x] %s\n", i, sheepid_to_str(members + i)); - if (sys->status == SD_STATUS_SHUTDOWN) + if (sys_stat_shutdown()) return; w = zalloc(sizeof(*w)); @@ -1982,9 +1979,9 @@ int create_cluster(int port, int64_t zone) dprintf("zone id = %u\n", sys->this_node.zone); if (get_latest_epoch() == 0) - sys->status = SD_STATUS_WAIT_FOR_FORMAT; + sys_stat_set(SD_STATUS_WAIT_FOR_FORMAT); else - sys->status = SD_STATUS_WAIT_FOR_JOIN; + sys_stat_set(SD_STATUS_WAIT_FOR_JOIN); INIT_LIST_HEAD(&sys->sd_node_list); INIT_LIST_HEAD(&sys->cpg_node_list); INIT_LIST_HEAD(&sys->pending_list); -- 1.7.6.1 |