Skip to content

Commit e73de47

Browse files
committed
Change clock.monotonic to clock.realtime (see issue #2)
1 parent 3365ea9 commit e73de47

File tree

4 files changed

+67
-18
lines changed

4 files changed

+67
-18
lines changed

rockspecs/xqueue-scm-1.rockspec

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
"Usage of this version was disabled. See issue https://github.com/moonlibs/xqueue/issues/2"
2+
13
package = 'xqueue'
24
version = 'scm-1'
35
source = {
46
url = 'git://github.com/moonlibs/xqueue.git',
5-
branch = 'master',
7+
branch = 'broken',
68
}
79
description = {
810
summary = "Package for loading external lua config",

rockspecs/xqueue-scm-2.rockspec

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package = 'xqueue'
2+
version = 'scm-2'
3+
source = {
4+
url = 'git://github.com/moonlibs/xqueue.git',
5+
branch = 'monofix',
6+
}
7+
description = {
8+
summary = "Package for loading external lua config",
9+
homepage = 'https://github.com/moonlibs/xqueue.git',
10+
license = 'BSD',
11+
}
12+
dependencies = {
13+
'lua >= 5.1'
14+
}
15+
build = {
16+
type = 'builtin',
17+
modules = {
18+
['xqueue'] = 'xqueue.lua'
19+
}
20+
}
21+
22+
-- vim: syntax=lua

rockspecs/xqueue-scm-3.rockspec

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package = 'xqueue'
2+
version = 'scm-3'
3+
source = {
4+
url = 'git://github.com/moonlibs/xqueue.git',
5+
branch = 'master',
6+
}
7+
description = {
8+
summary = "Package for loading external lua config",
9+
homepage = 'https://github.com/moonlibs/xqueue.git',
10+
license = 'BSD',
11+
}
12+
dependencies = {
13+
'lua >= 5.1'
14+
}
15+
build = {
16+
type = 'builtin',
17+
modules = {
18+
['xqueue'] = 'xqueue.lua'
19+
}
20+
}
21+
22+
-- vim: syntax=lua

xqueue.lua

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,16 @@ local clock = require 'clock'
77

88
local tuple_ctype = ffi.typeof(box.tuple.new())
99

10-
-- compat
11-
if not table.clear then
12-
table.clear = function(t)
13-
if type(t) ~= 'table' then
14-
error("bad argument #1 to 'clear' (table expected, got "..(t ~= nil and type(t) or 'no value')..")",2)
15-
end
16-
local count = #t
17-
for i=0, count do t[i]=nil end
18-
return
10+
local monotonic_max_age = 10*365*86400;
11+
12+
local function table_clear(t)
13+
if type(t) ~= 'table' then
14+
error("bad argument #1 to 'clear' (table expected, got "..(t ~= nil and type(t) or 'no value')..")",2)
1915
end
16+
local count = #t
17+
for i=0, count do t[i]=nil end
18+
return
2019
end
21-
-- compat
2220

2321
local function is_array(t)
2422
local gen,param,state = ipairs(t)
@@ -223,7 +221,7 @@ local methods = {}
223221

224222
function M.upgrade(space,opts,depth)
225223
depth = depth or 0
226-
print(string.format("call on xq(%s) + %s", space.name, json.encode(opts)))
224+
log.info("xqueue upgrade(%s,%s)", space.name, json.encode(opts))
227225
if not opts.fields then error("opts.fields required",2) end
228226
if opts.format then
229227
-- todo: check if already have such format
@@ -409,6 +407,12 @@ function M.upgrade(space,opts,depth)
409407
if not runat_index then
410408
error(string.format("fields.runat requires tree index with this first field in it"),2+depth)
411409
else
410+
for _,t in runat_index:pairs({0},{iterator = box.index.GT}) do
411+
if t[ self.fields.runat ] < monotonic_max_age then
412+
error("!!! Queue contains monotonic runat values. Consider updating tasks (https://github.com/moonlibs/xqueue/issues/2)")
413+
end
414+
break
415+
end
412416
have_runat = true
413417
end
414418
end
@@ -445,7 +449,7 @@ function M.upgrade(space,opts,depth)
445449
end
446450
local clock = require 'clock'
447451
gen_id = function()
448-
local key = clock.monotonic64()
452+
local key = clock.realtime64()
449453
while true do
450454
local exists = pk:get(key)
451455
if not exists then
@@ -552,14 +556,13 @@ function M.upgrade(space,opts,depth)
552556
self.space = space.id
553557

554558
function self.timeoffset(delta)
555-
-- return clock.monotonic64() + tonumber64(tonumber(delta) * 1e6)
556-
return clock.monotonic() + tonumber(delta)
559+
return clock.realtime() + tonumber(delta)
557560
end
558561
function self.timeready(time)
559-
return time < clock.monotonic()
562+
return time < clock.realtime()
560563
end
561564
function self.timeremaining(time)
562-
return time - clock.monotonic()
565+
return time - clock.realtime()
563566
end
564567
-- self.NEVER = -1ULL
565568
self.NEVER = 0
@@ -674,7 +677,7 @@ function M.upgrade(space,opts,depth)
674677
end
675678
end
676679

677-
table.clear(collect)
680+
table_clear(collect)
678681

679682
if remaining then
680683
if remaining >= 0 and remaining < 1 then

0 commit comments

Comments
 (0)