Tarantool development patches archive
 help / color / mirror / Atom feed
From: Georgy Kirichenko <georgy@tarantool.org>
To: tarantool-patches@freelists.org
Cc: Georgy Kirichenko <georgy@tarantool.org>
Subject: [tarantool-patches] [PATCH] Do not enable commit if read_only = true
Date: Wed, 27 Feb 2019 10:36:00 +0300	[thread overview]
Message-ID: <bcb57101e3a2e7db30e654db131c22d20f1a561c.1551252637.git.georgy@tarantool.org> (raw)

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

             reply	other threads:[~2019-02-27  7:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-27  7:36 Georgy Kirichenko [this message]
2019-02-27  9:02 ` Vladimir Davydov
2019-02-28 10:25   ` [tarantool-patches] " Konstantin Osipov
2019-03-03 20:49     ` Георгий Кириченко
2019-03-04  9:41       ` Konstantin Osipov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bcb57101e3a2e7db30e654db131c22d20f1a561c.1551252637.git.georgy@tarantool.org \
    --to=georgy@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH] Do not enable commit if read_only = true' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox