[tarantool-patches] Re: [PATCH 4/6] swim: expose enum swim_member_status to public API
Vladislav Shpilevoy
v.shpilevoy at tarantool.org
Tue Apr 2 15:25:57 MSK 2019
On 29/03/2019 21:24, Konstantin Osipov wrote:
> * Vladislav Shpilevoy <v.shpilevoy at 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 at 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.
More information about the Tarantool-patches
mailing list