From f68ef6047a599cf9e6a3665ac369867564d7822f Mon Sep 17 00:00:00 2001 From: Oleg Babin Date: Fri, 20 Mar 2020 14:03:34 +0300 Subject: [PATCH] confapplier: introduce automatic schema upgrade This patch introduces automatic schema upgrade. The main idea to apply box.schema.upgrade on the leader instance. We can't do it on each instance - it lead to replication conflicts. We can't delegate it to users becouse a bug: "Space 277 doesn't exist" (https://github.com/tarantool/tarantool/issues/4691) still is not resolved. Closes #640 --- cartridge/confapplier.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/cartridge/confapplier.lua b/cartridge/confapplier.lua index 78c783cd4..dda30cadf 100644 --- a/cartridge/confapplier.lua +++ b/cartridge/confapplier.lua @@ -246,6 +246,25 @@ local function apply_config(clusterwide_config) return true end +local function cartridge_schema_upgrade(clusterwide_config) + -- This was done in such way for several reasons: + -- * We don't have a way to check is current schema version is latest + -- (https://github.com/tarantool/tarantool/issues/4574) + -- * We run upgrade only on the "leader" instance to prevent replication conflicts + -- * We run upgrade as soon as possible to avoid Tarantool upgrade bugs: + -- (https://github.com/tarantool/tarantool/issues/4691) + -- * Also we do it completely automatically to protect user from the bug + -- mentioned in previous point + local topology_cfg = clusterwide_config:get_readonly('topology') or {} + local instance_uuid = box.info.uuid + local server = topology_cfg.servers[instance_uuid] + local leader_uuid = topology.get_leaders_order(topology_cfg, server.replicaset_uuid)[1] + local is_leader = leader_uuid == instance_uuid + if is_leader then + box.schema.upgrade() + end +end + local function boot_instance(clusterwide_config) checks('ClusterwideConfig') assert(clusterwide_config.locked) @@ -406,6 +425,8 @@ local function boot_instance(clusterwide_config) local read_only = box.cfg.read_only box.cfg({read_only = false}) + cartridge_schema_upgrade(clusterwide_config) + BoxError:pcall( box.schema.user.passwd, username, password