From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> To: tarantool-patches@freelists.org Cc: kostja@tarantool.org Subject: [tarantool-patches] [PATCH 2/2] swim: expose ping broadcast API Date: Wed, 10 Apr 2019 20:45:34 +0300 [thread overview] Message-ID: <8a92b8b538213827ac0ae156263bc88974e320c3.1554918303.git.v.shpilevoy@tarantool.org> (raw) In-Reply-To: <cover.1554918303.git.v.shpilevoy@tarantool.org> In-Reply-To: <cover.1554918303.git.v.shpilevoy@tarantool.org> The previous commit has introduced an API to broadcast SWIM packets. This commit harnesses it in orider to allow user to do initial discovery in a cluster, when member tables are empty, and UUIDs aren't ready at hand. Part of #3234 --- src/lib/swim/swim.c | 13 +++++++++++++ src/lib/swim/swim.h | 7 +++++++ test/unit/swim.c | 34 +++++++++++++++++++++++++++++++++- test/unit/swim.result | 12 +++++++++++- 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/src/lib/swim/swim.c b/src/lib/swim/swim.c index c64b8df3a..db21f54c5 100644 --- a/src/lib/swim/swim.c +++ b/src/lib/swim/swim.c @@ -1526,6 +1526,19 @@ swim_probe_member(struct swim *swim, const char *uri) return 0; } +int +swim_broadcast(struct swim *swim, int port) +{ + assert(swim_is_configured(swim)); + if (port < 0) + port = ntohs(swim->self->addr.sin_port); + struct swim_bcast_task *t = swim_bcast_task_new(port, "broadcast ping"); + if (t == NULL) + return -1; + swim_send_ping(swim, &t->base, &t->base.dst); + return 0; +} + void swim_info(struct swim *swim, struct info_handler *info) { diff --git a/src/lib/swim/swim.h b/src/lib/swim/swim.h index f8dfdde87..60f5a8a1d 100644 --- a/src/lib/swim/swim.h +++ b/src/lib/swim/swim.h @@ -136,6 +136,13 @@ swim_remove_member(struct swim *swim, const struct tt_uuid *uuid); int swim_probe_member(struct swim *swim, const char *uri); +/** + * Broadcast a ping to all interfaces on a specified @a port. If + * @a port is < 0, then a port of the SWIM instance is used. + */ +int +swim_broadcast(struct swim *swim, int port); + /** Dump member statuses into @a info. */ void swim_info(struct swim *swim, struct info_handler *info); diff --git a/test/unit/swim.c b/test/unit/swim.c index 499b2ef52..736db4da1 100644 --- a/test/unit/swim.c +++ b/test/unit/swim.c @@ -33,6 +33,7 @@ #include "fiber.h" #include "uuid/tt_uuid.h" #include "unit.h" +#include "uri/uri.h" #include "swim/swim.h" #include "swim/swim_ev.h" #include "swim_test_transport.h" @@ -552,10 +553,40 @@ swim_test_quit(void) swim_finish_test(); } +static void +swim_test_broadcast(void) +{ + swim_start_test(6); + int size = 4; + struct swim_cluster *cluster = swim_cluster_new(size); + struct swim *s0 = swim_cluster_node(cluster, 0); + struct swim *s1 = swim_cluster_node(cluster, 1); + const char *s1_uri = swim_member_uri(swim_self(s1)); + struct uri u; + fail_if(uri_parse(&u, s1_uri) != 0 || u.service == NULL); + int port = atoi(u.service); + is(swim_broadcast(s0, port), 0, "S1 chooses to broadcast with port %d", + port); + is(swim_cluster_wait_status(cluster, 1, 0, MEMBER_ALIVE, 1), 0, + "S2 receives the broadcast from S1"); + swim_run_for(1); + is(swim_cluster_member_status(cluster, 2, 0), swim_member_status_MAX, + "others don't"); + + is(swim_broadcast(s0, 0), 0, "S1 broadcasts ping without port"); + is(swim_cluster_wait_status_everywhere(cluster, 0, MEMBER_ALIVE, 0), 0, + "now everyone sees S1"); + is(swim_cluster_wait_fullmesh(cluster, size), 0, + "fullmesh is reached, and no one link was added explicitly"); + + swim_cluster_delete(cluster); + swim_finish_test(); +} + static int main_f(va_list ap) { - swim_start_test(13); + swim_start_test(14); (void) ap; swim_test_ev_init(); @@ -574,6 +605,7 @@ main_f(va_list ap) swim_test_undead(); swim_test_packet_loss(); swim_test_quit(); + swim_test_broadcast(); swim_test_transport_free(); swim_test_ev_free(); diff --git a/test/unit/swim.result b/test/unit/swim.result index 7277f2ee6..73f2706b1 100644 --- a/test/unit/swim.result +++ b/test/unit/swim.result @@ -1,5 +1,5 @@ *** main_f *** -1..13 +1..14 *** swim_test_one_link *** 1..6 ok 1 - no rounds - no fullmesh @@ -131,4 +131,14 @@ ok 12 - subtests ok 9 - and still is not added to S2 - left members can not be added ok 13 - subtests *** swim_test_quit: done *** + *** swim_test_broadcast *** + 1..6 + ok 1 - S1 chooses to broadcast with port 2 + ok 2 - S2 receives the broadcast from S1 + ok 3 - others don't + ok 4 - S1 broadcasts ping without port + ok 5 - now everyone sees S1 + ok 6 - fullmesh is reached, and no one link was added explicitly +ok 14 - subtests + *** swim_test_broadcast: done *** *** main_f: done *** -- 2.17.2 (Apple Git-113)
next prev parent reply other threads:[~2019-04-10 17:45 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-04-10 17:45 [tarantool-patches] [PATCH 0/2] swim broadcast Vladislav Shpilevoy 2019-04-10 17:45 ` [tarantool-patches] [PATCH 1/2] swim: introduce broadcast tasks Vladislav Shpilevoy 2019-04-11 12:57 ` [tarantool-patches] " Konstantin Osipov 2019-04-11 13:46 ` Vladislav Shpilevoy 2019-04-10 17:45 ` Vladislav Shpilevoy [this message] 2019-04-11 13:00 ` [tarantool-patches] Re: [PATCH 2/2] swim: expose ping broadcast API Konstantin Osipov 2019-04-11 13:00 ` Konstantin Osipov 2019-04-11 13:47 ` Vladislav Shpilevoy 2019-04-10 18:11 ` [tarantool-patches] Re: [PATCH 0/2] swim broadcast Konstantin Osipov 2019-04-10 18:13 ` Vladislav Shpilevoy 2019-04-10 22:13 ` Vladislav Shpilevoy
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=8a92b8b538213827ac0ae156263bc88974e320c3.1554918303.git.v.shpilevoy@tarantool.org \ --to=v.shpilevoy@tarantool.org \ --cc=kostja@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [tarantool-patches] [PATCH 2/2] swim: expose ping broadcast API' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox