[Tarantool-patches] [PATCH] Check schema version after tarantool update

Sergey Voinov sergeiv at tarantool.org
Wed Dec 11 17:48:58 MSK 2019


Some users forget to call box.schema.upgrade() after updating tarantool,
and get stuck with an old schema version until they encounter
some hard to debug problems.

This change checks schema version (stored in box.space._schema) on start
and prints a warning if it doesn't match current tarantool version.

Closes: #4574
---
 issue: https://github.com/tarantool/tarantool/issues/4574
 branch: https://github.com/tarantool/tarantool/compare/servoin/gh-4574-schema-version
 src/box/lua/load_cfg.lua   | 22 +++++++++++++++++
 test/box/cfg.result        | 50 ++++++++++++++++++++++++++++++++++++++
 test/box/cfg.test.lua      | 18 ++++++++++++++
 test/box/lua/cfg_test7.lua |  9 +++++++
 test/box/lua/cfg_test8.lua |  9 +++++++
 5 files changed, 108 insertions(+)
 create mode 100644 test/box/lua/cfg_test7.lua
 create mode 100644 test/box/lua/cfg_test8.lua

diff --git a/src/box/lua/load_cfg.lua b/src/box/lua/load_cfg.lua
index 85617c8f0..5ab41d4a9 100644
--- a/src/box/lua/load_cfg.lua
+++ b/src/box/lua/load_cfg.lua
@@ -555,6 +555,28 @@ local function load_cfg(cfg)
     if not box.cfg.read_only and not box.cfg.replication then
         box.schema.upgrade{auto = true}
     end
+
+    --- Check if schema version matches Tarantool version
+    --- and print warning if it's not (in case user forgot to call box.schema.upgrade())
+    local version = box.space._schema:get{'version'}
+    if version ~= nil then
+        local major = version[2]
+        local minor = version[3]
+        local patch = version[4] or 0
+        local schema_version = string.format("%s.%s.%s", major, minor, patch)
+        local tarantool_version = box.info.version
+        -- Versions are considered identical
+        -- if Tarantool version starts with schema version substring
+        local version_match = tarantool_version:sub(1, #schema_version) == schema_version
+        if not version_match then
+            --- Print the warning
+            local msg = string.format(
+                "Schema version %s doesn't match Tarantool version %s " ..
+                "(consider using box.schema.upgrade())",
+                schema_version, tarantool_version)
+            log.warn(msg)
+        end
+    end
 end
 box.cfg = locked(load_cfg)
 
diff --git a/test/box/cfg.result b/test/box/cfg.result
index 5370bb870..905bc4828 100644
--- a/test/box/cfg.result
+++ b/test/box/cfg.result
@@ -580,3 +580,53 @@ test_run:cmd("cleanup server cfg_tester6")
  | ---
  | - true
  | ...
+
+--
+-- gh-4574: Check schema version after tarantool update
+--
+test_run:cmd('create server cfg_tester7 with script = "box/lua/cfg_test7.lua", workdir="sql/upgrade/2.1.0/"')
+ | ---
+ | - true
+ | ...
+test_run:cmd("start server cfg_tester7")
+ | ---
+ | - true
+ | ...
+--- check that the warning is printed
+version_warning = "Schema version [0-9]%.[0-9]%.[0-9] doesn't match Tarantool version"
+ | ---
+ | ...
+test_run:grep_log('cfg_tester7', version_warning, 1000) ~= nil
+ | ---
+ | - true
+ | ...
+test_run:cmd("stop server cfg_tester7")
+ | ---
+ | - true
+ | ...
+test_run:cmd("cleanup server cfg_tester7")
+ | ---
+ | - true
+ | ...
+
+test_run:cmd('create server cfg_tester8 with script = "box/lua/cfg_test8.lua"')
+ | ---
+ | - true
+ | ...
+test_run:cmd("start server cfg_tester8")
+ | ---
+ | - true
+ | ...
+--- check that the warning is NOT printed
+test_run:grep_log('cfg_tester8', version_warning, 1000) == nil
+ | ---
+ | - true
+ | ...
+test_run:cmd("stop server cfg_tester8")
+ | ---
+ | - true
+ | ...
+test_run:cmd("cleanup server cfg_tester8")
+ | ---
+ | - true
+ | ...
diff --git a/test/box/cfg.test.lua b/test/box/cfg.test.lua
index 56ccb6767..05b7bb53e 100644
--- a/test/box/cfg.test.lua
+++ b/test/box/cfg.test.lua
@@ -141,3 +141,21 @@ test_run:cmd("start server cfg_tester6")
 test_run:grep_log('cfg_tester6', 'set \'vinyl_memory\' configuration option to 1073741824', 1000)
 test_run:cmd("stop server cfg_tester6")
 test_run:cmd("cleanup server cfg_tester6")
+
+--
+-- gh-4574: Check schema version after tarantool update
+--
+test_run:cmd('create server cfg_tester7 with script = "box/lua/cfg_test7.lua", workdir="sql/upgrade/2.1.0/"')
+test_run:cmd("start server cfg_tester7")
+--- check that the warning is printed
+version_warning = "Schema version [0-9]%.[0-9]%.[0-9] doesn't match Tarantool version"
+test_run:grep_log('cfg_tester7', version_warning, 1000) ~= nil
+test_run:cmd("stop server cfg_tester7")
+test_run:cmd("cleanup server cfg_tester7")
+
+test_run:cmd('create server cfg_tester8 with script = "box/lua/cfg_test8.lua"')
+test_run:cmd("start server cfg_tester8")
+--- check that the warning is NOT printed
+test_run:grep_log('cfg_tester8', version_warning, 1000) == nil
+test_run:cmd("stop server cfg_tester8")
+test_run:cmd("cleanup server cfg_tester8")
diff --git a/test/box/lua/cfg_test7.lua b/test/box/lua/cfg_test7.lua
new file mode 100644
index 000000000..c61b86ae3
--- /dev/null
+++ b/test/box/lua/cfg_test7.lua
@@ -0,0 +1,9 @@
+#!/usr/bin/env tarantool
+os = require('os')
+
+box.cfg{
+    listen = os.getenv("LISTEN"),
+    read_only = true
+}
+
+require('console').listen(os.getenv('ADMIN'))
diff --git a/test/box/lua/cfg_test8.lua b/test/box/lua/cfg_test8.lua
new file mode 100644
index 000000000..fa8b303f1
--- /dev/null
+++ b/test/box/lua/cfg_test8.lua
@@ -0,0 +1,9 @@
+#!/usr/bin/env tarantool
+os = require('os')
+
+box.cfg{
+    listen = os.getenv("LISTEN"),
+    read_only = false
+}
+
+require('console').listen(os.getenv('ADMIN'))
-- 
2.17.1



More information about the Tarantool-patches mailing list