[tarantool-patches] [PATCH] Do not enable commit if read_only = true

Georgy Kirichenko georgy at tarantool.org
Wed Feb 27 10:36:00 MSK 2019


Disable commit if server is in read only mode.

Closes: #4016
---
Issue: https://github.com/tarantool/tarantool/issues/4016
Branch: https://github.com/tarantool/tarantool/tree/g.kirichenko/gh-4016-readonly-commit
 src/box/box.cc         |  2 +-
 src/box/box.h          |  3 +++
 src/box/txn.c          |  6 ++++++
 test/box/misc.result   | 19 +++++++++++++++++++
 test/box/misc.test.lua |  8 ++++++++
 5 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/src/box/box.cc b/src/box/box.cc
index 73d94f79b..ec196bcc0 100644
--- a/src/box/box.cc
+++ b/src/box/box.cc
@@ -138,7 +138,7 @@ static struct fiber_pool tx_fiber_pool;
  */
 static struct cbus_endpoint tx_prio_endpoint;
 
-static int
+int
 box_check_writable(void)
 {
 	/* box is only writable if box.cfg.read_only == false and */
diff --git a/src/box/box.h b/src/box/box.h
index 9f5b3acbd..d9e403d7c 100644
--- a/src/box/box.h
+++ b/src/box/box.h
@@ -101,6 +101,9 @@ box_set_ro(bool ro);
 bool
 box_is_ro(void);
 
+int
+box_check_writable(void);
+
 /**
  * Wait until the instance switches to a desired mode.
  * \param ro wait read-only if set or read-write if unset
diff --git a/src/box/txn.c b/src/box/txn.c
index d55d5b93c..769a57a5a 100644
--- a/src/box/txn.c
+++ b/src/box/txn.c
@@ -34,6 +34,7 @@
 #include "journal.h"
 #include <fiber.h>
 #include "xrow.h"
+#include "box.h"
 
 double too_long_threshold;
 
@@ -448,6 +449,11 @@ box_txn_commit()
 	*/
 	if (! txn)
 		return 0;
+	/*
+	 * Check that tarantool didn't switch to ro.
+	 */
+	if (box_check_writable() != 0)
+		return -1;
 	if (txn->in_sub_stmt) {
 		diag_set(ClientError, ER_COMMIT_IN_SUB_STMT);
 		return -1;
diff --git a/test/box/misc.result b/test/box/misc.result
index 699358d53..80dfc4cf7 100644
--- a/test/box/misc.result
+++ b/test/box/misc.result
@@ -1207,3 +1207,22 @@ box.cfg{too_long_threshold = too_long_threshold}
 s:drop()
 ---
 ...
+-- Commit after read_only = true (gh-4016).
+s = box.schema.space.create('test')
+---
+...
+_ = s:create_index('pk')
+---
+...
+box.begin() s:replace({1}) box.cfg{read_only = true} box.commit()
+---
+...
+box.rollback()
+---
+...
+box.cfg{read_only = false}
+---
+...
+s:drop()
+---
+...
diff --git a/test/box/misc.test.lua b/test/box/misc.test.lua
index ee81c7be1..24ad0d1d1 100644
--- a/test/box/misc.test.lua
+++ b/test/box/misc.test.lua
@@ -342,3 +342,11 @@ rows == expected_rows
 lsn == expected_lsn
 box.cfg{too_long_threshold = too_long_threshold}
 s:drop()
+
+-- Commit after read_only = true (gh-4016).
+s = box.schema.space.create('test')
+_ = s:create_index('pk')
+box.begin() s:replace({1}) box.cfg{read_only = true} box.commit()
+box.rollback()
+box.cfg{read_only = false}
+s:drop()
-- 
2.21.0





More information about the Tarantool-patches mailing list