From c343ca0cc392e216e604aad3f1a394e7ed7ed973 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Fri, 29 Mar 2013 13:43:36 +0100 Subject: [PATCH] legion join hook --- core/legion.c | 16 +++++++++++++++- core/uwsgi.c | 1 + uwsgi.h | 4 ++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/core/legion.c b/core/legion.c index 698f8ae0..eabeb0c8 100644 --- a/core/legion.c +++ b/core/legion.c @@ -203,7 +203,6 @@ static void legions_check_nodes() { struct uwsgi_legion_node *node = legion->nodes_head; while (node) { - if (now - node->last_seen > uwsgi.legion_tolerance) { struct uwsgi_legion_node *tmp_node = node; node = node->next; @@ -302,6 +301,18 @@ static void legions_check_nodes_step2() { // we have 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 ??? if (ul->changed) { legions_report_quorum(ul, best_valor, best_uuid, votes); @@ -852,6 +863,9 @@ void uwsgi_opt_legion_hook(char *opt, char *value, void *foobar) { else if (!strcmp(opt, "legion-death")) { 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) return; diff --git a/core/uwsgi.c b/core/uwsgi.c index f18e4ed4..ffbaaf5c 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -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-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-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-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}, diff --git a/uwsgi.h b/uwsgi.h index 06ba2434..d167f8c6 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -597,6 +597,9 @@ struct uwsgi_legion_node { int quorum; int changed; + // set to 1 first time when quorum is reached + int joined; + uint64_t checksum; char *scroll; @@ -634,6 +637,7 @@ struct uwsgi_legion_node { struct uwsgi_string_list *unlord_hooks; struct uwsgi_string_list *setup_hooks; struct uwsgi_string_list *death_hooks; + struct uwsgi_string_list *join_hooks; struct uwsgi_legion *next; };