From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 2828229E01 for ; Wed, 10 Apr 2019 13:45:39 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GLBLvwdEIIKn for ; Wed, 10 Apr 2019 13:45:38 -0400 (EDT) Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 5128029C60 for ; Wed, 10 Apr 2019 13:45:38 -0400 (EDT) From: Vladislav Shpilevoy Subject: [tarantool-patches] [PATCH 2/2] swim: expose ping broadcast API Date: Wed, 10 Apr 2019 20:45:34 +0300 Message-Id: <8a92b8b538213827ac0ae156263bc88974e320c3.1554918303.git.v.shpilevoy@tarantool.org> In-Reply-To: References: In-Reply-To: References: Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tarantool-patches@freelists.org Cc: kostja@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)