Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: kostja@tarantool.org
Cc: georgy@tarantool.org, tarantool-patches@freelists.org
Subject: [PATCH 3/4] engine: add switch_to_ro callback
Date: Mon,  4 Mar 2019 18:39:26 +0300	[thread overview]
Message-ID: <370f9e62197b7642b89686ed9f38f77c0ee14e68.1551713282.git.vdavydov.dev@gmail.com> (raw)
In-Reply-To: <cover.1551713282.git.vdavydov.dev@gmail.com>
In-Reply-To: <cover.1551713282.git.vdavydov.dev@gmail.com>

We will use this callback to abort rw transactions in Vinyl when an
instance is switch to read-only mode.

Needed for #4016
---
 src/box/blackhole.c    |  1 +
 src/box/box.cc         |  7 +++++++
 src/box/engine.c       | 14 ++++++++++++++
 src/box/engine.h       | 13 +++++++++++++
 src/box/memtx_engine.c |  1 +
 src/box/sysview.c      |  1 +
 src/box/vinyl.c        |  1 +
 7 files changed, 38 insertions(+)

diff --git a/src/box/blackhole.c b/src/box/blackhole.c
index 249eb678..95064e1f 100644
--- a/src/box/blackhole.c
+++ b/src/box/blackhole.c
@@ -184,6 +184,7 @@ static const struct engine_vtab blackhole_engine_vtab = {
 	/* .commit = */ generic_engine_commit,
 	/* .rollback_statement = */ generic_engine_rollback_statement,
 	/* .rollback = */ generic_engine_rollback,
+	/* .switch_to_ro = */ generic_engine_switch_to_ro,
 	/* .bootstrap = */ generic_engine_bootstrap,
 	/* .begin_initial_recovery = */ generic_engine_begin_initial_recovery,
 	/* .begin_final_recovery = */ generic_engine_begin_final_recovery,
diff --git a/src/box/box.cc b/src/box/box.cc
index a6259542..fb896852 100644
--- a/src/box/box.cc
+++ b/src/box/box.cc
@@ -222,6 +222,11 @@ process_nop(struct request *request)
 void
 box_set_ro(bool ro)
 {
+	if (ro == is_ro)
+		return; /* nothing to do */
+	if (ro)
+		engine_switch_to_ro();
+
 	is_ro = ro;
 	fiber_cond_broadcast(&ro_cond);
 }
@@ -252,6 +257,8 @@ box_set_orphan(bool orphan)
 {
 	if (is_orphan == orphan)
 		return; /* nothing to do */
+	if (orphan)
+		engine_switch_to_ro();
 
 	is_orphan = orphan;
 	fiber_cond_broadcast(&ro_cond);
diff --git a/src/box/engine.c b/src/box/engine.c
index d0a08f5c..a52d0ed1 100644
--- a/src/box/engine.c
+++ b/src/box/engine.c
@@ -65,6 +65,14 @@ engine_shutdown(void)
 	}
 }
 
+void
+engine_switch_to_ro(void)
+{
+	struct engine *engine;
+	engine_foreach(engine)
+		engine->vtab->switch_to_ro(engine);
+}
+
 int
 engine_bootstrap(void)
 {
@@ -253,6 +261,12 @@ generic_engine_rollback(struct engine *engine, struct txn *txn)
 	(void)txn;
 }
 
