From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp29.i.mail.ru (smtp29.i.mail.ru [94.100.177.89]) (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 EF9CA43040C for ; Fri, 4 Sep 2020 11:13:22 +0300 (MSK) References: <89d43ffb6714598c377f0fdcccae61a6ab360409.1599173312.git.v.shpilevoy@tarantool.org> From: Serge Petrenko Message-ID: <48e523a3-0507-0702-c39d-c1ef367a235a@tarantool.org> Date: Fri, 4 Sep 2020 11:13:21 +0300 MIME-Version: 1.0 In-Reply-To: <89d43ffb6714598c377f0fdcccae61a6ab360409.1599173312.git.v.shpilevoy@tarantool.org> Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Transfer-Encoding: 8bit Content-Language: en-GB Subject: Re: [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: Vladislav Shpilevoy , tarantool-patches@dev.tarantool.org, gorcunov@gmail.com 04.09.2020 01:51, Vladislav Shpilevoy пишет: > 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 Hi! Thanks for the patch! > --- > 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) Maybe call it `applier_set_id`? This way it's shorter and resembles `replica_set_id`. > +{ > + /* > + * 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) */ -- Serge Petrenko