Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH] Check schema version after tarantool update
@ 2019-12-11 14:48 Sergey Voinov
  2020-01-14 12:11 ` Sergey Ostanevich
  0 siblings, 1 reply; 2+ messages in thread
From: Sergey Voinov @ 2019-12-11 14:48 UTC (permalink / raw)
  To: tarantool-patches, Alexander Turenko

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Tarantool-patches] [PATCH] Check schema version after tarantool update
  2019-12-11 14:48 [Tarantool-patches] [PATCH] Check schema version after tarantool update Sergey Voinov
@ 2020-01-14 12:11 ` Sergey Ostanevich
  0 siblings, 0 replies; 2+ messages in thread
From: Sergey Ostanevich @ 2020-01-14 12:11 UTC (permalink / raw)
  To: Sergey Voinov; +Cc: tarantool-patches

Hi!

Thanks for the patch! 

> +
> +    --- 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

This is apparently wrong, since according to 
the src/box/lua/upgrade.lua:973 Tarantool of version 1.10.5 (latest
release) has no corresponding upgrade procedure beyond 1.10.2. 
Hence, the schema version will be inconsistent in your check. 

> +        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)

Regards,
Sergos

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-01-14 12:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-11 14:48 [Tarantool-patches] [PATCH] Check schema version after tarantool update Sergey Voinov
2020-01-14 12:11 ` Sergey Ostanevich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox