Skip to content

Commit 3171b1b

Browse files
crud: support vshard identification by name
In vshard 0.1.25, new feature related to vshard configuration and storage info was introduced [1]. If the new mode is used, crud module fails to bootstrap and work in several places. This feature is enabled by Tarantool 3.0 if vshard cluster was configured with 3.0 config. After this patch, it is possible to bootstrap a vshard cluster with new configuration mode. We run all existing vshard tests with new modes after this patch. Module code was updated to support both possible modes. 1. tarantool/vshard#426 Closes #403
1 parent a897f4c commit 3171b1b

File tree

12 files changed

+216
-73
lines changed

12 files changed

+216
-73
lines changed

.github/workflows/test_on_push.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ jobs:
3737
cartridge-version: "2.8.0"
3838
- tarantool-version: "2.11"
3939
metrics-version: "1.0.0"
40-
vshard-version: "0.1.24"
40+
vshard-version: "0.1.25"
4141
- tarantool-version: "2.11"
4242
external-merger-version: "0.0.5"
4343
external-keydef-version: "0.0.4"
4444
- tarantool-version: "master"
4545
metrics-version: "1.0.0"
46-
vshard-version: "0.1.24"
46+
vshard-version: "0.1.25"
4747
fail-fast: false
4848
# Can't install older versions on 22.04,
4949
# see https://github.com/tarantool/setup-tarantool/issues/36
@@ -141,7 +141,7 @@ jobs:
141141
include:
142142
- tarantool-version: "master"
143143
metrics-version: "1.0.0"
144-
vshard-version: "0.1.24"
144+
vshard-version: "0.1.25"
145145
fail-fast: false
146146
runs-on: ubuntu-20.04
147147
steps:

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## Unreleased
9+
10+
### Fixed
11+
* Compatibility with vshard 0.1.25 `name_as_key` identification mode
12+
for Tarantool 3.0 (#403).
13+
814
## [1.4.1] - 23-10-23
915

1016
### Changed

crud.lua

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ local stats = require('crud.stats')
2323
local readview = require('crud.readview')
2424
local schema = require('crud.schema')
2525

26-
local vshard = require('vshard')
2726
local luri = require('uri')
2827

2928
local crud = {}
@@ -174,25 +173,14 @@ function crud.init_storage()
174173

175174
local user = nil
176175
if not box.info.ro then
177-
local ok, storage_info = pcall(vshard.storage.info)
178-
if not ok then
179-
error('vshard.storage.cfg() must be called first')
180-
end
176+
local replicaset_uuid, replicaset = utils.get_self_vshard_replicaset()
181177

182-
local box_info = box.info()
183-
local replicaset_uuid
184-
if box_info.replicaset ~= nil then
185-
replicaset_uuid = box_info.replicaset.uuid
186-
else
187-
replicaset_uuid = box_info.cluster.uuid
188-
end
189-
local replicaset_info = storage_info.replicasets[replicaset_uuid]
190-
if replicaset_info == nil or replicaset_info.master == nil then
178+
if replicaset == nil or replicaset.master == nil then
191179
error(string.format('Failed to find a vshard configuration for ' ..
192180
' replicaset with replicaset_uuid %s.',
193181
replicaset_uuid))
194182
end
195-
user = luri.parse(replicaset_info.master.uri).login or 'guest'
183+
user = luri.parse(replicaset.master.uri).login or 'guest'
196184
end
197185

198186
if rawget(_G, '_crud') == nil then

crud/common/utils.lua

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ function utils.format_replicaset_error(replicaset_uuid, msg, ...)
112112
end
113113

114114
local function get_replicaset_by_replica_uuid(replicasets, uuid)
115-
for replicaset_uuid, replicaset in pairs(replicasets) do
116-
for replica_uuid, _ in pairs(replicaset.replicas) do
117-
if replica_uuid == uuid then
118-
return replicasets[replicaset_uuid]
115+
for _, replicaset in pairs(replicasets) do
116+
for _, replica in pairs(replicaset.replicas) do
117+
if replica.uuid == uuid then
118+
return replicaset
119119
end
120120
end
121121
end
@@ -1143,23 +1143,23 @@ function utils.storage_info(opts)
11431143
local timeout = opts.timeout or const.DEFAULT_VSHARD_CALL_TIMEOUT
11441144

11451145
for _, replicaset in pairs(replicasets) do
1146-
for replica_uuid, replica in pairs(replicaset.replicas) do
1147-
replica_state_by_uuid[replica_uuid] = {
1146+
for _, replica in pairs(replicaset.replicas) do
1147+
replica_state_by_uuid[replica.uuid] = {
11481148
status = "error",
11491149
is_master = replicaset.master == replica
11501150
}
11511151
local ok, res = pcall(replica.conn.call, replica.conn, CRUD_STORAGE_INFO_FUNC_NAME,
11521152
{}, async_opts)
11531153
if ok then
1154-
futures_by_replicas[replica_uuid] = res
1154+
futures_by_replicas[replica.uuid] = res
11551155
else
1156-
local err_msg = string.format("Error getting storage info for %s", replica_uuid)
1156+
local err_msg = string.format("Error getting storage info for %s", replica.uuid)
11571157
if res ~= nil then
11581158
log.error("%s: %s", err_msg, res)
1159-
replica_state_by_uuid[replica_uuid].message = tostring(res)
1159+
replica_state_by_uuid[replica.uuid].message = tostring(res)
11601160
else
11611161
log.error(err_msg)
1162-
replica_state_by_uuid[replica_uuid].message = err_msg
1162+
replica_state_by_uuid[replica.uuid].message = err_msg
11631163
end
11641164
end
11651165
end
@@ -1314,4 +1314,29 @@ function utils.is_cartridge_hotreload_supported()
13141314
return true, cartridge_hotreload
13151315
end
13161316

1317+
function utils.get_self_vshard_replicaset()
1318+
local box_info = box.info()
1319+
1320+
local ok, storage_info = pcall(vshard.storage.info)
1321+
assert(ok, 'vshard.storage.cfg() must be called first')
1322+
1323+
local replicaset_uuid
1324+
if box_info.replicaset ~= nil then
1325+
replicaset_uuid = box_info.replicaset.uuid
1326+
else
1327+
replicaset_uuid = box_info.cluster.uuid
1328+
end
1329+
1330+
local replicaset
1331+
-- Identification key may be name since vshard 0.1.25.
1332+
-- See also https://github.com/tarantool/vshard/issues/460.
1333+
for _, v in pairs(storage_info.replicasets) do
1334+
if v.uuid == replicaset_uuid then
1335+
replicaset = v
1336+
end
1337+
end
1338+
1339+
return replicaset_uuid, replicaset
1340+
end
1341+
13171342
return utils

crud/readview.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,16 +260,16 @@ function Readview_obj:close(opts)
260260

261261
local errors = {}
262262
for _, replicaset in pairs(replicasets) do
263-
for replica_uuid, replica in pairs(replicaset.replicas) do
263+
for _, replica in pairs(replicaset.replicas) do
264264
for _, value in pairs(self._uuid) do
265-
if replica_uuid == value.uuid then
265+
if replica.uuid == value.uuid then
266266
local replica_result, replica_err = replica.conn:call(CRUD_CLOSE_FUNC_NAME,
267267
{self._uuid}, {timeout = opts.timeout})
268268
if replica_err ~= nil then
269269
table.insert(errors, ReadviewError:new("Failed to close Readview on storage: %s", replica_err))
270270
end
271271
if replica_err == nil and (not replica_result) then
272-
table.insert(errors, ReadviewError:new("Readview was not found on storage: %s", replica_uuid))
272+
table.insert(errors, ReadviewError:new("Readview was not found on storage: %s", replica.uuid))
273273
end
274274
end
275275
end

test/helper.lua

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ end
232232

233233
function helpers.get_test_vshard_sharding()
234234
local sharding = {
235-
{
235+
['s-1'] = {
236236
replicas = {
237237
['s1-master'] = {
238238
instance_uuid = helpers.uuid('b', 1),
@@ -243,7 +243,7 @@ function helpers.get_test_vshard_sharding()
243243
},
244244
},
245245
},
246-
{
246+
['s-2'] = {
247247
replicas = {
248248
['s2-master'] = {
249249
instance_uuid = helpers.uuid('c', 1),
@@ -361,12 +361,12 @@ function helpers.get_other_storage_bucket_id(cluster, bucket_id)
361361
362362
local replicasets = vshard.router.routeall()
363363
364-
local other_replicaset_uuid
365-
for replicaset_uuid, replicaset in pairs(replicasets) do
364+
local other_replicaset
365+
for _, replicaset in pairs(replicasets) do
366366
local stat, err = replicaset:callrw('vshard.storage.bucket_stat', {bucket_id})
367367
368368
if err ~= nil and err.name == 'WRONG_BUCKET' then
369-
other_replicaset_uuid = replicaset_uuid
369+
other_replicaset = replicaset
370370
break
371371
end
372372
@@ -378,13 +378,8 @@ function helpers.get_other_storage_bucket_id(cluster, bucket_id)
378378
end
379379
end
380380
381-
if other_replicaset_uuid == nil then
382-
return nil, 'Other replicaset is not found'
383-
end
384-
385-
local other_replicaset = replicasets[other_replicaset_uuid]
386381
if other_replicaset == nil then
387-
return nil, string.format('Replicaset %s not found', other_replicaset_uuid)
382+
return nil, 'Other replicaset is not found'
388383
end
389384
390385
local buckets_info = other_replicaset:callrw('vshard.storage.buckets_info')
@@ -734,7 +729,7 @@ function helpers.start_cluster(g, cartridge_cfg, vshard_cfg)
734729
local cfg = table.deepcopy(vshard_cfg)
735730
cfg.engine = g.params.engine
736731

737-
g.cfg = vtest.config_new(cfg)
732+
g.cfg = vtest.config_new(cfg, g.params.backend_cfg)
738733
vtest.cluster_new(g, g.cfg)
739734
g.cfg.engine = nil
740735
end
@@ -756,14 +751,57 @@ function helpers.get_router(cluster, backend)
756751
end
757752
end
758753

754+
function helpers.parse_module_version(str)
755+
-- https://github.com/tarantool/luatest/blob/f37b353b77be50a1f1ce87c1ff2edf0c1b96d5d1/luatest/utils.lua#L166-L173
756+
local splitstr = str:split('.')
757+
local major = tonumber(splitstr[1]:match('%d+'))
758+
local minor = tonumber(splitstr[2]:match('%d+'))
759+
local patch = tonumber(splitstr[3]:match('%d+'))
760+
return luatest_utils.version(major, minor, patch)
761+
end
762+
763+
function helpers.is_name_supported_as_vshard_id()
764+
local vshard_version = helpers.parse_module_version(require('vshard')._VERSION)
765+
local is_vshard_supports = luatest_utils.version_ge(vshard_version,
766+
luatest_utils.version(0, 1, 25))
767+
768+
local tarantool_version = luatest_utils.get_tarantool_version()
769+
local is_tarantool_supports = luatest_utils.version_ge(tarantool_version,
770+
luatest_utils.version(3, 0, 0))
771+
return is_vshard_supports and is_tarantool_supports
772+
end
773+
759774
function helpers.backend_matrix(base_matrix)
760775
base_matrix = base_matrix or {{}}
761-
local backends = {helpers.backend.VSHARD, helpers.backend.CARTRIDGE}
776+
local backend_params = {
777+
{
778+
backend = helpers.backend.CARTRIDGE,
779+
backend_cfg = nil,
780+
},
781+
}
782+
783+
if helpers.is_name_supported_as_vshard_id() then
784+
table.insert(backend_params, {
785+
backend = helpers.backend.VSHARD,
786+
backend_cfg = {identification_mode = 'uuid_as_key'},
787+
})
788+
table.insert(backend_params, {
789+
backend = helpers.backend.VSHARD,
790+
backend_cfg = {identification_mode = 'name_as_key'},
791+
})
792+
else
793+
table.insert(backend_params, {
794+
backend = helpers.backend.VSHARD,
795+
backend_cfg = nil,
796+
})
797+
end
798+
762799
local matrix = {}
763-
for _, backend in ipairs(backends) do
800+
for _, params in ipairs(backend_params) do
764801
for _, base in ipairs(base_matrix) do
765802
base = table.deepcopy(base)
766-
base.backend = backend
803+
base.backend = params.backend
804+
base.backend_cfg = params.backend_cfg
767805
table.insert(matrix, base)
768806
end
769807
end

test/performance/perf_test.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,23 @@ end
2424

2525
local vshard_cfg_template = {
2626
sharding = {
27-
{
27+
['s-1'] = {
2828
replicas = {
2929
['s1-master'] = {
3030
master = true,
3131
},
3232
['s1-replica'] = {},
3333
},
3434
},
35-
{
35+
['s-2'] = {
3636
replicas = {
3737
['s2-master'] = {
3838
master = true,
3939
},
4040
['s2-replica'] = {},
4141
},
4242
},
43-
{
43+
['s-3'] = {
4444
replicas = {
4545
['s3-master'] = {
4646
master = true,

test/unit/call_test.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ local pgroup = t.group('call', helpers.backend_matrix())
88

99
local vshard_cfg_template = {
1010
sharding = {
11-
{
11+
['s-1'] = {
1212
replicas = {
1313
['s1-master'] = {
1414
master = true,
1515
},
1616
['s1-replica'] = {},
1717
},
1818
},
19-
{
19+
['s-2'] = {
2020
replicas = {
2121
['s2-master'] = {
2222
master = true,

test/unit/not_initialized_test.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ local pgroup = t.group('not-initialized', helpers.backend_matrix({
99

1010
local vshard_cfg_template = {
1111
sharding = {
12-
{
12+
storages = {
1313
replicas = {
1414
storage = {
1515
master = true,

test/unit/stats_test.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ local function enable_stats(g, params)
4545
if params ~= nil then
4646
params = table.deepcopy(params)
4747
params.backend = nil
48+
params.backend_cfg = nil
4849
end
4950
g.router:eval("stats_module.enable(...)", { params })
5051
end

0 commit comments

Comments
 (0)