From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp29.i.mail.ru (smtp29.i.mail.ru [94.100.177.89]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id EF0F04696C3 for ; Mon, 17 Feb 2020 23:57:25 +0300 (MSK) From: Vladislav Shpilevoy Date: Mon, 17 Feb 2020 21:57:20 +0100 Message-Id: <2637883c072d078cf970a90a9d5b21164380ebd1.1581972845.git.v.shpilevoy@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 1/3] upgrade: add missing sys triggers off and erasure List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org, alexander.turenko@tarantool.org, korablev@tarantool.org box.internal.bootstrap() before doing anything turns off system space triggers, because it is likely to do some hard changes violating existing rules. And eliminates data from all system spaces to fill it from the scratch. Each time when a new space is added, its erasure and turning off its triggers should have been called explicitly here. As a result it was not done sometimes, by accident. For example, triggers were not turned off for _sequence_data, _sequence, _space_sequence. Content removal wasn't done for _space_sequence. The patch makes a generic solution which does not require manual patching of trigger manipulation and truncation anymore. The bug was discovered while working on #4771, although it is not related. --- src/box/lua/upgrade.lua | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/src/box/lua/upgrade.lua b/src/box/lua/upgrade.lua index c69b6b543..bd28c1001 100644 --- a/src/box/lua/upgrade.lua +++ b/src/box/lua/upgrade.lua @@ -63,18 +63,21 @@ local function truncate(space) end end +local function foreach_system_space(cb) + local max = box.schema.SYSTEM_ID_MAX + for id, space in pairs(box.space) do + if type(id) == 'number' and + (space.engine == 'memtx' or space.engine == 'vinyl') then + if id > max then + break + end + cb(space) + end + end +end + local function set_system_triggers(val) - box.space._space:run_triggers(val) - box.space._index:run_triggers(val) - box.space._user:run_triggers(val) - box.space._func:run_triggers(val) - box.space._priv:run_triggers(val) - box.space._trigger:run_triggers(val) - box.space._collation:run_triggers(val) - box.space._schema:run_triggers(val) - box.space._cluster:run_triggers(val) - box.space._fk_constraint:run_triggers(val) - box.space._ck_constraint:run_triggers(val) + foreach_system_space(function(s) s:run_triggers(val) end) end -------------------------------------------------------------------------------- @@ -82,20 +85,7 @@ end -------------------------------------------------------------------------------- local function erase() - truncate(box.space._space) - truncate(box.space._index) - truncate(box.space._user) - truncate(box.space._func) - truncate(box.space._priv) - truncate(box.space._sequence_data) - truncate(box.space._sequence) - truncate(box.space._truncate) - truncate(box.space._collation) - truncate(box.space._trigger) - truncate(box.space._schema) - truncate(box.space._cluster) - truncate(box.space._fk_constraint) - truncate(box.space._ck_constraint) + foreach_system_space(function(s) truncate(s) end) end local function create_sysview(source_id, target_id) -- 2.21.1 (Apple Git-122.3)