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 745112C1BD for ; Thu, 18 Apr 2019 14:16:54 -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 0l3l2thjAj9o for ; Thu, 18 Apr 2019 14:16:54 -0400 (EDT) Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (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 2AEE82C503 for ; Thu, 18 Apr 2019 14:16:54 -0400 (EDT) Subject: [tarantool-patches] [PATCH 7/6] swim: drop incarnation_inc parameter from update() routines From: Vladislav Shpilevoy References: Message-ID: <2e76a679-c509-f12e-5abb-b1457ca478b0@tarantool.org> Date: Thu, 18 Apr 2019 21:16:51 +0300 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit 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 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