Skip to content

Commit ee75f19

Browse files
committed
drop heap module
This is really happy case because currently we can drop part of crud module (heap) and replace it with a heap that shipped with vshard. Interfaces is not the same but it's easy to fix. Also I want to note that heap is used for an ancient 1.10 version (that didn't support tuple-keydef/tuple-merger modules) and 2.2 that has merger that segfaults. There is no significant benefits to keep our heap implementation if we could use heap directly from vshard.
1 parent 8183c61 commit ee75f19

File tree

5 files changed

+16
-260
lines changed

5 files changed

+16
-260
lines changed

crud-scm-1.rockspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dependencies = {
99
'lua ~> 5.1',
1010
'checks == 3.1.0-1',
1111
'errors == 2.2.1-1',
12-
'vshard == 0.1.17-1',
12+
'vshard >= 0.1.18-1',
1313
}
1414

1515
build = {

crud/common/heap.lua

Lines changed: 0 additions & 118 deletions
This file was deleted.

crud/select/compat/select_old.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ local function build_select_iterator(space_name, user_conditions, opts)
141141
cmp_operator, cmp_key_parts, plan.field_names, space_format
142142
)
143143

144+
local function comparator(node1, node2)
145+
return not tuples_comparator(node1.obj, node2.obj)
146+
end
147+
144148
-- filter space format by plan.field_names (user defined fields + primary key + scan key)
145149
-- to pass it user as metadata
146150
local filtered_space_format, err = utils.get_fields_format(space_format, plan.field_names)
@@ -152,7 +156,7 @@ local function build_select_iterator(space_name, user_conditions, opts)
152156
space_name = space_name,
153157
space_format = filtered_space_format,
154158
iteration_func = select_iteration,
155-
comparator = tuples_comparator,
159+
comparator = comparator,
156160

157161
plan = plan,
158162

crud/select/iterator.lua

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ local utils = require('crud.common.utils')
77
local UpdateTuplesError = errors.new_class('UpdateTuplesError')
88
local GetTupleError = errors.new_class('GetTupleError')
99

10-
local Heap = require('crud.common.heap')
10+
local Heap = require('vshard.heap')
1111

1212
local Iterator = {}
1313
Iterator.__index = Iterator
@@ -48,7 +48,7 @@ function Iterator.new(opts)
4848
tuples_by_replicasets = {},
4949
next_tuple_indexes = {},
5050

51-
heap = Heap.new({ comparator = opts.comparator }),
51+
heap = Heap.new(opts.comparator),
5252
tuples_count = 0,
5353

5454
update_tuples_channel = fiber.channel(1),
@@ -63,7 +63,7 @@ function Iterator.new(opts)
6363
end
6464

6565
function Iterator:has_next()
66-
if self.heap:size() == 0 and self.empty_replicasets_count >= self.replicasets_count then
66+
if self.heap:count() == 0 and self.empty_replicasets_count >= self.replicasets_count then
6767
return false
6868
end
6969

@@ -119,8 +119,9 @@ local function update_replicasets_tuples(iter, after_tuple, replicaset_uuid)
119119
local next_tuple = get_next_replicaset_tuple(iter, replicaset_uuid)
120120

121121
if next_tuple ~= nil then
122-
iter.heap:add(next_tuple, {
123-
replicaset_uuid = replicaset_uuid
122+
iter.heap:push({
123+
obj = next_tuple,
124+
meta = {replicaset_uuid = replicaset_uuid},
124125
})
125126
end
126127
end
@@ -182,9 +183,11 @@ function Iterator:get()
182183
if next_tuple_index <= replicaset_tuples_count then
183184
local next_tuple = get_next_replicaset_tuple(self, last_tuple_replicaset_uuid)
184185

185-
self.heap:add(next_tuple, {
186-
replicaset_uuid = last_tuple_replicaset_uuid
186+
self.heap:push({
187+
obj = next_tuple,
188+
meta = {replicaset_uuid = last_tuple_replicaset_uuid},
187189
})
190+
188191
elseif not self.empty_replicasets[last_tuple_replicaset_uuid] then
189192
self:_update_replicasets_tuples(
190193
tuple,

test/unit/heap_test.lua

Lines changed: 0 additions & 133 deletions
This file was deleted.

0 commit comments

Comments
 (0)