From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> To: tarantool-patches@freelists.org Cc: kostja@tarantool.org Subject: [tarantool-patches] [PATCH 7/6] swim: drop incarnation_inc parameter from update() routines Date: Thu, 18 Apr 2019 21:16:51 +0300 [thread overview] Message-ID: <2e76a679-c509-f12e-5abb-b1457ca478b0@tarantool.org> (raw) In-Reply-To: <cover.1555021137.git.v.shpilevoy@tarantool.org> Update_addr and update_payload need to increment member's incarnation when it is self. For that they used a special parameter incarnation_inc set in 1 for self and in 0 for others. It was used to encapsulate incarnation update + event scheduling on member attribute updates, but on the other hand it broke another encapsulation level - there should not be exceptions for 'self' in these functions. This patch makes incarnation increment explicit in the places where 'self' is updated. --- diff --git a/src/lib/swim/swim.c b/src/lib/swim/swim.c index 22760cdd7..86b45a2da 100644 --- a/src/lib/swim/swim.c +++ b/src/lib/swim/swim.c @@ -565,8 +565,7 @@ swim_by_scheduler(struct swim_scheduler *scheduler) /** Update member's payload, register a corresponding event. */ static inline int swim_update_member_payload(struct swim *swim, struct swim_member *member, - const char *payload, uint16_t payload_size, - int incarnation_increment) + const char *payload, uint16_t payload_size) { assert(payload_size <= MAX_PAYLOAD_SIZE); char *new_payload; @@ -584,7 +583,6 @@ swim_update_member_payload(struct swim *swim, struct swim_member *member, member->payload = new_payload; member->payload_size = payload_size; member->payload_ttd = mh_size(swim->members); - member->incarnation += incarnation_increment; member->is_payload_up_to_date = true; swim_on_member_update(swim, member); return 0; @@ -745,7 +743,7 @@ swim_new_member(struct swim *swim, const struct sockaddr_in *addr, swim_on_member_update(swim, member); if (payload_size >= 0 && swim_update_member_payload(swim, member, payload, - payload_size, 0) != 0) { + payload_size) != 0) { swim_delete_member(swim, member); return NULL; } @@ -1149,13 +1147,10 @@ swim_check_acks(struct ev_loop *loop, struct ev_timer *t, int events) /** Update member's address.*/ static inline void swim_update_member_addr(struct swim *swim, struct swim_member *member, - const struct sockaddr_in *addr, int incarnation_inc) + const struct sockaddr_in *addr) { - if (! swim_sockaddr_in_eq(addr, &member->addr)) { - member->incarnation += incarnation_inc; - member->addr = *addr; - swim_on_member_update(swim, member); - } + member->addr = *addr; + swim_on_member_update(swim, member); } /** @@ -1175,7 +1170,8 @@ swim_update_member(struct swim *swim, const struct swim_member_def *def, */ bool encode_payload = false; if (def->incarnation > member->incarnation) { - swim_update_member_addr(swim, member, &def->addr, 0); + if (! swim_sockaddr_in_eq(&def->addr, &member->addr)) + swim_update_member_addr(swim, member, &def->addr); if (def->payload_size >= 0) { encode_payload = true; } else if (member->is_payload_up_to_date) { @@ -1187,7 +1183,7 @@ swim_update_member(struct swim *swim, const struct swim_member_def *def, } if (encode_payload && swim_update_member_payload(swim, member, def->payload, - def->payload_size, 0) != 0) { + def->payload_size) != 0) { /* Not such a critical error. */ diag_log(); } @@ -1612,7 +1608,10 @@ swim_cfg(struct swim *swim, const char *uri, double heartbeat_rate, swim_on_member_update(swim, swim->self); swim->self = new_self; } - swim_update_member_addr(swim, swim->self, &addr, 1); + if (! swim_sockaddr_in_eq(&addr, &swim->self->addr)) { + swim->self->incarnation++; + swim_update_member_addr(swim, swim->self, &addr); + } if (gc_mode != SWIM_GC_DEFAULT) swim->gc_mode = gc_mode; return 0; @@ -1638,8 +1637,12 @@ swim_set_payload(struct swim *swim, const char *payload, uint16_t payload_size) MAX_PAYLOAD_SIZE); return -1; } - return swim_update_member_payload(swim, swim->self, payload, - payload_size, 1); + struct swim_member *self = swim->self; + if (swim_update_member_payload(swim, self, payload, payload_size) != 0) + return -1; + self->incarnation++; + swim_on_member_update(swim, self); + return 0; } int
next prev parent reply other threads:[~2019-04-18 18:16 UTC|newest] Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-04-11 22:22 [tarantool-patches] [PATCH 0/6] swim payload Vladislav Shpilevoy 2019-04-11 22:22 ` [tarantool-patches] [PATCH 1/6] swim: factor out MP_BIN decoding from swim_decode_uuid Vladislav Shpilevoy 2019-04-11 23:09 ` [tarantool-patches] " Konstantin Osipov 2019-04-12 19:23 ` Vladislav Shpilevoy 2019-04-11 22:22 ` [tarantool-patches] [PATCH 2/6] swim: replace event_bin and member_bin with the passport Vladislav Shpilevoy 2019-04-11 23:10 ` [tarantool-patches] " Konstantin Osipov 2019-04-12 19:23 ` Vladislav Shpilevoy 2019-04-11 22:22 ` [tarantool-patches] [PATCH 3/6] swim: factor out 'update' part of swim_member_upsert() Vladislav Shpilevoy 2019-04-11 23:11 ` [tarantool-patches] " Konstantin Osipov 2019-04-12 19:23 ` Vladislav Shpilevoy 2019-04-11 22:22 ` [tarantool-patches] [PATCH 4/6] test: generalize SWIM fake descriptor filters Vladislav Shpilevoy 2019-04-11 23:11 ` [tarantool-patches] " Konstantin Osipov 2019-04-12 19:23 ` Vladislav Shpilevoy 2019-04-11 22:22 ` [tarantool-patches] [PATCH 5/6] test: introduce new SWIM packet filter by component names Vladislav Shpilevoy 2019-04-11 23:11 ` [tarantool-patches] " Konstantin Osipov 2019-04-12 19:23 ` Vladislav Shpilevoy 2019-04-11 22:22 ` [tarantool-patches] [PATCH 6/6] swim: introduce payload Vladislav Shpilevoy 2019-04-18 15:12 ` [tarantool-patches] " Konstantin Osipov 2019-04-18 17:43 ` Vladislav Shpilevoy 2019-04-18 18:03 ` Konstantin Osipov 2019-04-18 20:40 ` Vladislav Shpilevoy 2019-04-18 17:43 ` [tarantool-patches] [PATCH 5.5/6] swim: rename TTL to TTD Vladislav Shpilevoy 2019-04-18 17:48 ` [tarantool-patches] " Konstantin Osipov 2019-04-18 20:40 ` Vladislav Shpilevoy 2019-04-18 18:16 ` Vladislav Shpilevoy [this message] 2019-04-18 18:20 ` [tarantool-patches] Re: [PATCH 7/6] swim: drop incarnation_inc parameter from update() routines Konstantin Osipov 2019-04-18 20:40 ` 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=2e76a679-c509-f12e-5abb-b1457ca478b0@tarantool.org \ --to=v.shpilevoy@tarantool.org \ --cc=kostja@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [tarantool-patches] [PATCH 7/6] swim: drop incarnation_inc parameter from update() routines' \ /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