Skip to content

Commit

Permalink
legion join hook
Browse files Browse the repository at this point in the history
  • Loading branch information
prymitive committed Mar 29, 2013
1 parent 527d371 commit c343ca0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
16 changes: 15 additions & 1 deletion core/legion.c
Expand Up @@ -203,7 +203,6 @@ static void legions_check_nodes() {


struct uwsgi_legion_node *node = legion->nodes_head; struct uwsgi_legion_node *node = legion->nodes_head;
while (node) { while (node) {

if (now - node->last_seen > uwsgi.legion_tolerance) { if (now - node->last_seen > uwsgi.legion_tolerance) {
struct uwsgi_legion_node *tmp_node = node; struct uwsgi_legion_node *tmp_node = node;
node = node->next; node = node->next;
Expand Down Expand Up @@ -302,6 +301,18 @@ static void legions_check_nodes_step2() {


// we have quorum !!! // we have quorum !!!
if (votes > 0 && votes >= ul->quorum) { if (votes > 0 && votes >= ul->quorum) {
if (!ul->joined) {
// triggering join hooks
struct uwsgi_string_list *usl = ul->join_hooks;
while (usl) {
int ret = uwsgi_legion_action_call("join", ul, usl);
if (ret) {
uwsgi_log("[uwsgi-legion] ERROR, join hook returned: %d\n", ret);
}
usl = usl->next;
}
ul->joined = 1;
}
// something changed ??? // something changed ???
if (ul->changed) { if (ul->changed) {
legions_report_quorum(ul, best_valor, best_uuid, votes); legions_report_quorum(ul, best_valor, best_uuid, votes);
Expand Down Expand Up @@ -852,6 +863,9 @@ void uwsgi_opt_legion_hook(char *opt, char *value, void *foobar) {
else if (!strcmp(opt, "legion-death")) { else if (!strcmp(opt, "legion-death")) {
usl = uwsgi_string_new_list(&ul->death_hooks, space + 1); usl = uwsgi_string_new_list(&ul->death_hooks, space + 1);
} }
else if (!strcmp(opt, "legion-join")) {
usl = uwsgi_string_new_list(&ul->join_hooks, space + 1);
}


if (!usl) if (!usl)
return; return;
Expand Down
1 change: 1 addition & 0 deletions core/uwsgi.c
Expand Up @@ -383,6 +383,7 @@ static struct uwsgi_option uwsgi_base_options[] = {
{"legion-unlord", required_argument, 0, "action to call on Lord dismiss", uwsgi_opt_legion_hook, NULL, UWSGI_OPT_MASTER}, {"legion-unlord", required_argument, 0, "action to call on Lord dismiss", uwsgi_opt_legion_hook, NULL, UWSGI_OPT_MASTER},
{"legion-setup", required_argument, 0, "action to call on legion setup", uwsgi_opt_legion_hook, NULL, UWSGI_OPT_MASTER}, {"legion-setup", required_argument, 0, "action to call on legion setup", uwsgi_opt_legion_hook, NULL, UWSGI_OPT_MASTER},
{"legion-death", required_argument, 0, "action to call on legion death (shutdown of the instance)", uwsgi_opt_legion_hook, NULL, UWSGI_OPT_MASTER}, {"legion-death", required_argument, 0, "action to call on legion death (shutdown of the instance)", uwsgi_opt_legion_hook, NULL, UWSGI_OPT_MASTER},
{"legion-join", required_argument, 0, "action to call on legion join (first time quorum is reached)", uwsgi_opt_legion_hook, NULL, UWSGI_OPT_MASTER},
{"legion-quorum", required_argument, 0, "set the quorum of a legion", uwsgi_opt_legion_quorum, NULL, UWSGI_OPT_MASTER}, {"legion-quorum", required_argument, 0, "set the quorum of a legion", uwsgi_opt_legion_quorum, NULL, UWSGI_OPT_MASTER},
{"legion-scroll", required_argument, 0, "set the scroll of a legion", uwsgi_opt_legion_scroll, NULL, UWSGI_OPT_MASTER}, {"legion-scroll", required_argument, 0, "set the scroll of a legion", uwsgi_opt_legion_scroll, NULL, UWSGI_OPT_MASTER},
{"legion-scroll-max-size", required_argument, 0, "set max size of legion scroll buffer", uwsgi_opt_set_16bit, &uwsgi.legion_scroll_max_size, 0}, {"legion-scroll-max-size", required_argument, 0, "set max size of legion scroll buffer", uwsgi_opt_set_16bit, &uwsgi.legion_scroll_max_size, 0},
Expand Down
4 changes: 4 additions & 0 deletions uwsgi.h
Expand Up @@ -597,6 +597,9 @@ struct uwsgi_legion_node {
int quorum; int quorum;
int changed; int changed;


// set to 1 first time when quorum is reached
int joined;

uint64_t checksum; uint64_t checksum;


char *scroll; char *scroll;
Expand Down Expand Up @@ -634,6 +637,7 @@ struct uwsgi_legion_node {
struct uwsgi_string_list *unlord_hooks; struct uwsgi_string_list *unlord_hooks;
struct uwsgi_string_list *setup_hooks; struct uwsgi_string_list *setup_hooks;
struct uwsgi_string_list *death_hooks; struct uwsgi_string_list *death_hooks;
struct uwsgi_string_list *join_hooks;
struct uwsgi_legion *next; struct uwsgi_legion *next;
}; };


Expand Down

0 comments on commit c343ca0

Please sign in to comment.