@@ -7,18 +7,16 @@ local clock = require 'clock'
77
88local 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
2019end
21- -- compat
2220
2321local function is_array (t )
2422 local gen ,param ,state = ipairs (t )
@@ -223,7 +221,7 @@ local methods = {}
223221
224222function 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