From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp39.i.mail.ru (smtp39.i.mail.ru [94.100.177.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id D6DDB469711 for ; Fri, 29 May 2020 18:12:55 +0300 (MSK) From: sergeyb@tarantool.org Date: Fri, 29 May 2020 18:09:04 +0300 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v6 06/25] Fix luacheck warnings in src/box/lua/ List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org, v.shpilevoy@tarantool.org, imun@tarantool.org Cc: o.piskunov@tarantool.org, alexander.turenko@tarantool.org From: Sergey Bronnikov Part of #4681 Reviewed-by: Vladislav Shpilevoy Co-authored-by: Vladislav Shpilevoy --- .luacheckrc | 9 +++++- src/box/lua/console.lua | 6 ++-- src/box/lua/feedback_daemon.lua | 2 +- src/box/lua/key_def.lua | 2 +- src/box/lua/load_cfg.lua | 31 +++++++++---------- src/box/lua/net_box.lua | 55 +++++++++++++-------------------- src/box/lua/schema.lua | 50 +++++++++++++++--------------- src/box/lua/tuple.lua | 8 ++--- src/box/lua/upgrade.lua | 19 ++++++------ 9 files changed, 87 insertions(+), 95 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index 4d95f2729..03a51ba3e 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -5,6 +5,7 @@ include_files = { exclude_files = { "build/**/*.lua", + "src/box/lua/serpent.lua", -- third-party source code "test/app/*.lua", "test/app-tap/lua/serializer_test.lua", "test/box/**/*.lua", @@ -28,7 +29,13 @@ files["extra/dist/tarantoolctl.in"] = { globals = {"box", "_TARANTOOL"}, ignore = {"212/self", "122", "431"} } -files["src/lua/*.lua"] = {ignore = {"212/self"}} +files["**/*.lua"] = { + globals = {"box", "_TARANTOOL"}, + ignore = {"212/self", "143"} +} files["src/lua/help.lua"] = {globals = {"help", "tutorial"}} files["src/lua/init.lua"] = {globals = {"dostring", "os", "package"}} files["src/lua/swim.lua"] = {ignore = {"431"}} +files["src/box/lua/console.lua"] = {globals = {"help"}, ignore = {"212"}} +files["src/box/lua/net_box.lua"] = {globals = {"bit"}, ignore = {"431", "432"}} +files["src/box/lua/schema.lua"] = {globals = {"tonumber64"}, ignore = {"431", "432"}} diff --git a/src/box/lua/console.lua b/src/box/lua/console.lua index 2add9a79d..5fd8b5e4e 100644 --- a/src/box/lua/console.lua +++ b/src/box/lua/console.lua @@ -465,7 +465,7 @@ local text_connection_mt = { -- Make sure it is exactly "\set output" command. if operators[items[1]] == set_param and param_handlers[items[2]] == set_output then - local err, fmt, opts = parse_output(items[3]) + local err, fmt = parse_output(items[3]) if not err then self.fmt = fmt self.eos = output_eos[fmt] @@ -489,7 +489,7 @@ local text_connection_mt = { break end if fmt == "yaml" then - local handle, prefix = yaml.decode(rc, {tag_only = true}) + local handle = yaml.decode(rc, {tag_only = true}) if not handle then -- Can not fail - tags are encoded with no -- user participation and are correct always. @@ -869,7 +869,7 @@ local function listen(uri) host = u.host port = u.service or 3313 end - local s, addr = socket.tcp_server(host, port, { handler = client_handler, + local s = socket.tcp_server(host, port, { handler = client_handler, name = 'console'}) if not s then error(string.format('failed to create server %s:%s: %s', diff --git a/src/box/lua/feedback_daemon.lua b/src/box/lua/feedback_daemon.lua index 95130d696..db74f558b 100644 --- a/src/box/lua/feedback_daemon.lua +++ b/src/box/lua/feedback_daemon.lua @@ -61,7 +61,7 @@ local function guard_loop(self) self.fiber = fiber.create(feedback_loop, self) log.verbose("%s restarted", PREFIX) end - local st, err = pcall(fiber.sleep, self.interval) + local st = pcall(fiber.sleep, self.interval) if not st then -- fiber was cancelled break diff --git a/src/box/lua/key_def.lua b/src/box/lua/key_def.lua index 586005709..a1b61441e 100644 --- a/src/box/lua/key_def.lua +++ b/src/box/lua/key_def.lua @@ -15,5 +15,5 @@ ffi.metatype(key_def_t, { __index = function(self, key) return methods[key] end, - __tostring = function(key_def) return "" end, + __tostring = function() return "" end, }) diff --git a/src/box/lua/load_cfg.lua b/src/box/lua/load_cfg.lua index 5d818addf..bb00e71ee 100644 --- a/src/box/lua/load_cfg.lua +++ b/src/box/lua/load_cfg.lua @@ -36,7 +36,7 @@ local ifdef_feedback_set_params = private.feedback_daemon.set_feedback_params or nil -- all available options -local default_cfg = { +local default_config = { listen = nil, memtx_memory = 256 * 1024 *1024, strip_core = true, @@ -101,7 +101,7 @@ local default_cfg = { -- types of available options -- could be comma separated lua types or 'any' if any type is allowed -local template_cfg = { +local template_config = { listen = 'string, number', memtx_memory = 'number', strip_core = 'boolean', @@ -184,7 +184,7 @@ local function normalize_uri_list(port_list) end -- options that require special handling -local modify_cfg = { +local modify_config = { listen = normalize_uri, replication = normalize_uri_list, } @@ -272,8 +272,8 @@ local dynamic_cfg = { sql_cache_size = private.cfg_set_sql_cache_size, } -ifdef_feedback = nil -ifdef_feedback_set_params = nil +ifdef_feedback = nil -- luacheck: ignore +ifdef_feedback_set_params = nil -- luacheck: ignore -- -- For some options it is important in which order they are set. @@ -352,7 +352,7 @@ end -- value of the old option, value of the new if present. It -- returns two values - value to replace the old option and to -- replace the new one. -local translate_cfg = { +local translate_config = { snapshot_count = {'checkpoint_count'}, snapshot_period = {'checkpoint_interval'}, slab_alloc_arena = {'memtx_memory', function(old) @@ -431,7 +431,7 @@ local function prepare_cfg(cfg, default_cfg, template_cfg, modify_cfg, prefix) elseif v == "" or v == nil then -- "" and NULL = ffi.cast('void *', 0) set option to default value v = default_cfg[k] - elseif template_cfg[k] == 'any' then + elseif template_cfg[k] == 'any' then -- luacheck: ignore -- any type is ok elseif type(template_cfg[k]) == 'table' then if type(v) ~= 'table' then @@ -447,7 +447,6 @@ local function prepare_cfg(cfg, default_cfg, template_cfg, modify_cfg, prefix) else local good_types = string.gsub(template_cfg[k], ' ', ''); if (string.find(',' .. good_types .. ',', ',' .. type(v) .. ',') == nil) then - good_types = string.gsub(good_types, ',', ', '); box.error(box.error.CFG, readable_name, "should be one of types ".. template_cfg[k]) end @@ -490,8 +489,8 @@ local function compare_cfg(cfg1, cfg2) end local function reload_cfg(oldcfg, cfg) - cfg = upgrade_cfg(cfg, translate_cfg) - local newcfg = prepare_cfg(cfg, default_cfg, template_cfg, modify_cfg) + cfg = upgrade_cfg(cfg, translate_config) + local newcfg = prepare_cfg(cfg, default_config, template_config, modify_config) local ordered_cfg = {} -- iterate over original table because prepare_cfg() may store NILs for key, val in pairs(cfg) do @@ -544,16 +543,16 @@ for k, v in pairs(box) do end setmetatable(box, { - __index = function(table, index) + __index = function() error(debug.traceback("Please call box.cfg{} first")) error("Please call box.cfg{} first") end }) local function load_cfg(cfg) - cfg = upgrade_cfg(cfg, translate_cfg) - cfg = prepare_cfg(cfg, default_cfg, template_cfg, modify_cfg) - apply_default_cfg(cfg, default_cfg); + cfg = upgrade_cfg(cfg, translate_config) + cfg = prepare_cfg(cfg, default_config, template_config, modify_config) + apply_default_cfg(cfg, default_config); -- Save new box.cfg box.cfg = cfg if not pcall(private.cfg_check) then @@ -568,7 +567,7 @@ local function load_cfg(cfg) box_configured = nil box.cfg = setmetatable(cfg, { - __newindex = function(table, index) + __newindex = function() error('Attempt to modify a read-only table') end, __call = locked(reload_cfg), @@ -580,7 +579,7 @@ local function load_cfg(cfg) if not dynamic_cfg_skip_at_load[key] then fun() end - if not compare_cfg(val, default_cfg[key]) then + if not compare_cfg(val, default_config[key]) then if log_cfg_option[key] ~= nil then val = log_cfg_option[key](val) end diff --git a/src/box/lua/net_box.lua b/src/box/lua/net_box.lua index 9560bfdd4..ae75d5b7a 100644 --- a/src/box/lua/net_box.lua +++ b/src/box/lua/net_box.lua @@ -39,10 +39,6 @@ local IPROTO_STATUS_KEY = 0x00 local IPROTO_ERRNO_MASK = 0x7FFF local IPROTO_SYNC_KEY = 0x01 local IPROTO_SCHEMA_VERSION_KEY = 0x05 -local IPROTO_METADATA_KEY = 0x32 -local IPROTO_SQL_INFO_KEY = 0x42 -local SQL_INFO_ROW_COUNT_KEY = 0 -local IPROTO_FIELD_NAME_KEY = 0 local IPROTO_DATA_KEY = 0x30 local IPROTO_ERROR_24 = 0x31 local IPROTO_ERROR = 0x52 @@ -68,18 +64,18 @@ error_unref(struct error *e); -- utility tables local is_final_state = {closed = 1, error = 1} -local function decode_nil(raw_data, raw_data_end) +local function decode_nil(raw_data, raw_data_end) -- luacheck: no unused args return nil, raw_data_end end local function decode_data(raw_data) local response, raw_end = decode(raw_data) return response[IPROTO_DATA_KEY], raw_end end -local function decode_tuple(raw_data, raw_data_end, format) +local function decode_tuple(raw_data, raw_data_end, format) -- luacheck: no unused args local response, raw_end = internal.decode_select(raw_data, nil, format) return response[1], raw_end end -local function decode_get(raw_data, raw_data_end, format) +local function decode_get(raw_data, raw_data_end, format) -- luacheck: no unused args local body, raw_end = internal.decode_select(raw_data, nil, format) if body[2] then return nil, raw_end, box.error.MORE_THAN_ONE_TUPLE @@ -122,7 +118,7 @@ local method_encoder = { max = internal.encode_select, count = internal.encode_call, -- inject raw data into connection, used by console and tests - inject = function(buf, id, bytes) + inject = function(buf, id, bytes) -- luacheck: no unused args local ptr = buf:reserve(#bytes) ffi.copy(ptr, bytes, #bytes) buf.wpos = ptr + #bytes @@ -187,7 +183,7 @@ local function next_id(id) return band(id + 1, 0x7FFFFFFF) end -- @retval two non-nils A connected socket and a decoded greeting. -- local function establish_connection(host, port, timeout) - local timeout = timeout or DEFAULT_CONNECT_TIMEOUT + timeout = timeout or DEFAULT_CONNECT_TIMEOUT local begin = fiber.clock() local s = socket.tcp_connect(host, port, timeout) if not s then @@ -212,7 +208,7 @@ end -- Default action on push during a synchronous request - -- ignore. -- -local function on_push_sync_default(...) end +local function on_push_sync_default() end -- -- Basically, *transport* is a TCP connection speaking one of @@ -253,7 +249,7 @@ local function on_push_sync_default(...) end -- -- The following events are delivered, with arguments: -- --- 'state_changed', state, errno, error +-- 'state_changed', state, error -- 'handshake', greeting -> nil (accept) / errno, error (reject) -- 'will_fetch_schema' -> true (approve) / false (skip fetch) -- 'did_fetch_schema', schema_version, spaces, indices @@ -449,7 +445,7 @@ local function create_transport(host, port, user, password, callback, state = new_state last_errno = new_errno last_error = new_error - callback('state_changed', new_state, new_errno, new_error) + callback('state_changed', new_state, new_error) state_cond:broadcast() if state == 'error' or state == 'error_reconnect' or state == 'closed' then @@ -598,7 +594,7 @@ local function create_transport(host, port, user, password, callback, -- Handle errors requests[id] = nil request.id = nil - local map_len, key, skip + local map_len, key map_len, body_rpos = decode_map_header(body_rpos, body_len) -- Reserve for 2 keys and 2 array indexes. Because no -- any guarantees how Lua will decide to save the @@ -610,7 +606,7 @@ local function create_transport(host, port, user, password, callback, if rdec then body[key], body_rpos = rdec(body_rpos) else - skip, body_rpos = decode(body_rpos) + _, body_rpos = decode(body_rpos) end end assert(body_end == body_rpos, "invalid xrow length") @@ -689,7 +685,7 @@ local function create_transport(host, port, user, password, callback, local function send_and_recv_iproto(timeout) local data_len = recv_buf.wpos - recv_buf.rpos - local required = 0 + local required if data_len < 5 then required = 5 else @@ -753,7 +749,8 @@ local function create_transport(host, port, user, password, callback, "please use require('console').connect() instead") local setup_delimiter = 'require("console").delimiter("$EOF$")\n' method_encoder.inject(send_buf, nil, setup_delimiter) - local err, response = send_and_recv_console() + local response + err, response = send_and_recv_console() if err then return error_sm(err, response) elseif response ~= '---\n...\n' then @@ -771,7 +768,6 @@ local function create_transport(host, port, user, password, callback, end console_sm = function(rid) - local delim = '\n...\n' local err, response = send_and_recv_console() if err then return error_sm(err, response) @@ -795,13 +791,12 @@ local function create_transport(host, port, user, password, callback, return iproto_schema_sm() end encode_auth(send_buf, new_request_id(), user, password, salt) - local err, hdr, body_rpos, body_end = send_and_recv_iproto() + local err, hdr, body_rpos = send_and_recv_iproto() if err then return error_sm(err, hdr) end if hdr[IPROTO_STATUS_KEY] ~= 0 then - local body - body, body_end = decode(body_rpos) + local body = decode(body_rpos) return error_sm(E_NO_CONNECTION, body[IPROTO_ERROR_24]) end set_state('fetch_schema') @@ -852,8 +847,7 @@ local function create_transport(host, port, user, password, callback, peer_has_vcollation = false goto continue end - local body - body, body_end = decode(body_rpos) + local body = decode(body_rpos) return error_sm(E_NO_CONNECTION, body[IPROTO_ERROR_24]) end if schema_version == nil then @@ -862,8 +856,7 @@ local function create_transport(host, port, user, password, callback, -- schema changed while fetching schema; restart loader return iproto_schema_sm() end - local body - body, body_end = decode(body_rpos) + local body = decode(body_rpos) response[id] = body[IPROTO_DATA_KEY] end ::continue:: @@ -880,14 +873,11 @@ local function create_transport(host, port, user, password, callback, local err, hdr, body_rpos, body_end = send_and_recv_iproto() if err then return error_sm(err, hdr) end dispatch_response_iproto(hdr, body_rpos, body_end) - local status = hdr[IPROTO_STATUS_KEY] local response_schema_version = hdr[IPROTO_SCHEMA_VERSION_KEY] if response_schema_version > 0 and response_schema_version ~= schema_version then -- schema_version has been changed - start to load a new version. -- Sic: self.schema_version will be updated only after reload. - local body - body, body_end = decode(body_rpos) set_state('fetch_schema') return iproto_schema_sm(schema_version) end @@ -926,7 +916,7 @@ end -- Now it is necessary to have a strong ref to callback somewhere or -- it is GC-ed prematurely. We wrap stop() method, stashing the -- ref in an upvalue (stop() performance doesn't matter much.) -local create_transport = function(host, port, user, password, callback, +local create_transport = function(host, port, user, password, callback, -- luacheck: ignore connection, greeting) local weak_refs = setmetatable({callback = callback}, {__mode = 'v'}) local function weak_callback(...) @@ -1004,7 +994,7 @@ local function new_sm(host, port, opts, connection, greeting) local remote = {host = host, port = port, opts = opts, state = 'initial'} local function callback(what, ...) if what == 'state_changed' then - local state, errno, err = ... + local state, err = ... local was_connected = remote._is_connected if state == 'active' then if not was_connected then @@ -1275,7 +1265,7 @@ function remote_methods:execute(query, parameters, sql_opts, netbox_opts) sql_opts or {}) end -function remote_methods:prepare(query, parameters, sql_opts, netbox_opts) +function remote_methods:prepare(query, parameters, sql_opts, netbox_opts) -- luacheck: no unused args check_remote_arg(self, "prepare") if type(query) ~= "string" then box.error(box.error.SQL_PREPARE, "expected string as SQL statement") @@ -1640,7 +1630,7 @@ this_module.self = { timeout = function(self) return self end, wait_connected = function(self) return true end, is_connected = function(self) return true end, - call = function(_box, proc_name, args, opts) + call = function(_box, proc_name, args) check_remote_arg(_box, 'call') check_call_args(args) args = args or {} @@ -1651,14 +1641,13 @@ this_module.self = { rollback() return box.error() -- re-throw end - local result if obj ~= nil then return handle_eval_result(pcall(proc, obj, unpack(args))) else return handle_eval_result(pcall(proc, unpack(args))) end end, - eval = function(_box, expr, args, opts) + eval = function(_box, expr, args) check_remote_arg(_box, 'eval') check_eval_args(args) args = args or {} diff --git a/src/box/lua/schema.lua b/src/box/lua/schema.lua index cdfbb65f7..811cbbfef 100644 --- a/src/box/lua/schema.lua +++ b/src/box/lua/schema.lua @@ -2,7 +2,6 @@ -- local ffi = require('ffi') local msgpack = require('msgpack') -local msgpackffi = require('msgpackffi') local fun = require('fun') local log = require('log') local buffer = require('buffer') @@ -212,7 +211,7 @@ local function revoke_object_privs(object_type, object_id) local _vpriv = box.space[box.schema.VPRIV_ID] local _priv = box.space[box.schema.PRIV_ID] local privs = _vpriv.index.object:select{object_type, object_id} - for k, tuple in pairs(privs) do + for _, tuple in pairs(privs) do local uid = tuple.grantee _priv:delete{uid, object_type, object_id} end @@ -262,7 +261,7 @@ local function check_param_table(table, template) if template[k] == nil then box.error(box.error.ILLEGAL_PARAMS, "unexpected option '" .. k .. "'") - elseif template[k] == 'any' then + elseif template[k] == 'any' then -- luacheck: ignore -- any type is ok elseif (string.find(template[k], ',') == nil) then -- one type @@ -276,7 +275,6 @@ local function check_param_table(table, template) local haystack = ',' .. good_types .. ',' local needle = ',' .. param_type(v) .. ',' if (string.find(haystack, needle) == nil) then - good_types = string.gsub(good_types, ',', ', ') box.error(box.error.ILLEGAL_PARAMS, "options parameter '" .. k .. "' should be one of types: " .. template[k]) @@ -584,9 +582,9 @@ end -- local function format_field_resolve(format, path, what) assert(type(path) == 'number' or type(path) == 'string') - local idx = nil + local idx local relative_path = nil - local field_name = nil + local field_name -- Path doesn't require resolve. if type(path) == 'number' then idx = path @@ -846,7 +844,7 @@ local function space_sequence_alter_prepare(format, parts, options, if id == nil then box.error(box.error.NO_SUCH_SEQUENCE, new_sequence.id) end - local tuple = _space_sequence.index.sequence:select(id)[1] + tuple = _space_sequence.index.sequence:select(id)[1] if tuple ~= nil and tuple.is_generated then box.error(box.error.ALTER_SPACE, space_name, "can not attach generated sequence") @@ -1146,7 +1144,7 @@ box.schema.index.alter = function(space_id, index_id, options) local can_update_field = {id = true, name = true, type = true } local can_update = true local cant_update_fields = '' - for k,v in pairs(options) do + for k, _ in pairs(options) do if not can_update_field[k] then can_update = false cant_update_fields = cant_update_fields .. ' ' .. k @@ -1190,7 +1188,7 @@ box.schema.index.alter = function(space_id, index_id, options) if options.type == nil then options.type = tuple.type end - for k, t in pairs(index_options) do + for k, _ in pairs(index_options) do if options[k] ~= nil then index_opts[k] = options[k] end @@ -1233,12 +1231,12 @@ end local iterator_t = ffi.typeof('struct iterator') ffi.metatype(iterator_t, { - __tostring = function(iterator) + __tostring = function() return "" end; }) -local iterator_gen = function(param, state) +local iterator_gen = function(param, state) -- luacheck: no unused args --[[ index:pairs() mostly conforms to the Lua for-in loop conventions and tries to follow the best practices of Lua community. @@ -1272,7 +1270,7 @@ local iterator_gen = function(param, state) end end -local iterator_gen_luac = function(param, state) +local iterator_gen_luac = function(param, state) -- luacheck: no unused args local tuple = internal.iterator_next(state) if tuple ~= nil then return state, tuple -- new state, value @@ -1500,7 +1498,8 @@ end base_index_mt.get_ffi = function(index, key) check_index_arg(index, 'get') - local key, key_end = tuple_encode(key) + local key_end + key, key_end = tuple_encode(key) if builtin.box_index_get(index.space_id, index.id, key, key_end, ptuple) ~= 0 then return box.error() -- error @@ -1533,7 +1532,8 @@ end base_index_mt.select_ffi = function(index, key, opts) check_index_arg(index, 'select') - local key, key_end = tuple_encode(key) + local key_end + key, key_end = tuple_encode(key) local iterator, offset, limit = check_select_opts(opts, key + 1 >= key_end) local port = ffi.cast('struct port *', port_c) @@ -1555,7 +1555,7 @@ end base_index_mt.select_luac = function(index, key, opts) check_index_arg(index, 'select') - local key = keify(key) + key = keify(key) local iterator, offset, limit = check_select_opts(opts, #key == 0) return internal.select(index.space_id, index.id, iterator, offset, limit, key) @@ -1775,9 +1775,9 @@ local function wrap_schema_object_mt(name) __pairs = global_mt.__pairs } local mt_mt = {} - mt_mt.__newindex = function(t, k, v) + mt_mt.__newindex = function(self, k, v) mt_mt.__newindex = nil - mt.__index = function(t, k) + mt.__index = function(self, k) return mt[k] or box.schema[name][k] end rawset(mt, k, v) @@ -2486,24 +2486,24 @@ local function revoke(uid, name, privilege, object_type, object_name, options) end end -local function drop(uid, opts) +local function drop(uid) -- recursive delete of user data local _vpriv = box.space[box.schema.VPRIV_ID] local spaces = box.space[box.schema.VSPACE_ID].index.owner:select{uid} - for k, tuple in pairs(spaces) do + for _, tuple in pairs(spaces) do box.space[tuple.id]:drop() end local funcs = box.space[box.schema.VFUNC_ID].index.owner:select{uid} - for k, tuple in pairs(funcs) do + for _, tuple in pairs(funcs) do box.schema.func.drop(tuple.id) end -- if this is a role, revoke this role from whoever it was granted to local grants = _vpriv.index.object:select{'role', uid} - for k, tuple in pairs(grants) do + for _, tuple in pairs(grants) do revoke(tuple.grantee, tuple.grantee, uid) end local sequences = box.space[box.schema.VSEQUENCE_ID].index.owner:select{uid} - for k, tuple in pairs(sequences) do + for _, tuple in pairs(sequences) do box.schema.sequence.drop(tuple.id) end -- xxx: hack, we have to revoke session and usage privileges @@ -2515,7 +2515,7 @@ local function drop(uid, opts) end local privs = _vpriv.index.primary:select{uid} - for k, tuple in pairs(privs) do + for _, tuple in pairs(privs) do -- we need an additional box.session.su() here, because of -- unnecessary check for privilege PRIV_REVOKE in priv_def_check() box.session.su("admin", revoke, uid, uid, tuple.privilege, @@ -2565,7 +2565,7 @@ box.schema.user.drop = function(name, opts) box.error(box.error.DROP_USER, name, "the user is active in the current session") end - return drop(uid, opts) + return drop(uid) end if not opts.if_exists then box.error(box.error.NO_SUCH_USER, name) @@ -2681,7 +2681,7 @@ box.once = function(key, func, ...) box.error(box.error.ILLEGAL_PARAMS, "Usage: box.once(key, func, ...)") end - local key = "once"..key + key = "once"..key if box.space._schema:get{key} ~= nil then return end diff --git a/src/box/lua/tuple.lua b/src/box/lua/tuple.lua index f97aa1579..1b958425f 100644 --- a/src/box/lua/tuple.lua +++ b/src/box/lua/tuple.lua @@ -1,7 +1,6 @@ -- tuple.lua (internal file) local ffi = require('ffi') -local yaml = require('yaml') local msgpackffi = require('msgpackffi') local fun = require('fun') local buffer = require('buffer') @@ -81,7 +80,6 @@ local tuple_encode = function(obj) encode_r(tmpbuf, obj, 1) elseif type(obj) == "table" then encode_array(tmpbuf, #obj) - local i for i = 1, #obj, 1 do encode_r(tmpbuf, obj[i], 1) end @@ -232,7 +230,7 @@ local function tuple_update(tuple, expr) error("Usage: tuple:update({ { op, field, arg}+ })") end local pexpr, pexpr_end = tuple_encode(expr) - local tuple = builtin.box_tuple_update(tuple, pexpr, pexpr_end) + tuple = builtin.box_tuple_update(tuple, pexpr, pexpr_end) if tuple == nil then return box.error() end @@ -245,7 +243,7 @@ local function tuple_upsert(tuple, expr) error("Usage: tuple:upsert({ { op, field, arg}+ })") end local pexpr, pexpr_end = tuple_encode(expr) - local tuple = builtin.box_tuple_upsert(tuple, pexpr, pexpr_end) + tuple = builtin.box_tuple_upsert(tuple, pexpr, pexpr_end) if tuple == nil then return box.error() end @@ -339,7 +337,7 @@ ffi.metatype(tuple_t, { ffi.metatype(tuple_iterator_t, { __call = tuple_iterator_next; - __tostring = function(it) return "" end; + __tostring = function() return "" end; }) -- Free methods, which are not needed anymore. diff --git a/src/box/lua/upgrade.lua b/src/box/lua/upgrade.lua index 075cc236e..208b53f15 100644 --- a/src/box/lua/upgrade.lua +++ b/src/box/lua/upgrade.lua @@ -52,10 +52,9 @@ end local function truncate(space) local pk = space.index[0] while pk:len() > 0 do - local state, t - for state, t in pk:pairs() do + for _, t in pk:pairs() do local key = {} - for _k2, parts in ipairs(pk.parts) do + for _, parts in ipairs(pk.parts) do table.insert(key, t[parts.fieldno]) end space:delete(key) @@ -173,7 +172,7 @@ local function initial_1_7_5() format[5] = {name='field_count', type='unsigned'} format[6] = {name='flags', type='map'} format[7] = {name='format', type='array'} - local def = _space:insert{_space.id, ADMIN, '_space', 'memtx', 0, MAP, format} + _space:insert{_space.id, ADMIN, '_space', 'memtx', 0, MAP, format} -- space name is unique log.info("create index primary on _space") _index:insert{_space.id, 0, 'primary', 'tree', { unique = true }, {{0, 'unsigned'}}} @@ -194,7 +193,7 @@ local function initial_1_7_5() format[4] = {name = 'type', type = 'string'} format[5] = {name = 'opts', type = 'map'} format[6] = {name = 'parts', type = 'array'} - def = _space:insert{_index.id, ADMIN, '_index', 'memtx', 0, MAP, format} + _space:insert{_index.id, ADMIN, '_index', 'memtx', 0, MAP, format} -- index name is unique within a space log.info("create index primary on _index") _index:insert{_index.id, 0, 'primary', 'tree', {unique = true}, {{0, 'unsigned'}, {1, 'unsigned'}}} @@ -211,7 +210,7 @@ local function initial_1_7_5() format[2] = {name='owner', type='unsigned'} format[3] = {name='name', type='string'} format[4] = {name='setuid', type='unsigned'} - def = _space:insert{_func.id, ADMIN, '_func', 'memtx', 0, MAP, format} + _space:insert{_func.id, ADMIN, '_func', 'memtx', 0, MAP, format} -- function name and id are unique log.info("create index _func:primary") _index:insert{_func.id, 0, 'primary', 'tree', {unique = true}, {{0, 'unsigned'}}} @@ -231,7 +230,7 @@ local function initial_1_7_5() format[3] = {name='name', type='string'} format[4] = {name='type', type='string'} format[5] = {name='auth', type='map'} - def = _space:insert{_user.id, ADMIN, '_user', 'memtx', 0, MAP, format} + _space:insert{_user.id, ADMIN, '_user', 'memtx', 0, MAP, format} -- user name and id are unique log.info("create index _func:primary") _index:insert{_user.id, 0, 'primary', 'tree', {unique = true}, {{0, 'unsigned'}}} @@ -251,7 +250,7 @@ local function initial_1_7_5() format[3] = {name='object_type', type='string'} format[4] = {name='object_id', type='unsigned'} format[5] = {name='privilege', type='unsigned'} - def = _space:insert{_priv.id, ADMIN, '_priv', 'memtx', 0, MAP, format} + _space:insert{_priv.id, ADMIN, '_priv', 'memtx', 0, MAP, format} -- user id, object type and object id are unique log.info("create index primary on _priv") _index:insert{_priv.id, 0, 'primary', 'tree', {unique = true}, {{1, 'unsigned'}, {2, 'string'}, {3, 'unsigned'}}} @@ -580,7 +579,7 @@ local function upgrade_to_2_1_0() -- Now, abscent field means NULL, so we can safely set second -- field in format, marking it nullable. log.info("Add nullable value field to space _schema") - local format = {} + format = {} format[1] = {type='string', name='key'} format[2] = {type='any', name='value', is_nullable=true} box.space._schema:format(format) @@ -734,7 +733,7 @@ local function upgrade_collation_to_2_1_3() local id = 4 for _, collation in ipairs(coll_lst) do - for i, strength in ipairs(coll_strengths) do + for _, strength in ipairs(coll_strengths) do local coll_name = 'unicode_' .. collation.name .. "_" .. strength.s log.info("creating collation %s", coll_name) box.space._collation:replace{id, coll_name, ADMIN, "ICU", collation.loc_str, strength.opt } -- 2.23.0