[Tarantool-patches] [PATCH] box: allow upgrading from version 1.6

Serge Petrenko sergepetrenko at tarantool.org
Fri Aug 13 13:47:51 MSK 2021



13.08.2021 10:54, Vladimir Davydov пишет:
> On Fri, Aug 13, 2021 at 02:20:23AM +0300, Serge Petrenko wrote:
>>>> +local function on_init_set_recovery_triggers()
>>>> +    log.info("Recovering snapshot with schema version %s", snap_version)
>>>> +    for _, trig_tbl in ipairs(recovery_triggers) do
>>>> +        if trig_tbl.version >= snap_version then
>>>> +            for space, trig in pairs(trig_tbl.tbl) do
>>>> +                box.space[space]:before_replace(trig)
>>>> +                log.info("Set recovery trigger on space '%s' to comply with "..
>>>> +                         "version %s format", space, trig_tbl.version)
>>>> +            end
>>>> +        end
>>>> +    end
>>>> +end
>>>> +
>>>> +local function set_recovery_triggers(version)
>>>> +    snap_version = version
>>>> +    box.ctl.on_schema_init(on_init_set_recovery_triggers)
>>>> +end
>>> Please don't use a global variable for this - it's bad for encapsulation
>>> and generally make code more difficult to follow. Pass version
>>> explicitly to all functions that need it.
>> I can't do that for an on_schema_init trigger, unfortunately.
>> Am I missing something? Looks like there's no way to pass trigger.data
>> for lua triggers.
> You can capture a value in a lambda:
>
> box.ctl.on_schema_init(function()
>      on_init_set_recover_triggers(snap_version)
> end)
Wow, indeed. Thanks!

I didn't apply that in v2 though, because now I have some places which
modify snap_version (which's now called trig_oldest_version):

local function schema_trig_last(_, tuple)
     ...
     clear_recovery_triggers(version_from_tuple)
     trig_oldest_version = version_from_tuple
end

local function clear_recovery_triggers(up_to_version)
     -- Clear triggers starting from trig_oldest_version up to 
up_to_version.
     ...
end

-- 
Serge Petrenko



More information about the Tarantool-patches mailing list