From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 dev.tarantool.org (Postfix) with ESMTPS id 8150943040D for ; Fri, 4 Sep 2020 01:51:27 +0300 (MSK) From: Vladislav Shpilevoy Date: Fri, 4 Sep 2020 00:51:15 +0200 Message-Id: <89d43ffb6714598c377f0fdcccae61a6ab360409.1599173312.git.v.shpilevoy@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v2 01/10] applier: store instance_id in struct applier List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org, sergepetrenko@tarantool.org, gorcunov@gmail.com Applier is going to need its numeric ID in order to tell the future Raft module who is a sender of a Raft message. An alternative would be to add sender ID to each Raft message, but this looks like a crutch. Moreover, applier still needs to know its numeric ID in order to notify Raft about heartbeats from the peer node. Needed for #1146 --- src/box/applier.cc | 19 +++++++++++++++++++ src/box/applier.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/src/box/applier.cc b/src/box/applier.cc index c1d07ca54..699b5a683 100644 --- a/src/box/applier.cc +++ b/src/box/applier.cc @@ -67,6 +67,23 @@ applier_set_state(struct applier *applier, enum applier_state state) trigger_run_xc(&applier->on_state, applier); } +static inline void +applier_assign_instance_id(struct applier *applier) +{ + /* + * After final join, the applier already received latest + * records from _cluster, including the record about + * source instance. It can be absent in case the source is + * an anonymous replica. + */ + assert(applier->state == APPLIER_JOINED); + struct replica *replica = replica_by_uuid(&applier->uuid); + if (replica != NULL) + applier->instance_id = replica->id; + else + assert(applier->instance_id == 0); +} + /** * Write a nice error message to log file on SocketError or ClientError * in applier_f(). @@ -603,6 +620,7 @@ applier_join(struct applier *applier) say_info("final data received"); applier_set_state(applier, APPLIER_JOINED); + applier_assign_instance_id(applier); applier_set_state(applier, APPLIER_READY); } @@ -1207,6 +1225,7 @@ applier_subscribe(struct applier *applier) instance_id != REPLICA_ID_NIL) { say_info("final data received"); applier_set_state(applier, APPLIER_JOINED); + applier_assign_instance_id(applier); applier_set_state(applier, APPLIER_READY); applier_set_state(applier, APPLIER_FOLLOW); } diff --git a/src/box/applier.h b/src/box/applier.h index 6e979a806..15ca1fcfd 100644 --- a/src/box/applier.h +++ b/src/box/applier.h @@ -95,6 +95,8 @@ struct applier { ev_tstamp lag; /** The last box_error_code() logged to avoid log flooding */ uint32_t last_logged_errcode; + /** Remote instance ID. */ + uint32_t instance_id; /** Remote instance UUID */ struct tt_uuid uuid; /** Remote URI (string) */ -- 2.21.1 (Apple Git-122.3)