From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp53.i.mail.ru (smtp53.i.mail.ru [94.100.177.113]) (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 F0FF146971A for ; Wed, 11 Dec 2019 17:48:57 +0300 (MSK) From: Sergey Voinov Date: Wed, 11 Dec 2019 17:48:58 +0300 Message-Id: <20191211144858.18223-1-sergeiv@tarantool.org> Subject: [Tarantool-patches] [PATCH] Check schema version after tarantool update List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org, 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