From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> To: tarantool-patches@freelists.org Cc: kostja@tarantool.org Subject: [tarantool-patches] [PATCH 1/5] swim: encapsulate member bin info into a 'passport' Date: Fri, 5 Apr 2019 14:57:27 +0300 [thread overview] Message-ID: <06133dce4005dbf6b6e5a9a2149bef25ef9d61e7.1554465150.git.v.shpilevoy@tarantool.org> (raw) In-Reply-To: <cover.1554465150.git.v.shpilevoy@tarantool.org> In-Reply-To: <cover.1554465150.git.v.shpilevoy@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)
next prev parent reply other threads:[~2019-04-05 11:57 UTC|newest] Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-04-05 11:57 [tarantool-patches] [PATCH 0/5] swim dissemination component Vladislav Shpilevoy 2019-04-05 11:57 ` Vladislav Shpilevoy [this message] 2019-04-05 11:57 ` [tarantool-patches] [PATCH 2/5] swim: make members array decoder be a separate function Vladislav Shpilevoy 2019-04-05 11:57 ` [tarantool-patches] [PATCH 3/5] test: speed up swim big cluster failure detection Vladislav Shpilevoy 2019-04-09 8:43 ` [tarantool-patches] " Konstantin Osipov 2019-04-09 11:47 ` Vladislav Shpilevoy 2019-04-05 11:57 ` [tarantool-patches] [PATCH 4/5] test: set packet drop rate instead of flag in swim tests Vladislav Shpilevoy 2019-04-05 11:57 ` [tarantool-patches] [PATCH 5/5] swim: introduce dissemination component Vladislav Shpilevoy 2019-04-08 20:13 ` [tarantool-patches] " Vladislav Shpilevoy 2019-04-09 9:58 ` Konstantin Osipov 2019-04-09 11:47 ` Vladislav Shpilevoy 2019-04-09 12:25 ` [tarantool-patches] Re: [PATCH 0/5] swim " 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=06133dce4005dbf6b6e5a9a2149bef25ef9d61e7.1554465150.git.v.shpilevoy@tarantool.org \ --to=v.shpilevoy@tarantool.org \ --cc=kostja@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [tarantool-patches] [PATCH 1/5] swim: encapsulate member bin info into a '\''passport'\''' \ /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