[tarantool-patches] [PATCH 1/5] swim: encapsulate member bin info into a 'passport'
Vladislav Shpilevoy
v.shpilevoy at tarantool.org
Fri Apr 5 14:57:27 MSK 2019
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)
More information about the Tarantool-patches
mailing list