diff --git a/src/box/lua/config/applier/sharding.lua b/src/box/lua/config/applier/sharding.lua index f19aaa897219e3cfcbc85684c8d685ebc418d7ed..d2d05af8af5ffbbd05349a2a42b9f028b18d6537 100644 --- a/src/box/lua/config/applier/sharding.lua +++ b/src/box/lua/config/applier/sharding.lua @@ -22,7 +22,9 @@ local function apply(config) local cfg = configdata:sharding() if is_storage then log.info('sharding: apply storage config') - _G.vshard.storage.cfg(cfg, box.info.uuid) + -- Name may be not set in box.info.name, e.g. during names applying. + -- Configure vshard anyway, pass configuration name. + _G.vshard.storage.cfg(cfg, configdata:names().instance_name) end if is_router then log.info('sharding: apply router config') diff --git a/src/box/lua/config/configdata.lua b/src/box/lua/config/configdata.lua index 454cd792866a5a9e38a2fbafa6ff6aba9e7bb40c..e40739b1f1f4525a6b2e4ea2319aaafc96dae1d2 100644 --- a/src/box/lua/config/configdata.lua +++ b/src/box/lua/config/configdata.lua @@ -5,7 +5,6 @@ local fun = require('fun') local urilib = require('uri') -local digest = require('digest') local uuid = require('uuid') local instance_config = require('internal.config.instance_config') local cluster_config = require('internal.config.cluster_config') @@ -71,13 +70,7 @@ function methods.names(self) } end -local function uuid_from_name(str) - local sha = digest.sha1_hex(str) - return sha:sub(1,8)..'-'..sha:sub(9,12)..'-'..sha:sub(13,16)..'-'.. - '00'..sha:sub(17,18)..'-'..sha:sub(19,30) -end - -local function instance_sharding(iconfig, instance_name) +local function instance_sharding(iconfig) local roles = instance_config:get(iconfig, 'sharding.roles') if roles == nil or #roles == 0 then return nil @@ -106,10 +99,11 @@ local function instance_sharding(iconfig, instance_name) u.login = 'guest' uri = urilib.format(u, true) end + local uuid = instance_config:get(iconfig, 'database.instance_uuid') return { uri = uri, + uuid = uuid, zone = zone, - name = instance_name, } end @@ -144,28 +138,20 @@ function methods.sharding(self) table.insert(rebalancers, replicaset_name) end end - local isharding = instance_sharding(iconfig, instance_name) + local isharding = instance_sharding(iconfig) if isharding ~= nil then if replicaset_uuid == nil then replicaset_uuid = instance_config:get(iconfig, 'database.replicaset_uuid') - if replicaset_uuid == nil then - replicaset_uuid = uuid_from_name(replicaset_name) - end - end - local instance_uuid = instance_config:get(iconfig, - 'database.instance_uuid') - if instance_uuid == nil then - instance_uuid = uuid_from_name(instance_name) end - replicaset_cfg[instance_uuid] = isharding + replicaset_cfg[instance_name] = isharding end end if next(replicaset_cfg) ~= nil then - assert(replicaset_uuid ~= nil) - sharding[replicaset_uuid] = { + sharding[replicaset_name] = { rebalancer = is_rebalancer or nil, replicas = replicaset_cfg, + uuid = replicaset_uuid, master = 'auto', lock = lock, } @@ -181,6 +167,7 @@ function methods.sharding(self) sharding = sharding, box_cfg_mode = 'manual', schema_management_mode = 'auto', + identification_mode = 'name_as_key', } local vshard_global_options = { @@ -644,12 +631,6 @@ local function new(iconfig, cconfig, instance_name) 'database.replicaset_uuid') local instance_uuid = instance_config:get(iconfig_def, 'database.instance_uuid') - if replicaset_uuid == nil then - replicaset_uuid = uuid_from_name(found.replicaset_name) - end - if instance_uuid == nil then - instance_uuid = uuid_from_name(instance_name) - end -- Save instance configs of the peers from the same replicaset. local peers = {} diff --git a/test/config-luatest/basic_test.lua b/test/config-luatest/basic_test.lua index 9b1fbdabdcf14033b998492e72e438a2a825b917..2671b3160c3f88bfc63ea8ffdfec1dd4fe6bbd33 100644 --- a/test/config-luatest/basic_test.lua +++ b/test/config-luatest/basic_test.lua @@ -6,6 +6,7 @@ local treegen = require('test.treegen') local justrun = require('test.justrun') local server = require('test.luatest_helpers.server') local helpers = require('test.config-luatest.helpers') +local cbuilder = require('test.config-luatest.cbuilder') local g = helpers.group() @@ -669,3 +670,44 @@ g.test_loader_paths = function(g) t.assert_equals(bar.whoami, 'bar') end) end + +-- Verify, that instance can recover from the xlogs using config. +g.test_recovery_without_uuid = function(g) + local dir = treegen.prepare_directory(g, {}, {}) + local cfg = cbuilder.new() + :add_instance('instance-001', { + database = { + mode = 'rw', + instance_uuid = '22222222-2222-2222-0022-222222222222', + } + }) + :config() + local cfg_file = treegen.write_script(dir, 'config.yaml', yaml.encode(cfg)) + local opts = { + config_file = cfg_file, + chdir = dir, + net_box_credentials = { + user = 'client', + password = 'secret', + }, + } + g.server = server:new(fun.chain(opts, {alias = 'instance-001'}):tomap()) + + -- Initial start. + g.server:start() + g.server:exec(function() + t.assert_equals(box.info.status, 'running') + end) + + -- Remove UUID. Previously generated ones were used, so it wasn't possible + -- to recover from the xlogs without passing UUID to config. + local cfg_rs = cfg.groups['group-001'].replicasets['replicaset-001'] + cfg_rs.instances['instance-001'].database.instance_uuid = nil + cfg_file = treegen.write_script(dir, 'config.yaml', yaml.encode(cfg)) + g.server.config_file = cfg_file + -- Recovery process. + g.server:restart() + g.server:exec(function() + t.assert_equals(box.info.status, 'running') + end) +end diff --git a/test/config-luatest/config_test.lua b/test/config-luatest/config_test.lua index 19fcf966c7aea4388cabc06ec2204a17fad31486..4a9518a534fac761d80406e4cb10fa1792ac8bc0 100644 --- a/test/config-luatest/config_test.lua +++ b/test/config-luatest/config_test.lua @@ -153,8 +153,6 @@ local function verify_configdata() replicaset_name = "replicaset-001", } local res_names = data:names() - res_names.instance_uuid = nil - res_names.replicaset_uuid = nil t.assert_equals(res_names, expected_names) t.assert_equals(data:peers(), {'instance-001', 'instance-002'}) diff --git a/test/config-luatest/vars_test.lua b/test/config-luatest/vars_test.lua index d19856533325adb78982cfb2d7391d300de18b81..878a53234196de38f39e9a309e09d1a58763a5d6 100644 --- a/test/config-luatest/vars_test.lua +++ b/test/config-luatest/vars_test.lua @@ -186,20 +186,9 @@ g.test_sharding = run_as_script(function() }, replicasets = { ['routers-a'] = { - database = { - replicaset_uuid = t.helpers.uuid('f', 0), - }, instances = { - ['router-001'] = { - database = { - instance_uuid = t.helpers.uuid('f', 1), - }, - }, - ['router-002'] = { - database = { - instance_uuid = t.helpers.uuid('f', 2), - }, - }, + ['router-001'] = {}, + ['router-002'] = {}, }, }, }, @@ -210,47 +199,17 @@ g.test_sharding = run_as_script(function() }, replicasets = { ['storages-a'] = { - database = { - replicaset_uuid = t.helpers.uuid('e', 'a', 0), - }, instances = { - ['storage-a-001'] = { - database = { - instance_uuid = t.helpers.uuid('e', 'a', 1), - }, - }, - ['storage-a-002'] = { - database = { - instance_uuid = t.helpers.uuid('e', 'a', 2), - }, - }, - ['storage-a-003'] = { - database = { - instance_uuid = t.helpers.uuid('e', 'a', 3), - }, - }, + ['storage-a-001'] = {}, + ['storage-a-002'] = {}, + ['storage-a-003'] = {}, }, }, ['storages-b'] = { - database = { - replicaset_uuid = t.helpers.uuid('e', 'b', 0), - }, instances = { - ['storage-b-001'] = { - database = { - instance_uuid = t.helpers.uuid('e', 'b', 1), - }, - }, - ['storage-b-002'] = { - database = { - instance_uuid = t.helpers.uuid('e', 'b', 2), - }, - }, - ['storage-b-003'] = { - database = { - instance_uuid = t.helpers.uuid('e', 'b', 3), - }, - }, + ['storage-b-001'] = {}, + ['storage-b-002'] = {}, + ['storage-b-003'] = {}, }, }, }, @@ -269,36 +228,30 @@ g.test_sharding = run_as_script(function() -- Verify URIs of the storages. t.assert_equals(res.sharding, { - [t.helpers.uuid('e', 'a', 0)] = { + ['storages-a'] = { master = 'auto', replicas = { - [t.helpers.uuid('e', 'a', 1)] = { - name = 'storage-a-001', + ['storage-a-001'] = { uri = exp_uri('storages', 'storages-a', 'storage-a-001'), }, - [t.helpers.uuid('e', 'a', 2)] = { - name = 'storage-a-002', + ['storage-a-002'] = { uri = exp_uri('storages', 'storages-a', 'storage-a-002'), }, - [t.helpers.uuid('e', 'a', 3)] = { - name = 'storage-a-003', + ['storage-a-003'] = { uri = exp_uri('storages', 'storages-a', 'storage-a-003'), }, }, }, - [t.helpers.uuid('e', 'b', 0)] = { + ['storages-b'] = { master = 'auto', replicas = { - [t.helpers.uuid('e', 'b', 1)] = { - name = 'storage-b-001', + ['storage-b-001'] = { uri = exp_uri('storages', 'storages-b', 'storage-b-001'), }, - [t.helpers.uuid('e', 'b', 2)] = { - name = 'storage-b-002', + ['storage-b-002'] = { uri = exp_uri('storages', 'storages-b', 'storage-b-002'), }, - [t.helpers.uuid('e', 'b', 3)] = { - name = 'storage-b-003', + ['storage-b-003'] = { uri = exp_uri('storages', 'storages-b', 'storage-b-003'), }, }, diff --git a/test/config-luatest/vshard_test.lua b/test/config-luatest/vshard_test.lua index cd3542cc6b3d341377b4e8b0c8009c8c9e152f1c..84306c3f8106d6da71b87544aba3dc84c0901026 100644 --- a/test/config-luatest/vshard_test.lua +++ b/test/config-luatest/vshard_test.lua @@ -119,6 +119,7 @@ g.test_fixed_masters = function(g) bucket_count = 1234, discovery_mode = "on", failover_ping_timeout = 5, + identification_mode = 'name_as_key', rebalancer_disbalance_threshold = 1, rebalancer_max_receiving = 100, rebalancer_max_sending = 1, @@ -129,41 +130,39 @@ g.test_fixed_masters = function(g) shard_index = "bucket_id", sync_timeout = 1, sharding = { - ["11111111-1111-1111-0011-111111111111"] = { + ["replicaset-001"] = { master = "auto", replicas = { - ["ef10b92d-9ae9-e7bb-004c-89d8fb468341"] = { - name = "instance-002", + ["instance-001"] = { uri = { login = "storage", password = "storage", - uri = "unix/:./instance-002.iproto", + uri = "unix/:./instance-001.iproto", }, }, - ["ffe08155-a26d-bd7c-0024-00ee6815a41c"] = { - name = "instance-001", + ["instance-002"] = { uri = { login = "storage", password = "storage", - uri = "unix/:./instance-001.iproto", + uri = "unix/:./instance-002.iproto", }, }, }, + uuid = "11111111-1111-1111-0011-111111111111", weight = 1, }, - ["d1f75e70-6883-d7fe-0087-e582c9c67543"] = { + ["replicaset-002"] = { master = "auto", replicas = { - ["22222222-2222-2222-0022-222222222222"] = { - name = "instance-003", + ["instance-003"] = { uri = { login = "storage", password = "storage", uri = "unix/:./instance-003.iproto", }, + uuid = "22222222-2222-2222-0022-222222222222", }, - ["50367d8e-488b-309b-001a-138a0c516772"] = { - name = "instance-004", + ["instance-004"] = { uri = { login = "storage", password = "storage", @@ -233,9 +232,9 @@ g.test_fixed_masters = function(g) g.server_5:eval(exec) t.helpers.retrying({timeout = 60}, function() local res = g.server_2:eval([[return box.space.a:select()]]) - t.assert_equals(res, {{800, 800}}) - res = g.server_4:eval([[return box.space.a:select()]]) t.assert_equals(res, {{1, 1}}) + res = g.server_4:eval([[return box.space.a:select()]]) + t.assert_equals(res, {{800, 800}}) end) -- Make sure that the new master is auto-discovered when master is changed. @@ -252,9 +251,9 @@ g.test_fixed_masters = function(g) g.server_5:eval(exec) t.helpers.retrying({timeout = 60}, function() local res = g.server_1:eval([[return box.space.a:select()]]) - t.assert_equals(res, {{799, 799}, {800, 800}}) - res = g.server_3:eval([[return box.space.a:select()]]) t.assert_equals(res, {{1, 1}, {2, 2}}) + res = g.server_3:eval([[return box.space.a:select()]]) + t.assert_equals(res, {{799, 799}, {800, 800}}) end) end @@ -355,42 +354,38 @@ g.test_rebalancer_role = function(g) -- Check vshard config on each instance. local exp = { - ["2ab78dc2-4652-3699-00e4-12df0ae32351"] = { + ["replicaset-001"] = { master = "auto", rebalancer = true, replicas = { - ["ef10b92d-9ae9-e7bb-004c-89d8fb468341"] = { - name = "instance-002", + ["instance-001"] = { uri = { login = "storage", password = "storage", - uri = "unix/:./instance-002.iproto" + uri = "unix/:./instance-001.iproto" }, }, - ["ffe08155-a26d-bd7c-0024-00ee6815a41c"] = { - name = "instance-001", + ["instance-002"] = { uri = { login = "storage", password = "storage", - uri = "unix/:./instance-001.iproto" + uri = "unix/:./instance-002.iproto" }, }, }, weight = 1, }, - ["d1f75e70-6883-d7fe-0087-e582c9c67543"] = { + ["replicaset-002"] = { master = "auto", replicas = { - ["f2974852-9b48-8e24-00ea-d34059bf24fd"] = { - name = "instance-003", + ["instance-003"] = { uri = { login = "storage", password = "storage", uri = "unix/:./instance-003.iproto" }, }, - ["50367d8e-488b-309b-001a-138a0c516772"] = { - name = "instance-004", + ["instance-004"] = { uri = { login = "storage", password = "storage",