Skip to content

Commit 22265f0

Browse files
Satbekvakhov
authored andcommitted
Handle update 2.11 schema on tarantool 3.1 version (#15)
Added support for working in 3.1 with data from 2.11, previously there was an error due to the inability to find the replicasets by name #16 close #16 (cherry picked from commit c9a9400faeb0fcb9e028344fdaae0444f5acabd1)
1 parent eb5b1b7 commit 22265f0

File tree

3 files changed

+434
-4
lines changed

3 files changed

+434
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1313
* `crud.schema` no longer returns `tt` system space `_tt_migrations`.
1414
* Tests of `schema` with Tarantool 3.2+.
1515
* Fixed bad error handling for method `call.single`
16+
* Added support for working in 3.1 with data from 2.11, previously there was an error
17+
due to the inability to find the replicasets by name https://github.com/tarantool/crud-ee/issues/16
1618

1719
## [1.5.2] - 20-05-24
1820

crud/common/vshard_utils.lua

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ local vshard = require('vshard')
55
local vshard_utils = {}
66

77
function vshard_utils.get_self_vshard_replicaset()
8-
local box_info = box.info()
8+
local box_info = vshard_utils.__get_box_info()
99

10-
local ok, storage_info = pcall(vshard.storage.info)
10+
local ok, storage_info = vshard_utils.__get_storage_info()
1111
assert(ok, 'vshard.storage.cfg() must be called first')
1212

13-
if vshard_utils.get_vshard_identification_mode() == 'name_as_key' then
13+
14+
local is_needs_upgrade_2_11 = vshard_utils.is_schema_needs_upgrade_from_2_11()
15+
16+
if vshard_utils.get_vshard_identification_mode() == 'name_as_key' and not is_needs_upgrade_2_11 then
1417
local replicaset_name = box_info.replicaset.name
1518

1619
return replicaset_name, storage_info.replicasets[replicaset_name]
@@ -22,7 +25,30 @@ function vshard_utils.get_self_vshard_replicaset()
2225
replicaset_uuid = box_info.cluster.uuid
2326
end
2427

25-
return replicaset_uuid, storage_info.replicasets[replicaset_uuid]
28+
for _, rep in pairs(storage_info.replicasets) do
29+
if rep.uuid == replicaset_uuid then
30+
return replicaset_uuid, rep
31+
end
32+
end
33+
error(('failed to find replicaset by uuid %s'):format(replicaset_uuid))
34+
end
35+
end
36+
37+
-- for unit tests
38+
function vshard_utils.__get_storage_info()
39+
return pcall(vshard.storage.info)
40+
end
41+
42+
-- for unit tests
43+
function vshard_utils.__get_box_info()
44+
return box.info()
45+
end
46+
47+
function vshard_utils.is_schema_needs_upgrade_from_2_11()
48+
local version_tup = box.space._schema:get({'version'})
49+
local version_str = ("%s.%s"):format(version_tup[2], version_tup[3])
50+
if version_str == "2.11" and box.internal.schema_needs_upgrade() then
51+
return true
2652
end
2753
end
2854

0 commit comments

Comments
 (0)