From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 9EC3022681 for ; Wed, 27 Feb 2019 02:36:07 -0500 (EST) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NKGljnfY1PW3 for ; Wed, 27 Feb 2019 02:36:07 -0500 (EST) Received: from smtp29.i.mail.ru (smtp29.i.mail.ru [94.100.177.89]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id CED2A224BD for ; Wed, 27 Feb 2019 02:36:06 -0500 (EST) From: Georgy Kirichenko Subject: [tarantool-patches] [PATCH] Do not enable commit if read_only = true Date: Wed, 27 Feb 2019 10:36:00 +0300 Message-Id: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: Georgy Kirichenko 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 #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