Skip to content

Commit 8fd816c

Browse files
committed
migrations: fix bootstrap on cluster rolling upgrade
1 parent a7c31a1 commit 8fd816c

File tree

2 files changed

+36
-23
lines changed

2 files changed

+36
-23
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [Unreleased]
8+
9+
### Fixed:
10+
- State space bootstrap on cluster rolling upgrade
11+
712
## [1.0.1]
813

914
### Added:

migrator/init.lua

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,27 @@ local function get_server_alias(instance_uri)
9797
return servers[1].alias
9898
end
9999

100+
local function create_space_for_storing_applied_migrations()
101+
box.schema.sequence.create('_migrations_id_seq', { if_not_exists = true })
102+
box.schema.create_space('_migrations', {
103+
format = {
104+
{'id', type='unsigned', is_nullable=false},
105+
{'name', type='string', is_nullable=false},
106+
},
107+
if_not_exists = true,
108+
})
109+
box.space._migrations:create_index('primary', {
110+
sequence = '_migrations_id_seq',
111+
if_not_exists = true,
112+
})
113+
-- Workaround for https://github.com/tarantool/ddl/issues/122
114+
-- If index is created by ddl, sequence is not set. Check and update is required.
115+
if box.space._migrations.index.primary ~= nil
116+
and box.space._migrations.index.primary.sequence_id == nil then
117+
box.space._migrations.index.primary:alter({sequence = '_migrations_id_seq'})
118+
end
119+
end
120+
100121
--- Run migrations on all nodes in the cluster
101122
-- Throws an exception in case of any problems
102123
-- @function up
@@ -290,29 +311,7 @@ local function move_migrations_state(current_server_only)
290311
return migrations_by_alias
291312
end
292313

293-
local function init(opts)
294-
-- Create space for storing applied migrations.
295-
if opts.is_master then
296-
box.schema.sequence.create('_migrations_id_seq', { if_not_exists = true })
297-
box.schema.create_space('_migrations', {
298-
format = {
299-
{'id', type='unsigned', is_nullable=false},
300-
{'name', type='string', is_nullable=false},
301-
},
302-
if_not_exists = true,
303-
})
304-
box.space._migrations:create_index('primary', {
305-
sequence = '_migrations_id_seq',
306-
if_not_exists = true,
307-
})
308-
-- Workaround for https://github.com/tarantool/ddl/issues/122
309-
-- If index is created by ddl, sequence is not set. Check and update is required.
310-
if box.space._migrations.index.primary ~= nil
311-
and box.space._migrations.index.primary.sequence_id == nil then
312-
box.space._migrations.index.primary:alter({sequence = '_migrations_id_seq'})
313-
end
314-
end
315-
314+
local function init()
316315
local httpd = cartridge.service_get('httpd')
317316
if not httpd then return true end
318317

@@ -381,10 +380,19 @@ local function validate_config(conf_new)
381380
return true
382381
end
383382

383+
local function apply_config()
384+
if not box.info().ro then
385+
create_space_for_storing_applied_migrations()
386+
end
387+
388+
return true
389+
end
390+
384391
return {
385392
init = init,
386393

387394
validate_config = validate_config,
395+
apply_config = apply_config,
388396

389397
permanent = true,
390398

0 commit comments

Comments
 (0)