Skip to content

Commit

Permalink
box: setting names is NoOp before schema 3.0.0
Browse files Browse the repository at this point in the history
Currently it's impossible to recover from the snapshot, which doesn't
have names set in it. This makes upgrading to 3.0.0 difficult and
requires starting Tarantool manually in interactive mode, invoking
box.cfg without names, upgrading schema and setting names manually.

We need to make Tarantool set names automatically, when it's configured
via yaml file. Even with invoking box.cfg two times (without names and
with them) it's impossible to set names before the time, schema is
upgraded. But we consider schema auto-upgrade unacceptable and expect
from users to do it, when they're ready.

So, let's allow setting names in box.cfg on the first configuration
and recover from snaps, which don't have names set. As we cannot apply
such names before schema upgrade, setting names on schema version below
3.0.0 has no effect.

Needed for tarantool#8978

NO_DOC=tarantool/doc#3661
  • Loading branch information
Serpentian committed Sep 27, 2023
1 parent fcb41bb commit edfac67
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 4 deletions.
5 changes: 5 additions & 0 deletions changelogs/unreleased/names-noop-on-previous-schemas.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## bugfix/core

* Setting instance/replicaset/cluster_name on schema version below 3.0.0 is
ignored.

28 changes: 28 additions & 0 deletions src/box/box.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@
#include "node_name.h"
#include "tt_sort.h"

/** Names can be set only with schema >= 3.0.0. */
#define MIN_NAMES_VERSION_ID 196608

static char status[64] = "unconfigured";

/** box.stat rmean */
Expand Down Expand Up @@ -1506,6 +1509,23 @@ box_check_node_name(char *out, const char *cfg_name, bool set_diag)
}
return -1;
}

/**
* If schema version is less then 3.0.0, then we consider setting name
* as NoOp in order to allow painless configuration of Tarantool 3.0
* on the lower schema schema. if dd_version_id == 0, then
* recovery/bootstrap is not done, we can say nothing, allow
* retrieving name.
*/
if (dd_version_id != 0 && dd_version_id < MIN_NAMES_VERSION_ID) {
say_warn("Setting %s was skipped. Please, consider upgrading "
"schema. If you're using yaml configuration names "
"will be automatically set after schema upgrade",
cfg_name);
*out = 0;
return 0;
}

strlcpy(out, name, NODE_NAME_SIZE_MAX);
return 0;
}
Expand Down Expand Up @@ -5396,6 +5416,14 @@ box_cfg_xc(void)
bootstrap(&is_bootstrap_leader);
}
replicaset_state = REPLICASET_READY;
/**
* Check configured name after recovery one more time.
* Otherwise, it might be set to incorrect value, when
* we run on schema version < 3.0.0 and it will block
* reconfiguriation of instance_name in the future.
*/
if (box_check_instance_name(cfg_instance_name) != 0)
diag_raise();

/*
* replicaset.applier.vclock is filled with real
Expand Down
39 changes: 35 additions & 4 deletions test/box-luatest/upgrade_to_3_0_0_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,57 @@ local t = require('luatest')

local g = t.group("Upgrade to 3.0.0")

g.before_all(function(cg)
g.before_each(function(cg)
cg.server = server:new({
datadir = 'test/box-luatest/upgrade/2.11.0',
})
cg.server:start()
cg.server:exec(function()
t.assert_equals(box.space._schema:get{'version'}, {'version', 2, 11, 0})
box.schema.upgrade()
end)
end)

g.after_all(function(cg)
cg.server:drop()
g.after_each(function(cg)
cg.server:stop()
end)

g.test_new_replicaset_uuid_key = function(cg)
cg.server:exec(function()
box.schema.upgrade()
local _schema = box.space._schema
t.assert_equals(_schema:get{'cluster'}, nil)
t.assert_equals(_schema:get{'replicaset_uuid'}.value,
box.info.replicaset.uuid)
end)
end

--
-- Test, that we're able to start with snaps, which doesn't include
-- name in it, but does in cfg. Test, that names are correctly applied
-- after second box.cfg.
--
g.test_start_with_old_snaps = function(cg)
local cfg = {
instance_name = 'instance',
replicaset_name = 'replicaset',
cluster_name = 'cluster',
}

cg.server:restart({box_cfg = cfg})
cg.server:exec(function(cfg)
local info = box.info
t.assert_equals(info.name, nil)
t.assert_equals(info.replicaset.name, nil)
t.assert_equals(info.cluster.name, nil)
box.schema.upgrade()
--
-- After schema upgrade names must be set one more time, if
-- user didn't apply names via config module.
--
box.cfg(cfg)
info = box.info
t.assert_equals(info.name, cfg.instance_name)
t.assert_equals(info.replicaset.name, cfg.replicaset_name)
t.assert_equals(info.cluster.name, cfg.cluster_name)
end, {cfg})
end

0 comments on commit edfac67

Please sign in to comment.