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 F24972AFB9 for ; Tue, 9 Apr 2019 07:46:41 -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 I2Sw6jVN1tdt for ; Tue, 9 Apr 2019 07:46:41 -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 15A342AF95 for ; Tue, 9 Apr 2019 07:46:40 -0400 (EDT) From: Vladislav Shpilevoy Subject: [tarantool-patches] [PATCH v2 2/6] swim: make members array decoder be a separate function Date: Tue, 9 Apr 2019 14:46:33 +0300 Message-Id: <0b70490be1c6d5a666178f38f1c9534e84dbf10d.1554809200.git.v.shpilevoy@tarantool.org> 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 this moment SWIM protocol stores array of members only in one place: inside the anti-entropy component. Its decoding is a simple loop taking the member definitions one by one and upserting them into the member table. But the dissemination also has something kinda like members array: an array of events. The trick is that an event is basically the same as a member +/- a couple of optional fields. Events are also decoded into the member definition structure. It means that anti-entropy decoder can be easily reused. Part of #3234 --- src/lib/swim/swim.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/lib/swim/swim.c b/src/lib/swim/swim.c index f65fb60a3..a30a83886 100644 --- a/src/lib/swim/swim.c +++ b/src/lib/swim/swim.c @@ -1019,12 +1019,14 @@ skip: return 0; } -/** Decode an anti-entropy message, update member table. */ +/** + * Decode a bunch of members encoded as a MessagePack array. Each + * correctly decoded member is upserted into the member table. + */ static int -swim_process_anti_entropy(struct swim *swim, const char **pos, const char *end) +swim_process_members(struct swim *swim, const char *prefix, + const char **pos, const char *end) { - say_verbose("SWIM %d: process anti-entropy", swim_fd(swim)); - const char *prefix = "invalid anti-entropy message:"; uint32_t size; if (swim_decode_array(pos, end, &size, prefix, "root") != 0) return -1; @@ -1044,6 +1046,15 @@ swim_process_anti_entropy(struct swim *swim, const char **pos, const char *end) return 0; } +/** Decode an anti-entropy message, update member table. */ +static int +swim_process_anti_entropy(struct swim *swim, const char **pos, const char *end) +{ + say_verbose("SWIM %d: process anti-entropy", swim_fd(swim)); + const char *prefix = "invalid anti-entropy message:"; + return swim_process_members(swim, prefix, pos, end); +} + /** * Decode a failure detection message. Schedule acks, process * acks. -- 2.17.2 (Apple Git-113)