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 because 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 0ec7ec4 commit 42cfca0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

- New internal module to handle `.tar` files.

- Cartridge automatically upgrades schema version.

Lua API:

- `cartridge.cfg({webui_blacklist = {'/admin/code', ...}})`: blacklist
Expand Down
24 changes: 24 additions & 0 deletions cartridge/confapplier.lua
Expand Up @@ -246,6 +246,28 @@ 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]
if server == nil then
return
end
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 +428,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 42cfca0

Please sign in to comment.