Skip to content

Commit 7413c6a

Browse files
committed
fix compatibility with old Tarantool versions
After a15e774 (Introduce crud.min and crud.max) module started to throw an error ``` .../.rocks/share/tarantool/crud/common/compat.lua:20: module 'key_def' not found: ``` Because some 1.10 versions don't have support tuple-keydef module or they didn't installed it near this module. This patch adds a fix that fallbacks such lost souls to lua implemented comparators. Also 1.10.6 EE is added to test process to be able verify changes. Closes #163
1 parent 9719341 commit 7413c6a

File tree

4 files changed

+45
-10
lines changed

4 files changed

+45
-10
lines changed

.github/workflows/test_on_push.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ jobs:
3838
if: github.event_name == 'push'
3939
strategy:
4040
matrix:
41-
bundle_version: [ "1.10.10-0-gaea7ae77a-r399", "2.7.2-0-g4d8c06890-r399" ]
41+
# We need 1.10.6 here to check that module works with
42+
# old Tarantool versions that don't have "tuple-keydef"/"tuple-merger" support.
43+
bundle_version: [ "1.10.6-1-g52c786b", "1.10.10-0-gaea7ae77a-r399", "2.7.2-0-g4d8c06890-r399" ]
4244
fail-fast: false
4345
runs-on: [ ubuntu-latest ]
4446
steps:

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
* Compatibility with Tarantool versions that don't support key_def and merger modules.
13+
1014
## [0.7.0] - 2021-05-27
1115

1216
### Fixed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ install(
3131

3232
# Don't include to rockspec as some Tarantool versions (e.g. 2.2 and 2.3)
3333
# don't have symbols required by "tuple-merger" and "tuple-keydef" modules.
34+
execute_process(
35+
COMMAND bash "-c" "tarantoolctl rocks install tuple-keydef 0.0.2"
36+
)
37+
3438
execute_process(
3539
COMMAND bash "-c" "tarantoolctl rocks install tuple-merger 0.0.1"
3640
)

crud/borders.lua

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ local dev_checks = require('crud.common.dev_checks')
66
local call = require('crud.common.call')
77
local utils = require('crud.common.utils')
88
local schema = require('crud.common.schema')
9-
local Keydef = require('crud.compare.keydef')
9+
local has_keydef, Keydef = pcall(require, 'crud.compare.keydef')
10+
local select_comparators = require('crud.compare.comparators')
1011

1112
local BorderError = errors.new_class('Border', {capture_stack = false})
1213

@@ -44,14 +45,25 @@ function borders.init()
4445
_G._crud.get_border_on_storage = get_border_on_storage
4546
end
4647

47-
local function is_closer(compare_sign, keydef, tuple, res_tuple)
48-
if res_tuple == nil then
49-
return true
50-
end
48+
local is_closer
49+
50+
if has_keydef then
51+
is_closer = function (compare_sign, keydef, tuple, res_tuple)
52+
if res_tuple == nil then
53+
return true
54+
end
5155

52-
local cmp = keydef:compare(tuple, res_tuple)
56+
local cmp = keydef:compare(tuple, res_tuple)
5357

54-
return cmp * compare_sign > 0
58+
return cmp * compare_sign > 0
59+
end
60+
else
61+
is_closer = function (_, comparator, tuple, res_tuple)
62+
if res_tuple == nil then
63+
return true
64+
end
65+
return comparator(tuple, res_tuple)
66+
end
5567
end
5668

5769
local function call_get_border_on_router(border_name, space_name, index_name, opts)
@@ -99,8 +111,21 @@ local function call_get_border_on_router(border_name, space_name, index_name, op
99111
return nil, BorderError:new("Failed to get %s: %s", border_name, err)
100112
end
101113

102-
local keydef = Keydef.new(space, field_names, index.id)
103114
local compare_sign = border_name == 'max' and 1 or -1
115+
local comparator
116+
if has_keydef then
117+
comparator = Keydef.new(space, field_names, index.id)
118+
else
119+
local tarantool_iter
120+
if compare_sign > 0 then
121+
tarantool_iter = box.index.GT
122+
else
123+
tarantool_iter = box.index.LT
124+
end
125+
local key_parts = utils.merge_primary_key_parts(index.parts, primary_index.parts)
126+
local cmp_operator = select_comparators.get_cmp_operator(tarantool_iter)
127+
comparator = select_comparators.gen_tuples_comparator(cmp_operator, key_parts, field_names, space:format())
128+
end
104129

105130
local res_tuple = nil
106131
for _, storage_result in pairs(results) do
@@ -111,7 +136,7 @@ local function call_get_border_on_router(border_name, space_name, index_name, op
111136
end
112137

113138
local tuple = storage_result.res
114-
if tuple ~= nil and is_closer(compare_sign, keydef, tuple, res_tuple) then
139+
if tuple ~= nil and is_closer(compare_sign, comparator, tuple, res_tuple) then
115140
res_tuple = tuple
116141
end
117142
end

0 commit comments

Comments
 (0)