From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> To: tarantool-patches@freelists.org Cc: kostja@tarantool.org Subject: [tarantool-patches] [PATCH 4/6] swim: expose enum swim_member_status to public API Date: Wed, 20 Mar 2019 13:49:17 +0300 [thread overview] Message-ID: <bc6b3655bb2ffbbd2e6420efa92e14a77abf5f97.1553078631.git.v.shpilevoy@tarantool.org> (raw) In-Reply-To: <cover.1553078631.git.v.shpilevoy@tarantool.org> In-Reply-To: <cover.1553078631.git.v.shpilevoy@tarantool.org> 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 --- src/lib/swim/swim.c | 6 ++++++ src/lib/swim/swim.h | 6 ++++++ src/lib/swim/swim_proto.h | 14 +++++++++++--- test/unit/swim.c | 11 ++++++++++- test/unit/swim.result | 6 +++++- test/unit/swim_test_utils.c | 22 +++++++++++++++++++++- test/unit/swim_test_utils.h | 6 +++++- 7 files changed, 64 insertions(+), 7 deletions(-) diff --git a/src/lib/swim/swim.c b/src/lib/swim/swim.c index c2b2132a2..df34ce247 100644 --- a/src/lib/swim/swim.c +++ b/src/lib/swim/swim.c @@ -962,6 +962,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..ddb759c3d 100644 --- a/src/lib/swim/swim.h +++ b/src/lib/swim/swim.h @@ -31,6 +31,8 @@ * SUCH DAMAGE. */ #include <stdbool.h> +#define SWIM_PUBLIC_API +#include "swim_proto.h" #if defined(__cplusplus) extern "C" { @@ -112,6 +114,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_proto.h b/src/lib/swim/swim_proto.h index 300a08c1f..4f3cdf03d 100644 --- a/src/lib/swim/swim_proto.h +++ b/src/lib/swim/swim_proto.h @@ -1,5 +1,3 @@ -#ifndef TARANTOOL_SWIM_PROTO_H_INCLUDED -#define TARANTOOL_SWIM_PROTO_H_INCLUDED /* * Copyright 2010-2019, Tarantool AUTHORS, please see AUTHORS file. * @@ -64,6 +62,9 @@ * +-------------------------------------------------------------+ */ +#ifndef TARANTOOL_SWIM_PUBLIC_PROTO_H_INCLUDED +#define TARANTOOL_SWIM_PUBLIC_PROTO_H_INCLUDED + enum swim_member_status { /** The instance is ok, responds to requests. */ MEMBER_ALIVE = 0, @@ -72,6 +73,13 @@ enum swim_member_status { extern const char *swim_member_status_strs[]; +#endif /* TARANTOOL_SWIM_PUBLIC_PROTO_H_INCLUDED */ + +#ifdef SWIM_PUBLIC_API +#undef SWIM_PUBLIC_API +#elif !defined(TARANTOOL_SWIM_PRIVATE_PROTO_H_INCLUDED) +#define TARANTOOL_SWIM_PRIVATE_PROTO_H_INCLUDED + /** * SWIM member attributes from anti-entropy and dissemination * messages. @@ -317,4 +325,4 @@ int swim_decode_uuid(struct tt_uuid *uuid, const char **pos, const char *end, const char *prefix, const char *param_name); -#endif /* TARANTOOL_SWIM_PROTO_H_INCLUDED */ +#endif /* TARANTOOL_SWIM_PRIVATE_PROTO_H_INCLUDED */ 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 ee24b0320..0d62bb26c 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. -- 2.17.2 (Apple Git-113)
next prev parent reply other threads:[~2019-03-20 10:49 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 ` Vladislav Shpilevoy [this message] 2019-03-29 18:24 ` [tarantool-patches] Re: [PATCH 4/6] swim: expose enum swim_member_status to public API Konstantin Osipov 2019-04-02 12:25 ` Vladislav Shpilevoy 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=bc6b3655bb2ffbbd2e6420efa92e14a77abf5f97.1553078631.git.v.shpilevoy@tarantool.org \ --to=v.shpilevoy@tarantool.org \ --cc=kostja@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [tarantool-patches] [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