Skip to content

Commit cd9d6ea

Browse files
ligurioTotktonada
authored andcommitted
Revert "Remove support of Tarantool wo tuple-keydef support"
This reverts commit 56247f2. We will remove support of Tarantool version a bit later.
1 parent d029cd7 commit cd9d6ea

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

.github/workflows/test_on_push.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ jobs:
5656
if: github.event_name == 'push'
5757
strategy:
5858
matrix:
59-
bundle_version: [ "1.10.11-0-gf0b0e7ecf-r422", "2.7.3-0-gdddf926c3-r422" ]
59+
# We need 1.10.6 here to check that module works with
60+
# old Tarantool versions that don't have "tuple-keydef"/"tuple-merger" support.
61+
bundle_version: [ "1.10.6-1-g52c786b", "1.10.10-0-gaea7ae77a-r399", "2.7.2-0-g4d8c06890-r399" ]
6062
fail-fast: false
6163
runs-on: [ ubuntu-latest ]
6264
steps:

CHANGELOG.md

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

1010
### Changed
1111

12-
* Remove support of Tarantool versions that have no builtin tuple-keydef
13-
module.
1412
* Tarantool versions 2.{4,5,6} have reached EOL and removed from regression
1513
testing. It means that methods `crud.min()` and `crud.max` won't work for old
1614
versions (< 1.10.8) anymore.

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('BorderError', {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 is_closer = function (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)
@@ -100,7 +112,20 @@ local function call_get_border_on_router(border_name, space_name, index_name, op
100112
end
101113

102114
local compare_sign = border_name == 'max' and 1 or -1
103-
local keydef = Keydef.new(space, field_names, index.id)
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)