diff --git a/test/unit/upgrade.result b/test/unit/upgrade.result index c82208e6..b8ec0292 100644 --- a/test/unit/upgrade.result +++ b/test/unit/upgrade.result @@ -48,7 +48,7 @@ password = 'storage' | --- | ... -schema_bootstrap(user, password) +schema_bootstrap({username = user, password = password}) | --- | ... @@ -169,20 +169,25 @@ for _, handler in pairs(handlers) do table.insert(upgrade_trace, 'Errinj in begin') errinj.ERRINJ_UPGRADE = 'begin' - table.insert(upgrade_trace, - {util.check_error(upgrade, handler.version, user, password)}) + table.insert(upgrade_trace, { + util.check_error(upgrade, handler.version, + {username = user, password = password}) + }) table.insert(upgrade_trace, {diff = stat_update()}) table.insert(upgrade_trace, 'Errinj in end') errinj.ERRINJ_UPGRADE = 'end' - table.insert(upgrade_trace, - {util.check_error(upgrade, handler.version, user, password)}) + table.insert(upgrade_trace, { + util.check_error(upgrade, handler.version, + {usernme = user, password = password}) + }) table.insert(upgrade_trace, {diff = stat_update()}) table.insert(upgrade_trace, 'No errinj') errinj.ERRINJ_UPGRADE = nil - table.insert(upgrade_trace, - {pcall(upgrade, handler.version, user, password)}) + table.insert(upgrade_trace, { + pcall(upgrade, handler.version, {username = user, password = password}) + }) table.insert(upgrade_trace, {diff = stat_update()}) end; | --- diff --git a/test/unit/upgrade.test.lua b/test/unit/upgrade.test.lua index 1fcfb634..9445b78f 100644 --- a/test/unit/upgrade.test.lua +++ b/test/unit/upgrade.test.lua @@ -21,7 +21,7 @@ schema_bootstrap = vshard.storage.internal.schema_bootstrap user = 'storage' password = 'storage' -schema_bootstrap(user, password) +schema_bootstrap({username = user, password = password}) version_make({0, 1, 16, 0}) @@ -107,20 +107,25 @@ for _, handler in pairs(handlers) do table.insert(upgrade_trace, 'Errinj in begin') errinj.ERRINJ_UPGRADE = 'begin' - table.insert(upgrade_trace, - {util.check_error(upgrade, handler.version, user, password)}) + table.insert(upgrade_trace, { + util.check_error(upgrade, handler.version, + {username = user, password = password}) + }) table.insert(upgrade_trace, {diff = stat_update()}) table.insert(upgrade_trace, 'Errinj in end') errinj.ERRINJ_UPGRADE = 'end' - table.insert(upgrade_trace, - {util.check_error(upgrade, handler.version, user, password)}) + table.insert(upgrade_trace, { + util.check_error(upgrade, handler.version, + {usernme = user, password = password}) + }) table.insert(upgrade_trace, {diff = stat_update()}) table.insert(upgrade_trace, 'No errinj') errinj.ERRINJ_UPGRADE = nil - table.insert(upgrade_trace, - {pcall(upgrade, handler.version, user, password)}) + table.insert(upgrade_trace, { + pcall(upgrade, handler.version, {username = user, password = password}) + }) table.insert(upgrade_trace, {diff = stat_update()}) end; diff --git a/vshard/storage/init.lua b/vshard/storage/init.lua index 68bc9eff..dd5e439e 100644 --- a/vshard/storage/init.lua +++ b/vshard/storage/init.lua @@ -800,14 +800,14 @@ end -- The schema first time appeared with 0.1.16. So this function -- describes schema before that - 0.1.15. -local function schema_init_0_1_15_0(username, password) +local function schema_init_0_1_15_0(ctx) log.info("Initializing schema %s", schema_version_make({0, 1, 15, 0})) - box.schema.user.create(username, { - password = password, + box.schema.user.create(ctx.username, { + password = ctx.password, if_not_exists = true, }) -- Replication may has not been granted, if user exists. - box.schema.user.grant(username, 'replication', nil, nil, + box.schema.user.grant(ctx.username, 'replication', nil, nil, {if_not_exists = true}) local bucket = box.schema.space.create('_bucket') @@ -837,13 +837,13 @@ local function schema_init_0_1_15_0(username, password) for _, name in ipairs(storage_api) do box.schema.func.create(name, {setuid = true}) - box.schema.user.grant(username, 'execute', 'function', name) + box.schema.user.grant(ctx.username, 'execute', 'function', name) end box.space._schema:replace({'vshard_version', 0, 1, 15, 0}) end -local function schema_upgrade_to_0_1_16_0(username) +local function schema_upgrade_to_0_1_16_0(ctx) -- Since 0.1.16.0 the old versioning by -- 'oncevshard:storage:' is dropped because it is not -- really extendible nor understandable. @@ -858,7 +858,7 @@ local function schema_upgrade_to_0_1_16_0(username) local func = 'vshard.storage._call' log.info('Create function %s()', func) box.schema.func.create(func, {setuid = true}) - box.schema.user.grant(username, 'execute', 'function', func) + box.schema.user.grant(ctx.username, 'execute', 'function', func) -- Don't drop old functions in the same version. Removal can -- happen only after 0.1.16. Or there should appear support of -- rebalancing from too old versions. Drop of these functions @@ -993,14 +993,14 @@ local schema_upgrade_handlers = { }, } -local function schema_upgrade_master(target_version, username, password) +local function schema_upgrade_master(target_version, ctx) local _schema = box.space._schema local is_old_versioning = _schema:get({'oncevshard:storage:1'}) ~= nil local version = schema_current_version() local is_bootstrap = not box.space._bucket if is_bootstrap then - schema_init_0_1_15_0(username, password) + schema_init_0_1_15_0(ctx) elseif is_old_versioning then log.info("The instance does not have 'vshard_version' record. ".. "It is 0.1.15.0.") @@ -1020,7 +1020,7 @@ local function schema_upgrade_master(target_version, username, password) if errinj == 'begin' then ok, err1 = false, 'Errinj in begin' else - ok, err1 = pcall(handler.upgrade, username) + ok, err1 = pcall(handler.upgrade, ctx) if ok and errinj == 'end' then ok, err1 = false, 'Errinj in end' end @@ -1053,13 +1053,13 @@ local function schema_upgrade_master(target_version, username, password) end end -local function schema_upgrade(is_first_cfg, is_master, username, password) - if is_master then - schema_upgrade_master(schema_latest_version, username, password) +local function schema_upgrade(ctx) + if ctx.is_master then + schema_upgrade_master(schema_latest_version, ctx) -- Core features can only change with Tarantool exe update, which means -- it won't happen on reconfig nor on hot reload. Enough to do it when -- configured first time. - if is_first_cfg then + if ctx.is_first_cfg then schema_upgrade_core_features() end else @@ -3912,7 +3912,13 @@ local function storage_cfg_xc(cfgctx) storage_cfg_services_update() local uri = luri.parse(M.this_replica.uri) - schema_upgrade(is_first_cfg, this_is_master(), uri.login, uri.password) + local upgrade_ctx = { + is_first_cfg = is_first_cfg, + is_master = this_is_master(), + username = uri.login, + password = uri.password, + } + schema_upgrade(upgrade_ctx) -- Check for master specifically. On master _bucket space must exist. -- Because it should have done the schema bootstrap. Shall not ever try to