[PATCH 4/8] box: remove orphan check from box_is_ro()

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Wed Aug 8 01:03:47 MSK 2018


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()) {
diff --git a/src/box/box.h b/src/box/box.h
index 9e13378d9..29618c9f8 100644
--- a/src/box/box.h
+++ b/src/box/box.h
@@ -86,6 +86,9 @@ box_atfork(void);
 void
 box_set_ro(bool ro);
 
+bool
+box_is_writable(void);
+
 bool
 box_is_ro(void);
 
diff --git a/src/box/lua/info.c b/src/box/lua/info.c
index d6697df9c..42729bea3 100644
--- a/src/box/lua/info.c
+++ b/src/box/lua/info.c
@@ -242,7 +242,7 @@ lbox_info_signature(struct lua_State *L)
 static int
 lbox_info_ro(struct lua_State *L)
 {
-	lua_pushboolean(L, box_is_ro());
+	lua_pushboolean(L, ! box_is_writable());
 	return 1;
 }
 
-- 
2.15.2 (Apple Git-101.1)




More information about the Tarantool-patches mailing list