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 C8DCA430412 for ; Sat, 15 Aug 2020 18:04:33 +0300 (MSK) References: <20200814211442.667099-1-gorcunov@gmail.com> <20200814211442.667099-6-gorcunov@gmail.com> From: Vladislav Shpilevoy Message-ID: <0da9d013-6b94-fc4d-17d4-379dcf51bbed@tarantool.org> Date: Sat, 15 Aug 2020 17:04:32 +0200 MIME-Version: 1.0 In-Reply-To: <20200814211442.667099-6-gorcunov@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [Tarantool-patches] [PATCH v7 5/8] applier: factor out latch locking List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Cyrill Gorcunov , tml Thanks for the patch! On 14.08.2020 23:14, Cyrill Gorcunov wrote: > We will need to reuse this helpers. > > Part-of #5129 > > Signed-off-by: Cyrill Gorcunov > --- > src/box/applier.cc | 43 +++++++++++++++++++++++++++++-------------- > 1 file changed, 29 insertions(+), 14 deletions(-) > > diff --git a/src/box/applier.cc b/src/box/applier.cc > index 98fb87375..60689f6d3 100644 > --- a/src/box/applier.cc > +++ b/src/box/applier.cc > @@ -799,6 +799,29 @@ applier_txn_wal_write_cb(struct trigger *trigger, void *event) > return 0; > } > > +/* > + * In a full mesh topology, the same set of changes > + * may arrive via two concurrently running appliers. > + * Hence we need a latch to strictly order all changes > + * that belong to the same server id. > + */ > +static inline struct latch * > +applier_lock(uint32_t replica_id) > +{ > + struct replica *replica = replica_by_id(replica_id); > + struct latch *latch = (replica ? &replica->order_latch : We usually use != NULL to check if a pointer is not NULL. To emphasize it is not a boolean variable in the code. > + &replicaset.applier.order_latch); > + latch_lock(latch); > + return latch; > +}