Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org
Cc: kostja@tarantool.org
Subject: [tarantool-patches] [PATCH 7/6] swim: make swim_upsert_member returning two values
Date: Wed, 27 Mar 2019 22:28:38 +0300	[thread overview]
Message-ID: <1a730742-0560-21da-d089-9d5b278532e4@tarantool.org> (raw)
In-Reply-To: <cover.1553078631.git.v.shpilevoy@tarantool.org>

Here is one new patch. It appeared to be usefull both
for the failure detection and for the dissemination.

================================================================

swim_upsert_member is a function to add new members or update
existing ones using info received from other cluster
participants. At this moment it is quite simple and
straightforward: either create a new member and return it, or
update an existing member and return it.

But things are going to change in failure detection and
dissemination components. A couple of examples showing that a
member should be returned separately from success/error status:

  * To prevent undead members the failure detection forbids to
    add dead members. Otherwise a dead member would be added and
    removed back and forth by different components infinitely.
    Upsert for such members should return NULL, but it is not an
    error - it is a normal function of the protocol;

  * When the dissemination component receives a UUID update of
    an existing member, but with too old incarnation, it does not
    apply that update. And can not return that member from upsert
    because of UUID being different from the one in the
    'request'. In such a case it should be ok to return NULL, but
    do not deem it an error.

Part of #3234
---

diff --git a/src/lib/swim/swim.c b/src/lib/swim/swim.c
index df34ce247..1b623fc27 100644
--- a/src/lib/swim/swim.c
+++ b/src/lib/swim/swim.c
@@ -657,22 +657,32 @@ swim_update_member_addr(struct swim *swim, struct swim_member *member,
 /**
  * Update or create a member by its definition, received from a
  * remote instance.
- * @retval NULL Error.
- * @retval New member, or updated old member.
+ * @param swim SWIM instance to upsert into.
+ * @param def Member definition to build a new member or update an
+ *        existing one.
+ * @param[out] result A result member: a new, or an updated, or
+ *        NULL in case of nothing has changed. For example, @a def
+ *        was too old.
+ *
+ * @retval 0 Success. Member is added, or updated. Or nothing has
+ *         changed but not always it is an error.
+ * @retval -1 Error.
  */
-static struct swim_member *
-swim_upsert_member(struct swim *swim, const struct swim_member_def *def)
+static int
+swim_upsert_member(struct swim *swim, const struct swim_member_def *def,
+		   struct swim_member **result)
 {
 	struct swim_member *member = swim_find_member(swim, &def->uuid);
 	if (member == NULL) {
-		member = swim_new_member(swim, &def->addr, &def->uuid,
-					 def->status);
-		return member;
+		*result = swim_new_member(swim, &def->addr, &def->uuid,
+					  def->status);
+		return *result != NULL ? 0 : -1;
 	}
 	struct swim_member *self = swim->self;
 	if (member != self)
 		swim_update_member_addr(swim, member, &def->addr);
-	return member;
+	*result = member;
+	return 0;
 }
 
 /** Decode an anti-entropy message, update member table. */
@@ -686,9 +696,10 @@ swim_process_anti_entropy(struct swim *swim, const char **pos, const char *end)
 		return -1;
 	for (uint64_t i = 0; i < size; ++i) {
 		struct swim_member_def def;
+		struct swim_member *member;
 		if (swim_member_def_decode(&def, pos, end, prefix) != 0)
 			return -1;
-		if (swim_upsert_member(swim, &def) == NULL) {
+		if (swim_upsert_member(swim, &def, &member) != 0) {
 			/*
 			 * Not a critical error. Other members
 			 * still can be updated.

  parent reply	other threads:[~2019-03-27 19:28 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
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 ` Vladislav Shpilevoy [this message]
2019-03-28  8:52   ` [tarantool-patches] Re: [PATCH 7/6] swim: make swim_upsert_member returning two values 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=1a730742-0560-21da-d089-9d5b278532e4@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH 7/6] swim: make swim_upsert_member returning two values' \
    /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