[Tarantool-patches] [PATCH 1/3] upgrade: add missing sys triggers off and erasure

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Mon Feb 17 23:57:20 MSK 2020


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)



More information about the Tarantool-patches mailing list