From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> To: tarantool-patches@freelists.org, Konstantin Osipov <kostja@tarantool.org> Subject: [tarantool-patches] Re: [PATCH 4/6] swim: expose enum swim_member_status to public API Date: Tue, 2 Apr 2019 15:25:57 +0300 [thread overview] Message-ID: <bf8a911c-1891-3826-9cd8-0738bcadbcb1@tarantool.org> (raw) In-Reply-To: <20190329182432.GC20712@chai> On 29/03/2019 21:24, Konstantin Osipov wrote: > * Vladislav Shpilevoy <v.shpilevoy@tarantool.org> [19/03/20 14:11]: >> At least for testing it is necessary to be able to get status of >> a member. Now it is always 'alive', but forthcoming >> failure-detection component would change it. > >> +#define SWIM_PUBLIC_API >> +#include "swim_proto.h" > > Please rather than using a define kludge introduce > swim_constants.h and move the declaration there. Make > swim_constants.h part of the public api. My main goal was not to lost the git history of enum swim_member_status, because at this moment it is pedantically accurate, with one commit per a single SWIM component introduction in each line of that enum. But as you wish. Since the patch has changed too much, there are no incremental diff. I pasted a new version below. ============================================================================== commit c775ac3bb2debf7bb14514cad9446c734f97afc2 Author: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> Date: Tue Mar 12 20:36:31 2019 +0300 swim: expose enum swim_member_status to public API At least for testing it is necessary to be able to get status of a member. Now it is always 'alive', but forthcoming failure-detection component would change it. Part of #3234 diff --git a/src/lib/swim/swim.c b/src/lib/swim/swim.c index 6e80b2268..1b623fc27 100644 --- a/src/lib/swim/swim.c +++ b/src/lib/swim/swim.c @@ -973,6 +973,12 @@ swim_member_by_uuid(struct swim *swim, const struct tt_uuid *uuid) return swim_find_member(swim, uuid); } +enum swim_member_status +swim_member_status(const struct swim_member *member) +{ + return member->status; +} + struct swim_iterator * swim_iterator_open(struct swim *swim) { diff --git a/src/lib/swim/swim.h b/src/lib/swim/swim.h index 744214371..3e57076c5 100644 --- a/src/lib/swim/swim.h +++ b/src/lib/swim/swim.h @@ -31,6 +31,7 @@ * SUCH DAMAGE. */ #include <stdbool.h> +#include "swim_constants.h" #if defined(__cplusplus) extern "C" { @@ -112,6 +113,10 @@ swim_self(struct swim *swim); const struct swim_member * swim_member_by_uuid(struct swim *swim, const struct tt_uuid *uuid); +/** Member's current status. */ +enum swim_member_status +swim_member_status(const struct swim_member *member); + /** * Open an iterator to scan the whole member table. The iterator * is not stable. It means, that a caller can not yield between diff --git a/src/lib/swim/swim_constants.h b/src/lib/swim/swim_constants.h new file mode 100644 index 000000000..c17e5060a --- /dev/null +++ b/src/lib/swim/swim_constants.h @@ -0,0 +1,45 @@ +#ifndef TARANTOOL_SWIM_CONSTANTS_H_INCLUDED +#define TARANTOOL_SWIM_CONSTANTS_H_INCLUDED +/* + * Copyright 2010-2019, Tarantool AUTHORS, please see AUTHORS file. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +/** + * Constants for public API. + */ + +enum swim_member_status { + /** The instance is ok, responds to requests. */ + MEMBER_ALIVE = 0, + swim_member_status_MAX, +}; + +extern const char *swim_member_status_strs[]; + +#endif /* TARANTOOL_SWIM_CONSTANTS_H_INCLUDED */ diff --git a/src/lib/swim/swim_proto.h b/src/lib/swim/swim_proto.h index a0eb26209..69b44f14a 100644 --- a/src/lib/swim/swim_proto.h +++ b/src/lib/swim/swim_proto.h @@ -36,6 +36,7 @@ #include <netinet/in.h> #include <sys/socket.h> #include <stdbool.h> +#include "swim_constants.h" /** * SWIM binary protocol structures and helpers. Below is a picture @@ -66,14 +67,6 @@ * +-------------------------------------------------------------+ */ -enum swim_member_status { - /** The instance is ok, responds to requests. */ - MEMBER_ALIVE = 0, - swim_member_status_MAX, -}; - -extern const char *swim_member_status_strs[]; - /** * SWIM member attributes from anti-entropy and dissemination * messages. diff --git a/test/unit/swim.c b/test/unit/swim.c index 2c04e25b9..ea60be4ae 100644 --- a/test/unit/swim.c +++ b/test/unit/swim.c @@ -50,7 +50,7 @@ static int test_result; static void swim_test_one_link(void) { - swim_start_test(2); + swim_start_test(6); /* * Run a simple cluster of two elements. One of them * learns about another explicitly. Another should add the @@ -61,6 +61,15 @@ swim_test_one_link(void) is(swim_cluster_wait_fullmesh(cluster, 0.9), -1, "no rounds - no fullmesh"); is(swim_cluster_wait_fullmesh(cluster, 0.1), 0, "one link"); + + is(swim_cluster_member_status(cluster, 0, 0), MEMBER_ALIVE, + "self 0 is alive"); + is(swim_cluster_member_status(cluster, 1, 1), MEMBER_ALIVE, + "self 1 is alive"); + is(swim_cluster_member_status(cluster, 0, 1), MEMBER_ALIVE, + "0 sees 1 as alive"); + is(swim_cluster_member_status(cluster, 1, 0), MEMBER_ALIVE, + "1 sees 0 as alive"); swim_cluster_delete(cluster); swim_finish_test(); diff --git a/test/unit/swim.result b/test/unit/swim.result index b58325b73..42cef1612 100644 --- a/test/unit/swim.result +++ b/test/unit/swim.result @@ -1,9 +1,13 @@ *** main_f *** 1..5 *** swim_test_one_link *** - 1..2 + 1..6 ok 1 - no rounds - no fullmesh ok 2 - one link + ok 3 - self 0 is alive + ok 4 - self 1 is alive + ok 5 - 0 sees 1 as alive + ok 6 - 1 sees 0 as alive ok 1 - subtests *** swim_test_one_link: done *** *** swim_test_sequence *** diff --git a/test/unit/swim_test_utils.c b/test/unit/swim_test_utils.c index b4c2adf3b..71ec63f3b 100644 --- a/test/unit/swim_test_utils.c +++ b/test/unit/swim_test_utils.c @@ -31,7 +31,6 @@ #include "swim_test_utils.h" #include "swim_test_ev.h" #include "swim_test_transport.h" -#include "swim/swim.h" #include "swim/swim_ev.h" #include "uuid/tt_uuid.h" #include "trivia/util.h" @@ -87,6 +86,27 @@ swim_cluster_add_link(struct swim_cluster *cluster, int to_id, int from_id) swim_member_uuid(from)); } +static const struct swim_member * +swim_cluster_member_view(struct swim_cluster *cluster, int node_id, + int member_id) +{ + struct swim *node = cluster->node[node_id]; + const struct swim_member *member = swim_self(cluster->node[member_id]); + const struct tt_uuid *member_uuid = swim_member_uuid(member); + return swim_member_by_uuid(node, member_uuid); +} + +enum swim_member_status +swim_cluster_member_status(struct swim_cluster *cluster, int node_id, + int member_id) +{ + const struct swim_member *m = + swim_cluster_member_view(cluster, node_id, member_id); + if (m == NULL) + return swim_member_status_MAX; + return swim_member_status(m); +} + struct swim * swim_cluster_node(struct swim_cluster *cluster, int i) { diff --git a/test/unit/swim_test_utils.h b/test/unit/swim_test_utils.h index 56fc2f57d..befb95420 100644 --- a/test/unit/swim_test_utils.h +++ b/test/unit/swim_test_utils.h @@ -31,9 +31,9 @@ * SUCH DAMAGE. */ #include <stdbool.h> +#include "swim/swim.h" struct swim_cluster; -struct swim; /** * Create a new cluster of SWIM instances. Instances are assigned @@ -71,6 +71,10 @@ swim_cluster_unblock_io(struct swim_cluster *cluster, int i); int swim_cluster_add_link(struct swim_cluster *cluster, int to_id, int from_id); +enum swim_member_status +swim_cluster_member_status(struct swim_cluster *cluster, int node_id, + int member_id); + /** * Check if in the cluster every instance knowns the about other * instances.
next prev parent reply other threads:[~2019-04-02 12:26 UTC|newest] Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-03-20 10:49 [tarantool-patches] [PATCH 0/6] SWIM failure detection draft Vladislav Shpilevoy 2019-03-20 10:49 ` [tarantool-patches] [PATCH 1/6] swim: follow-ups for SWIM anti-entropy Vladislav Shpilevoy 2019-03-29 8:27 ` [tarantool-patches] " Konstantin Osipov 2019-03-29 10:19 ` Vladislav Shpilevoy 2019-03-20 10:49 ` [tarantool-patches] [PATCH 2/6] test: introduce breakpoints for swim's event loop Vladislav Shpilevoy 2019-03-29 18:20 ` [tarantool-patches] " Konstantin Osipov 2019-04-02 12:25 ` Vladislav Shpilevoy 2019-04-02 19:16 ` Vladislav Shpilevoy 2019-04-02 20:40 ` Konstantin Osipov 2019-04-02 21:26 ` Vladislav Shpilevoy 2019-03-20 10:49 ` [tarantool-patches] [PATCH 3/6] test: remove swim_unblock_fd event from swim test harness Vladislav Shpilevoy 2019-03-29 18:22 ` [tarantool-patches] " Konstantin Osipov 2019-04-02 21:26 ` Vladislav Shpilevoy 2019-03-20 10:49 ` [tarantool-patches] [PATCH 4/6] swim: expose enum swim_member_status to public API Vladislav Shpilevoy 2019-03-29 18:24 ` [tarantool-patches] " Konstantin Osipov 2019-04-02 12:25 ` Vladislav Shpilevoy [this message] 2019-04-02 13:17 ` Konstantin Osipov 2019-04-02 21:26 ` Vladislav Shpilevoy 2019-03-20 10:49 ` [tarantool-patches] [PATCH 5/6] test: differentiate blocked and closed swim fake fds Vladislav Shpilevoy 2019-03-29 18:25 ` [tarantool-patches] " Konstantin Osipov 2019-04-02 21:26 ` Vladislav Shpilevoy 2019-03-20 10:49 ` [tarantool-patches] [PATCH 6/6] [RAW] swim: introduce failure detection component Vladislav Shpilevoy 2019-03-29 18:59 ` [tarantool-patches] " Konstantin Osipov 2019-04-02 12:25 ` Vladislav Shpilevoy 2019-04-04 10:20 ` Vladislav Shpilevoy 2019-04-04 12:45 ` Konstantin Osipov 2019-04-04 13:57 ` Vladislav Shpilevoy 2019-04-04 16:14 ` Vladimir Davydov 2019-04-04 16:47 ` Vladislav Shpilevoy 2019-03-27 19:28 ` [tarantool-patches] [PATCH 7/6] swim: make swim_upsert_member returning two values Vladislav Shpilevoy 2019-03-28 8:52 ` [tarantool-patches] " Konstantin Osipov 2019-03-28 11:52 ` 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=bf8a911c-1891-3826-9cd8-0738bcadbcb1@tarantool.org \ --to=v.shpilevoy@tarantool.org \ --cc=kostja@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='[tarantool-patches] Re: [PATCH 4/6] swim: expose enum swim_member_status to public 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