From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [PATCH 3/4] engine: add switch_to_ro callback Date: Mon, 4 Mar 2019 18:39:26 +0300 Message-Id: <370f9e62197b7642b89686ed9f38f77c0ee14e68.1551713282.git.vdavydov.dev@gmail.com> In-Reply-To: References: In-Reply-To: References: To: kostja@tarantool.org Cc: georgy@tarantool.org, tarantool-patches@freelists.org List-ID: 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