Skip to content

Commit

Permalink
confapplier: introduce automatic schema upgrade
Browse files Browse the repository at this point in the history
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" (tarantool/tarantool#4691)
still is not resolved.

Closes #640
  • Loading branch information
olegrok committed Mar 20, 2020
1 parent 86b8f18 commit f68ef60
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions cartridge/confapplier.lua
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f68ef60

Please sign in to comment.