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 D0B702A4E8 for ; Wed, 20 Mar 2019 06:49:23 -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 3DdxyQ6G1o4z for ; Wed, 20 Mar 2019 06:49:23 -0400 (EDT) Received: from smtpng2.m.smailru.net (smtpng2.m.smailru.net [94.100.179.3]) (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 2B6312A4DE for ; Wed, 20 Mar 2019 06:49:23 -0400 (EDT) From: Vladislav Shpilevoy Subject: [tarantool-patches] [PATCH 4/6] swim: expose enum swim_member_status to public API Date: Wed, 20 Mar 2019 13:49:17 +0300 Message-Id: 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 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 +#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 +#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)