From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Mon, 13 Aug 2018 11:34:30 +0300 From: Vladimir Davydov Subject: Re: [PATCH 4/8] box: remove orphan check from box_is_ro() Message-ID: <20180813083430.ofl75nzppuixwwpa@esperanza> References: <07b102e6b0abd42b550e718fd366927144b0c527.1533679264.git.v.shpilevoy@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <07b102e6b0abd42b550e718fd366927144b0c527.1533679264.git.v.shpilevoy@tarantool.org> To: Vladislav Shpilevoy Cc: tarantool-patches@freelists.org List-ID: On Wed, Aug 08, 2018 at 01:03:47AM +0300, Vladislav Shpilevoy wrote: > Box_is_ro now checks both for 'read_only' and 'orphan' modes, but > in promotion only 'read_only' is needed. And now there is no a > method to get the current 'read_only' value. After replacing > box_is_ro with box_is_writable it is possible to reimplement > box_is_ro as a getter for 'read_only' option. > --- > src/box/box.cc | 10 ++++++++-- > src/box/box.h | 3 +++ > src/box/lua/info.c | 2 +- > 3 files changed, 12 insertions(+), 3 deletions(-) > > diff --git a/src/box/box.cc b/src/box/box.cc > index 6eb358442..d8fbc6252 100644 > --- a/src/box/box.cc > +++ b/src/box/box.cc > @@ -216,17 +216,23 @@ box_set_ro(bool ro) > fiber_cond_broadcast(&ro_cond); > } > > +bool > +box_is_writable(void) > +{ > + return !is_ro && !is_orphan; > +} > + > bool > box_is_ro(void) > { > - return is_ro || is_orphan; > + return is_ro; > } > > int > box_wait_ro(bool ro, double timeout) > { > double deadline = ev_monotonic_now(loop()) + timeout; > - while (box_is_ro() != ro) { > + while (!box_is_writable() != ro) { > if (fiber_cond_wait_deadline(&ro_cond, deadline) != 0) > return -1; > if (fiber_is_cancelled()) { So now we have box_wait_ro() that checks box_is_writable() != box.cfg.read_only and we have box_is_ro() that returns the value of box.cfg.read_only. Looks ugly. I think that the promotion algorithm shouldn't flip box.cfg.read_only. Instead it should use its own flag and box_is_ro() should be defined as bool box_is_ro() { return is_ro || is_oprhan || is_slave; } That would be consistent with the orphan state.