|
| 1 | +local t = require('luatest') |
| 2 | +local vtest = require('test.luatest_helpers.vtest') |
| 3 | +local vutil = require('vshard.util') |
| 4 | + |
| 5 | +local group_config = {{engine = 'memtx'}, {engine = 'vinyl'}} |
| 6 | + |
| 7 | +if vutil.feature.memtx_mvcc then |
| 8 | + table.insert(group_config, { |
| 9 | + engine = 'memtx', memtx_use_mvcc_engine = true |
| 10 | + }) |
| 11 | + table.insert(group_config, { |
| 12 | + engine = 'vinyl', memtx_use_mvcc_engine = true |
| 13 | + }) |
| 14 | +end |
| 15 | + |
| 16 | +local test_group = t.group('storage', group_config) |
| 17 | + |
| 18 | +local cfg_template = { |
| 19 | + sharding = { |
| 20 | + { |
| 21 | + replicas = { |
| 22 | + replica_1_a = { |
| 23 | + master = true, |
| 24 | + }, |
| 25 | + }, |
| 26 | + }, |
| 27 | + { |
| 28 | + replicas = { |
| 29 | + replica_2_a = { |
| 30 | + master = true, |
| 31 | + }, |
| 32 | + }, |
| 33 | + }, |
| 34 | + }, |
| 35 | + bucket_count = 10, |
| 36 | + replication_timeout = 0.1, |
| 37 | +} |
| 38 | +local global_cfg |
| 39 | + |
| 40 | +test_group.before_all(function(g) |
| 41 | + t.run_only_if(vutil.feature.persistent_names) |
| 42 | + cfg_template.memtx_use_mvcc_engine = g.params.memtx_use_mvcc_engine |
| 43 | + global_cfg = vtest.config_new(cfg_template) |
| 44 | + |
| 45 | + vtest.cluster_new(g, global_cfg) |
| 46 | + vtest.cluster_bootstrap(g, global_cfg) |
| 47 | + vtest.cluster_rebalancer_disable(g) |
| 48 | +end) |
| 49 | + |
| 50 | +test_group.after_all(function(g) |
| 51 | + g.cluster:drop() |
| 52 | +end) |
| 53 | + |
| 54 | +test_group.test_named_config_identification = function(g) |
| 55 | + local new_cfg_template = table.deepcopy(cfg_template) |
| 56 | + new_cfg_template.identification_mode = 'name_as_key' |
| 57 | + new_cfg_template.sharding['replicaset_1'] = new_cfg_template.sharding[1] |
| 58 | + new_cfg_template.sharding['replicaset_2'] = new_cfg_template.sharding[2] |
| 59 | + new_cfg_template.sharding[1] = nil |
| 60 | + new_cfg_template.sharding[2] = nil |
| 61 | + local new_global_cfg = vtest.config_new(new_cfg_template) |
| 62 | + |
| 63 | + -- Attempt to configure with named config without name set causes error. |
| 64 | + g.replica_1_a:exec(function(cfg) |
| 65 | + -- Name is not shown in info, when uuid identification is used. |
| 66 | + local info = ivshard.storage.info() |
| 67 | + local rs = info.replicasets[ivutil.replicaset_uuid()] |
| 68 | + ilt.assert_equals(rs.name, nil) |
| 69 | + ilt.assert_equals(rs.master.name, nil) |
| 70 | + ilt.assert_equals(info.identification_mode, 'uuid_as_key') |
| 71 | + ilt.assert_error_msg_contains('Instance name mismatch', |
| 72 | + ivshard.storage.cfg, cfg, 'replica_1_a') |
| 73 | + end, {new_global_cfg}) |
| 74 | + |
| 75 | + -- Set names on all replicas. |
| 76 | + g.replica_1_a:exec(function() |
| 77 | + box.cfg{instance_name = 'replica_1_a', replicaset_name = 'replicaset_1'} |
| 78 | + end) |
| 79 | + g.replica_2_a:exec(function() |
| 80 | + box.cfg{instance_name = 'replica_2_a', replicaset_name = 'replicaset_2'} |
| 81 | + end) |
| 82 | + |
| 83 | + -- Check, that UUIDs are validated, when named config is used. |
| 84 | + local rs_1_cfg = new_global_cfg.sharding.replicaset_1 |
| 85 | + local replica_1_a_cfg = rs_1_cfg.replicas.replica_1_a |
| 86 | + replica_1_a_cfg.uuid = g.replica_2_a:instance_uuid() |
| 87 | + g.replica_1_a:exec(function(cfg) |
| 88 | + ilt.assert_error_msg_contains('Instance UUID mismatch', |
| 89 | + ivshard.storage.cfg, cfg, 'replica_1_a') |
| 90 | + end, {new_global_cfg}) |
| 91 | + -- The correct UUID should be OK. |
| 92 | + replica_1_a_cfg.uuid = g.replica_1_a:instance_uuid() |
| 93 | + |
| 94 | + -- Now the config can be finally applied. |
| 95 | + vtest.cluster_cfg(g, new_global_cfg) |
| 96 | + |
| 97 | + -- Test, that sending by name works properly |
| 98 | + local rs_name_2 = g.replica_2_a:replicaset_name() |
| 99 | + t.assert_equals(rs_name_2, 'replicaset_2') |
| 100 | + g.replica_1_a:exec(function(name) |
| 101 | + -- Name is shown, when name identification is used. |
| 102 | + local info = ivshard.storage.info() |
| 103 | + local rs = info.replicasets[box.info.replicaset.name] |
| 104 | + ilt.assert_equals(rs.name, box.info.replicaset.name) |
| 105 | + ilt.assert_equals(rs.uuid, nil) |
| 106 | + ilt.assert_equals(rs.master.name, box.info.name) |
| 107 | + ilt.assert_equals(info.identification_mode, 'name_as_key') |
| 108 | + |
| 109 | + local bid = _G.get_first_bucket() |
| 110 | + local ok, err = ivshard.storage.bucket_send( |
| 111 | + bid, name, {timeout = _G.iwait_timeout}) |
| 112 | + ilt.assert_equals(err, nil) |
| 113 | + ilt.assert(ok) |
| 114 | + end, {rs_name_2}) |
| 115 | + |
| 116 | + -- Test, that rebalancer is also ok. |
| 117 | + vtest.cluster_rebalancer_enable(g) |
| 118 | + g.replica_1_a:exec(function() |
| 119 | + local internal = ivshard.storage.internal |
| 120 | + ivtest.service_wait_for_new_ok(internal.rebalancer_service, |
| 121 | + {on_yield = ivshard.storage.rebalancer_wakeup}) |
| 122 | + |
| 123 | + -- Cleanup |
| 124 | + _G.bucket_recovery_wait() |
| 125 | + _G.bucket_gc_wait() |
| 126 | + ilt.assert_equals(box.space._bucket:count(), 5) |
| 127 | + end) |
| 128 | + |
| 129 | + g.replica_2_a:exec(function() |
| 130 | + _G.bucket_recovery_wait() |
| 131 | + _G.bucket_gc_wait() |
| 132 | + ilt.assert_equals(box.space._bucket:count(), 5) |
| 133 | + end) |
| 134 | + |
| 135 | + vtest.cluster_rebalancer_disable(g) |
| 136 | + -- Back to UUID identification. |
| 137 | + vtest.cluster_cfg(g, global_cfg) |
| 138 | +end |
0 commit comments