From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Wed, 15 Aug 2018 21:47:58 +0300 From: Vladimir Davydov Subject: Re: [PATCH v3/3] replication: handle replication shutdown correctly. Message-ID: <20180815184758.oru4d4nxzgj7ze3p@esperanza> References: <20180815110303.89530-1-sergepetrenko@tarantool.org> <20180815134926.zrs52nxmq3x3sllk@esperanza> <2FE86AFE-AE17-4AB3-A60B-F7CB487E5F85@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2FE86AFE-AE17-4AB3-A60B-F7CB487E5F85@tarantool.org> To: Serge Petrenko Cc: tarantool-patches@freelists.org, Georgy Kirichenko List-ID: On Wed, Aug 15, 2018 at 07:13:28PM +0300, Serge Petrenko wrote: > diff --git a/src/box/replication.cc b/src/box/replication.cc > index 48956d2ed..083ae6407 100644 > --- a/src/box/replication.cc > +++ b/src/box/replication.cc > @@ -91,13 +91,6 @@ replication_init(void) > latch_create(&replicaset.applier.order_latch); > } > > -void > -replication_free(void) > -{ > - free(replicaset.replica_by_id); > - fiber_cond_destroy(&replicaset.applier.cond); > -} > - > void > replica_check_id(uint32_t replica_id) > { > @@ -242,6 +235,42 @@ replica_clear_applier(struct replica *replica) > trigger_clear(&replica->on_applier_state); > } > > +void > +replication_free(void) > +{ > + struct replica *replica, *next; > + > + replica_hash_foreach_safe(&replicaset.hash, replica, next) { > + if (replica->id == instance_id) { > + replica_hash_remove(&replicaset.hash, replica); > + /* > + * Local replica doesn't have neither applier > + * nor relay, so ignore it. > + */ > + continue; > + } > + if (replica->applier != NULL) { > + replica_clear_applier(replica); > + /* > + * We're exiting, so control won't be passed > + * to appliers and we don't need to stop them. > + */ > + } You don't need this code either. I want this loop to be as simple as /* * */ replicaset_foreach(replica) relay_cancel(replica->relay); Then you wouldn't even need to move the definition of replication_free. > + if (replica->id != REPLICA_ID_NIL) { > + /* > + * Relay threads keep sending messages > + * to tx via cbus upon shutdown, which > + * could lead to segfaults. So cancel > + * them. > + */ > + relay_cancel(replica->relay); > + } > + } > + > + free(replicaset.replica_by_id); > + fiber_cond_destroy(&replicaset.applier.cond); > +}