Skip to content

Commit 11488e6

Browse files
committed
drivers: unable to take a task with utubettl
Previously, the function incorrectly retrieved the lowest priority task instead of the actual task in the ready buffer. This caused a logical error when the current task had the lowest priority. The implementation error caused: 1. Incorrect selection of the lowest priority task for a take. 2. ready buffer appearing empty when tasks were actually in ready state.
1 parent 0d0f7c6 commit 11488e6

File tree

3 files changed

+50
-8
lines changed

3 files changed

+50
-8
lines changed

CHANGELOG.md

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

1414
### Fixed
1515

16+
- Incorrect choice by priority of task with utubettl driver + ready buffer
17+
mode (#244).
18+
- Unable to take task with utubettl driver + ready buffer mode (#244).
19+
1620
## [1.4.3] - 2024-03-05
1721

1822
The release fixes start of a queue on instances with gaps inside

queue/abstract/driver/utubettl.lua

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,17 @@ end
137137
local function put_ready(self, id, utube, pri)
138138
local taken = self.space.index.utube:min{state.TAKEN, utube}
139139
if taken == nil or taken[i_status] ~= state.TAKEN then
140-
local current_task = self.space.index.utube_pri:min{state.READY, utube}
141-
if current_task[i_status] ~= state.READY or
142-
current_task[i_pri] < pri or (current_task[i_pri] == pri and current_task[i_id] < id) then
143-
return
144-
end
145-
if current_task[i_pri] > pri then
146-
self.space_ready_buffer:delete(current_task[id])
140+
local cur_task = self.space_ready_buffer.index.utube:get{utube}
141+
142+
if cur_task ~= nil then
143+
local cur_id = cur_task[1]
144+
local cur_pri = cur_task[3]
145+
if cur_pri < pri or (cur_pri == pri and cur_id < id) then
146+
return
147+
end
148+
self.space_ready_buffer:delete(cur_id)
147149
end
150+
148151
-- Ignoring ER_TUPLE_FOUND error, if a tuple with the same task_id
149152
-- or utube name is already in the space.
150153
-- Note that both task_id and utube indexes are unique, so there will be

t/040-utubettl.t

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ local yaml = require('yaml')
33
local fiber = require('fiber')
44

55
local test = (require('tap')).test()
6-
test:plan(17)
6+
test:plan(18)
77

88
local queue = require('queue')
99
local state = require('queue.abstract.state')
@@ -208,6 +208,7 @@ test:test('bury in utube', function(test)
208208
test:is(state, 2, 'state was changed')
209209
end
210210
end)
211+
211212
test:test('instant bury', function(test)
212213
if engine ~= 'vinyl' then
213214
test:plan(1 * 2)
@@ -225,6 +226,40 @@ test:test('instant bury', function(test)
225226
test:is(tube_ready:bury(taken[1])[2], '!', 'task is buried')
226227
end
227228
end)
229+
230+
test:test('priority in utube', function(test)
231+
if engine ~= 'vinyl' then
232+
test:plan(8 * 2)
233+
else
234+
test:plan(8)
235+
end
236+
237+
for _, test_tube in ipairs({tube, tube_ready}) do
238+
if test_tube == nil then
239+
break
240+
end
241+
242+
test:ok(test_tube:put(670, {utube = 'dee', pri = 1}), 'task was put')
243+
test:ok(test_tube:put(671, {utube = 'dee', pri = 0}), 'task was put')
244+
245+
local taken = test_tube:take(.1)
246+
test:ok(taken, 'task was taken ' .. taken[1])
247+
test:is(taken[3], 671, 'task.data')
248+
249+
test_tube:release(taken[1])
250+
251+
taken = test_tube:take(.1)
252+
test:ok(taken, 'task was taken ' .. taken[1])
253+
test:is(taken[3], 671, 'task.data')
254+
test_tube:ack(taken[1])
255+
256+
taken = test_tube:take(.1)
257+
test:ok(taken, 'task was taken ' .. taken[1])
258+
test:is(taken[3], 670, 'task.data')
259+
test_tube:ack(taken[1])
260+
end
261+
end)
262+
228263
test:test('release in utube', function(test)
229264
if engine ~= 'vinyl' then
230265
test:plan(8 * 2)

0 commit comments

Comments
 (0)