From ae4c96c7cb04d8393831bc7d6a2b377985bb7261 Mon Sep 17 00:00:00 2001 From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> Date: Mon, 16 Jan 2023 23:08:59 +0100 Subject: [PATCH] box: store box.cfg.force_recovery in C box.cfg.force_recovery used to be needed only during box.cfg() in a few places, but its usage is going to extend. In future commits about cluster/replicaset/instance names it will be needed to allow rename. It won't be entirely legal (hence can't be done without any flags), but won't be fully illegal either. The "valid" rename will be after upgrading, when an old cluster updated to a new version and wants to start using the names. Then it will have to set force_recovery, set the names, sync the instances, drop force_recovery. One-time action to allow old installations use the new feature - the names. Part of #5029 NO_DOC=refactoring NO_CHANGELOG=refactoring NO_TEST=already covered --- src/box/box.cc | 27 ++++++++++++++++----------- src/box/box.h | 4 ++++ src/box/lua/cfg.cc | 9 +++++++++ src/box/lua/load_cfg.lua | 2 +- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/box/box.cc b/src/box/box.cc index 5d9d1a1f08..4ea445c371 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -116,6 +116,8 @@ const char *box_ballot_event_key = "internal.ballot"; struct tt_uuid bootstrap_leader_uuid; +bool box_is_force_recovery = false; + /** * Set if backup is in progress, i.e. box_backup_start() was * called but box_backup_stop() hasn't been yet. @@ -2798,6 +2800,12 @@ box_set_vinyl_timeout(void) vinyl_engine_set_timeout(vinyl, cfg_getd("vinyl_timeout")); } +void +box_set_force_recovery(void) +{ + box_is_force_recovery = cfg_geti("force_recovery"); +} + void box_set_net_msg_max(void) { @@ -4238,7 +4246,7 @@ engine_init() */ struct memtx_engine *memtx; memtx = memtx_engine_new_xc(cfg_gets("memtx_dir"), - cfg_geti("force_recovery"), + box_is_force_recovery, cfg_getd("memtx_memory"), cfg_geti("memtx_min_tuple_size"), cfg_geti("strip_core"), @@ -4263,7 +4271,7 @@ engine_init() cfg_geti64("vinyl_memory"), cfg_geti("vinyl_read_threads"), cfg_geti("vinyl_write_threads"), - cfg_geti("force_recovery")); + box_is_force_recovery); engine_register((struct engine *)vinyl); box_set_vinyl_max_tuple_size(); box_set_vinyl_cache(); @@ -4565,12 +4573,8 @@ local_recovery(const struct tt_uuid *instance_uuid, auto stream_guard = make_scoped_guard([&]{ wal_stream_abort(&wal_stream); }); - - struct recovery *recovery; - bool is_force_recovery = cfg_geti("force_recovery"); - recovery = recovery_new(wal_dir(), is_force_recovery, - checkpoint_vclock); - + struct recovery *recovery = recovery_new( + wal_dir(), box_is_force_recovery, checkpoint_vclock); /* * Make sure we report the actual recovery position * in box.info while local recovery is in progress. @@ -4657,7 +4661,7 @@ local_recovery(const struct tt_uuid *instance_uuid, diag_set(XlogError, "found a not finished transaction " "in the log"); wal_stream_abort(&wal_stream); - if (!is_force_recovery) + if (!box_is_force_recovery) diag_raise(); diag_log(); } @@ -4684,7 +4688,7 @@ local_recovery(const struct tt_uuid *instance_uuid, diag_set(XlogError, "found a not finished transaction " "in the log in hot standby mode"); wal_stream_abort(&wal_stream); - if (!is_force_recovery) + if (!box_is_force_recovery) diag_raise(); diag_log(); } @@ -4724,7 +4728,7 @@ local_recovery(const struct tt_uuid *instance_uuid, "recovered data %s", vclock_to_string(&replicaset.vclock), vclock_to_string(&recovery->vclock)); - if (is_force_recovery) { + if (box_is_force_recovery) { say_warn("%s: ignoring, because 'force_recovery' " "configuration option is set.", mismatch_str); vclock_copy(&replicaset.vclock, &recovery->vclock); @@ -4799,6 +4803,7 @@ box_is_configured(void) static void box_cfg_xc(void) { + box_set_force_recovery(); box_storage_init(); title("loading"); diff --git a/src/box/box.h b/src/box/box.h index 1f8f44c648..e582f9c9bc 100644 --- a/src/box/box.h +++ b/src/box/box.h @@ -98,6 +98,9 @@ extern const char *box_ballot_event_key; */ extern struct tt_uuid bootstrap_leader_uuid; +/** box.cfg.force_recovery. */ +extern bool box_is_force_recovery; + /* * Initialize box library * @throws C++ exception @@ -299,6 +302,7 @@ void box_set_vinyl_memory(void); void box_set_vinyl_max_tuple_size(void); void box_set_vinyl_cache(void); void box_set_vinyl_timeout(void); +void box_set_force_recovery(void); int box_set_election_mode(void); int box_set_election_timeout(void); int box_set_election_fencing_mode(void); diff --git a/src/box/lua/cfg.cc b/src/box/lua/cfg.cc index 38ed523915..5812374529 100644 --- a/src/box/lua/cfg.cc +++ b/src/box/lua/cfg.cc @@ -262,6 +262,14 @@ lbox_cfg_set_vinyl_timeout(struct lua_State *L) return 0; } +static int +lbox_cfg_set_force_recovery(struct lua_State *L) +{ + (void)L; + box_set_force_recovery(); + return 0; +} + static int lbox_cfg_set_net_msg_max(struct lua_State *L) { @@ -462,6 +470,7 @@ box_lua_cfg_init(struct lua_State *L) {"cfg_set_vinyl_max_tuple_size", lbox_cfg_set_vinyl_max_tuple_size}, {"cfg_set_vinyl_cache", lbox_cfg_set_vinyl_cache}, {"cfg_set_vinyl_timeout", lbox_cfg_set_vinyl_timeout}, + {"cfg_set_force_recovery", lbox_cfg_set_force_recovery}, {"cfg_set_election_mode", lbox_cfg_set_election_mode}, {"cfg_set_election_timeout", lbox_cfg_set_election_timeout}, {"cfg_set_election_fencing_mode", lbox_cfg_set_election_fencing_mode}, diff --git a/src/box/lua/load_cfg.lua b/src/box/lua/load_cfg.lua index d4f3fae9e0..4a0c0f6e83 100644 --- a/src/box/lua/load_cfg.lua +++ b/src/box/lua/load_cfg.lua @@ -468,7 +468,7 @@ local dynamic_cfg = { custom_proc_title = function() require('title').update(box.cfg.custom_proc_title) end, - force_recovery = nop, + force_recovery = private.cfg_set_force_recovery, election_mode = private.cfg_set_election_mode, election_timeout = private.cfg_set_election_timeout, election_fencing_mode = private.cfg_set_election_fencing_mode, -- GitLab