+void
+generic_engine_switch_to_ro(struct engine *engine)
+{
+	(void)engine;
+}
+
 int
 generic_engine_bootstrap(struct engine *engine)
 {
diff --git a/src/box/engine.h b/src/box/engine.h
index a6949d28..a302b3bc 100644
--- a/src/box/engine.h
+++ b/src/box/engine.h
@@ -113,6 +113,12 @@ struct engine_vtab {
 	 */
 	void (*rollback)(struct engine *, struct txn *);
 	/**
+	 * Notify the engine that the instance is about to switch
+	 * to read-only mode. The engine is supposed to abort all
+	 * active rw transactions when this method is called.
+	 */
+	void (*switch_to_ro)(struct engine *);
+	/**
 	 * Bootstrap an empty data directory
 	 */
 	int (*bootstrap)(struct engine *);
@@ -293,6 +299,12 @@ void
 engine_shutdown(void);
 
 /**
+ * Called before switching the instance to read-only mode.
+ */
+void
+engine_switch_to_ro(void);
+
+/**
  * Initialize an empty data directory
  */
 int
@@ -361,6 +373,7 @@ void generic_engine_commit(struct engine *, struct txn *);
 void generic_engine_rollback_statement(struct engine *, struct txn *,
 				       struct txn_stmt *);
 void generic_engine_rollback(struct engine *, struct txn *);
+void generic_engine_switch_to_ro(struct engine *);
 int generic_engine_bootstrap(struct engine *);
 int generic_engine_begin_initial_recovery(struct engine *,
 					  const struct vclock *);
diff --git a/src/box/memtx_engine.c b/src/box/memtx_engine.c
index 049a7f7d..d468d1cd 100644
--- a/src/box/memtx_engine.c
+++ b/src/box/memtx_engine.c
@@ -936,6 +936,7 @@ static const struct engine_vtab memtx_engine_vtab = {
 	/* .commit = */ generic_engine_commit,
 	/* .rollback_statement = */ memtx_engine_rollback_statement,
 	/* .rollback = */ memtx_engine_rollback,
+	/* .switch_to_ro = */ generic_engine_switch_to_ro,
 	/* .bootstrap = */ memtx_engine_bootstrap,
 	/* .begin_initial_recovery = */ memtx_engine_begin_initial_recovery,
 	/* .begin_final_recovery = */ memtx_engine_begin_final_recovery,
diff --git a/src/box/sysview.c b/src/box/sysview.c
index 29de4309..63b669d0 100644
--- a/src/box/sysview.c
+++ b/src/box/sysview.c
@@ -534,6 +534,7 @@ static const struct engine_vtab sysview_engine_vtab = {
 	/* .commit = */ generic_engine_commit,
 	/* .rollback_statement = */ generic_engine_rollback_statement,
 	/* .rollback = */ generic_engine_rollback,
+	/* .switch_to_ro = */ generic_engine_switch_to_ro,
 	/* .bootstrap = */ generic_engine_bootstrap,
 	/* .begin_initial_recovery = */ generic_engine_begin_initial_recovery,
 	/* .begin_final_recovery = */ generic_engine_begin_final_recovery,
diff --git a/src/box/vinyl.c b/src/box/vinyl.c
index 87b9eefa..c8b02eb8 100644
--- a/src/box/vinyl.c
+++ b/src/box/vinyl.c
@@ -4463,6 +4463,7 @@ static const struct engine_vtab vinyl_engine_vtab = {
 	/* .commit = */ vinyl_engine_commit,
 	/* .rollback_statement = */ vinyl_engine_rollback_statement,
 	/* .rollback = */ vinyl_engine_rollback,
+	/* .switch_to_ro = */ generic_engine_switch_to_ro,
 	/* .bootstrap = */ vinyl_engine_bootstrap,
 	/* .begin_initial_recovery = */ vinyl_engine_begin_initial_recovery,
 	/* .begin_final_recovery = */ vinyl_engine_begin_final_recovery,
-- 
2.11.0

  parent reply	other threads:[~2019-03-04 15:39 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-04 15:39 [PATCH 0/4] Abort vinyl transactions before switching to ro Vladimir Davydov
2019-03-04 15:39 ` [PATCH 1/4] vinyl: rename tx statement begin/rollback routines Vladimir Davydov
2019-03-05  7:29   ` Konstantin Osipov
2019-03-04 15:39 ` [PATCH 2/4] vinyl: add tx to writers list in begin_statement engine callback Vladimir Davydov
2019-03-05  7:30   ` Konstantin Osipov
2019-03-04 15:39 ` Vladimir Davydov [this message]
2019-03-05  7:31   ` [PATCH 3/4] engine: add switch_to_ro callback Konstantin Osipov
2019-03-04 15:39 ` [PATCH 4/4] vinyl: abort rw transactions when instance switches to ro Vladimir Davydov
2019-03-05  7:43   ` Konstantin Osipov
2019-03-05  8:35     ` Vladimir Davydov

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=370f9e62197b7642b89686ed9f38f77c0ee14e68.1551713282.git.vdavydov.dev@gmail.com \
    --to=vdavydov.dev@gmail.com \
    --cc=georgy@tarantool.org \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [PATCH 3/4] engine: add switch_to_ro callback' \
    /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