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 06A4E2AFBF for ; Tue, 9 Apr 2019 07:46:42 -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 d-tlSlhZuZqV 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 1D4652AF98 for ; Tue, 9 Apr 2019 07:46:41 -0400 (EDT) From: Vladislav Shpilevoy Subject: [tarantool-patches] [PATCH v2 1/6] swim: encapsulate member bin info into a 'passport' Date: Tue, 9 Apr 2019 14:46:32 +0300 Message-Id: <06133dce4005dbf6b6e5a9a2149bef25ef9d61e7.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 Each member stored in components dissemination and anti-entropy should carry a unique identifier, a status, and an address. Those attributes are UUID, IP, Port, enum swim_member_status, incarnation. Now they are sent only in scope of anti-entropy, but forthcoming dissemination component also would like to use these attributes for each event. This commit makes the vital attributes and their code more reusable by encapsulation of them into a binary passport structure. Part of #3234 --- src/lib/swim/swim_proto.c | 46 ++++++++++++++++++++++++++------------- src/lib/swim/swim_proto.h | 26 +++++++++++++++++----- 2 files changed, 51 insertions(+), 21 deletions(-) diff --git a/src/lib/swim/swim_proto.c b/src/lib/swim/swim_proto.c index 4e607e796..416e1d99e 100644 --- a/src/lib/swim/swim_proto.c +++ b/src/lib/swim/swim_proto.c @@ -314,32 +314,48 @@ swim_anti_entropy_header_bin_create(struct swim_anti_entropy_header_bin *header, header->v_anti_entropy = mp_bswap_u16(batch_size); } +static inline void +swim_passport_bin_create(struct swim_passport_bin *passport) +{ + passport->k_status = SWIM_MEMBER_STATUS; + passport->k_addr = SWIM_MEMBER_ADDRESS; + passport->m_addr = 0xce; + passport->k_port = SWIM_MEMBER_PORT; + passport->m_port = 0xcd; + passport->k_uuid = SWIM_MEMBER_UUID; + passport->m_uuid = 0xc4; + passport->m_uuid_len = UUID_LEN; + passport->k_incarnation = SWIM_MEMBER_INCARNATION; + passport->m_incarnation = 0xcf; +} + +static inline void +swim_passport_bin_fill(struct swim_passport_bin *passport, + const struct sockaddr_in *addr, + const struct tt_uuid *uuid, + enum swim_member_status status, uint64_t incarnation) +{ + passport->v_status = status; + passport->v_addr = mp_bswap_u32(ntohl(addr->sin_addr.s_addr)); + passport->v_port = mp_bswap_u16(ntohs(addr->sin_port)); + memcpy(passport->v_uuid, uuid, UUID_LEN); + passport->v_incarnation = mp_bswap_u64(incarnation); +} + void swim_member_bin_fill(struct swim_member_bin *header, const struct sockaddr_in *addr, const struct tt_uuid *uuid, enum swim_member_status status, uint64_t incarnation) { - header->v_status = status; - header->v_addr = mp_bswap_u32(ntohl(addr->sin_addr.s_addr)); - header->v_port = mp_bswap_u16(ntohs(addr->sin_port)); - memcpy(header->v_uuid, uuid, UUID_LEN); - header->v_incarnation = mp_bswap_u64(incarnation); + swim_passport_bin_fill(&header->passport, addr, uuid, status, + incarnation); } void swim_member_bin_create(struct swim_member_bin *header) { header->m_header = 0x85; - header->k_status = SWIM_MEMBER_STATUS; - header->k_addr = SWIM_MEMBER_ADDRESS; - header->m_addr = 0xce; - header->k_port = SWIM_MEMBER_PORT; - header->m_port = 0xcd; - header->k_uuid = SWIM_MEMBER_UUID; - header->m_uuid = 0xc4; - header->m_uuid_len = UUID_LEN; - header->k_incarnation = SWIM_MEMBER_INCARNATION; - header->m_incarnation = 0xcf; + swim_passport_bin_create(&header->passport); } void diff --git a/src/lib/swim/swim_proto.h b/src/lib/swim/swim_proto.h index 07905df31..0e73f37fb 100644 --- a/src/lib/swim/swim_proto.h +++ b/src/lib/swim/swim_proto.h @@ -239,13 +239,16 @@ swim_anti_entropy_header_bin_create(struct swim_anti_entropy_header_bin *header, uint16_t batch_size); /** - * SWIM member MessagePack template. Represents one record in - * anti-entropy section. + * The structure represents a passport of a member. It consists of + * some vital necessary member attributes, allowing to detect its + * state, exact address. The whole passport is necessary for each + * info related to a member: for anti-entropy records, for + * dissemination events. The components can inherit that structure + * and add more attributes. For example, anti-entropy can add a + * mandatory payload; dissemination adds optional old UUID and + * payload. */ -struct PACKED swim_member_bin { - /** mp_encode_map(5) */ - uint8_t m_header; - +struct PACKED swim_passport_bin { /** mp_encode_uint(SWIM_MEMBER_STATUS) */ uint8_t k_status; /** mp_encode_uint(enum member_status) */ @@ -277,6 +280,17 @@ struct PACKED swim_member_bin { uint64_t v_incarnation; }; +/** + * SWIM member MessagePack template. Represents one record in + * anti-entropy section. + */ +struct PACKED swim_member_bin { + /** mp_encode_map(5) */ + uint8_t m_header; + /** Basic member info like status, address. */ + struct swim_passport_bin passport; +}; + /** Initialize antri-entropy record. */ void swim_member_bin_create(struct swim_member_bin *header); -- 2.17.2 (Apple Git-113)