From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 2D2256EC56; Fri, 23 Jul 2021 14:15:35 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 2D2256EC56 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1627038935; bh=cE22+meuSZxO8FdYgxkGg0MjzKwoa3CzUTe3rTVC5pA=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=li+Dg1sPucQdb4VrM8RidyT+RG1IIFVK7nTKZ5xHET29dvF3bWmAuES21WHogGoYH UQyCIstpQATjIM6Ip6eW4HlACPdqzAT7AJmFsmvk2OOFKnzedeIx+ibMf/4M54cP+v TevZyhmEmaxg9rnqJNhMhdpVuwpTHzovQ+J8Yla0= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [94.100.181.251]) (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 63F746E222 for ; Fri, 23 Jul 2021 14:07:54 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 63F746E222 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1m6t21-0004dl-VX; Fri, 23 Jul 2021 14:07:54 +0300 To: tarantool-patches@dev.tarantool.org Date: Fri, 23 Jul 2021 14:07:26 +0300 Message-Id: <15f3d09cd20eb1b5b7e50f41925d8a51fb0f12a4.1627024646.git.vdavydov@tarantool.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-174C08C4: 5188C02AEC42908C481ED7ADC579193296BBA28369E3F2D2713F3D5F7D406D31BCF678C7329BA986 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD941C43E597735A9C36A98DBA789EBB6AEFB5A483DCE5E7579182A05F538085040EC4926894A62C7244B19923845647B6D6274E07216780A6689072DDCCEA1CAF9 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7D9C4478D0B876341EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637E6006D770ADD73CF8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8EA5BC7FF3A6B718A698E770D49DDE8E9117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC974A882099E279BDA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD182CC0D3CB04F14752D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6045A9A90E9EED90B089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 8BD88D57C5CADBC8B2710865C38675103A641320869028BEA3B1A56EE2B804F6B226C914C996894645FD9D8A29397D6EFF55FE49A3C2BFCFC8C84E951CD0BE2F296C473AB1E14218EA052B563B0B06C67866D6147AF826D8EA5BC7FF3A6B718A698E770D49DDE8E9F972CCD2F8FE1EF1CFC4036BBF6A4EA9A6404EA6EC7D025CCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D340CB2836B823694498374F8A571CD625E00472E280B970106F22E0AC7C11DDB3263CDEBF2DE9621DF1D7E09C32AA3244C3C9403777293CDC05DB92A4A2A0EE88430452B15D76AEC14729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojbL9S8ysBdXiEX0g4jkpDten+9W+3AgzI X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D68B2AD4D97E27964CC0E0704D2BFABED274CEFED1673C562683ABF942079399BFB559BB5D741EB966A65DFF43FF7BE03240331F90058701C67EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH 16/20] net.box: store next_request_id in C code X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Vladimir Davydov via Tarantool-patches Reply-To: Vladimir Davydov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Needed to rewrite performance-critical parts of net.box in C, e.g. iproto_schema_sm. --- src/box/lua/net_box.c | 31 +++++++++++++++++++++++++++++++ src/box/lua/net_box.lua | 24 +++++++----------------- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/box/lua/net_box.c b/src/box/lua/net_box.c index 044f7d337ca7..1a615797d485 100644 --- a/src/box/lua/net_box.c +++ b/src/box/lua/net_box.c @@ -79,6 +79,8 @@ enum netbox_method { }; struct netbox_registry { + /* Next request id. */ + uint64_t next_sync; /* sync -> netbox_request */ struct mh_i64ptr_t *requests; }; @@ -278,6 +280,7 @@ netbox_request_push_result(struct netbox_request *request, struct lua_State *L) static int netbox_registry_create(struct netbox_registry *registry) { + registry->next_sync = 1; registry->requests = mh_i64ptr_new(); if (registry->requests == NULL) { diag_set(OutOfMemory, 0, "mhash", "netbox_registry"); @@ -1444,6 +1447,32 @@ luaT_netbox_registry_gc(struct lua_State *L) return 0; } +/* Allocates a new id (sync). */ +static int +luaT_netbox_registry_new_id(struct lua_State *L) +{ + struct netbox_registry *registry = luaT_check_netbox_registry(L, 1); + luaL_pushuint64(L, registry->next_sync++); + return 1; +} + +/* + * Returns the next id (sync) without reserving it. + * If called with an argument, returns the id following its value. + */ +static int +luaT_netbox_registry_next_id(struct lua_State *L) +{ + struct netbox_registry *registry = luaT_check_netbox_registry(L, 1); + uint64_t next_sync; + if (lua_isnoneornil(L, 2)) + next_sync = registry->next_sync; + else + next_sync = luaL_touint64(L, 2) + 1; + luaL_pushuint64(L, next_sync); + return 1; +} + static int luaT_netbox_registry_reset(struct lua_State *L) { @@ -1798,6 +1827,8 @@ luaopen_net_box(struct lua_State *L) { static const struct luaL_Reg netbox_registry_meta[] = { { "__gc", luaT_netbox_registry_gc }, + { "new_id", luaT_netbox_registry_new_id }, + { "next_id", luaT_netbox_registry_next_id }, { "reset", luaT_netbox_registry_reset }, { NULL, NULL } }; diff --git a/src/box/lua/net_box.lua b/src/box/lua/net_box.lua index 4bc66940ea2a..0643477cbc9c 100644 --- a/src/box/lua/net_box.lua +++ b/src/box/lua/net_box.lua @@ -82,8 +82,6 @@ local function version_at_least(peer_version_id, major, minor, patch) return peer_version_id >= version_id(major, minor, patch) end -local function next_id(id) return band(id + 1, 0x7FFFFFFF) end - -- -- Connect to a remote server, do handshake. -- @param host Hostname. @@ -192,7 +190,6 @@ local function create_transport(host, port, user, password, callback, -- Sync requests are implemented as async call + immediate -- wait for a result. local requests = internal.new_registry() - local next_request_id = 1 local worker_fiber local send_buf = buffer.ibuf(buffer.READAHEAD) @@ -301,9 +298,8 @@ local function create_transport(host, port, user, password, callback, if send_buf:size() == 0 then worker_fiber:wakeup() end - local id = next_request_id + local id = requests:new_id() encode_method(method, send_buf, id, ...) - next_request_id = next_id(id) return internal.new_request(requests, id, buffer, skip_header, method, on_push, on_push_ctx, format) end @@ -335,12 +331,6 @@ local function create_transport(host, port, user, password, callback, internal.dispatch_response_console(requests, rid, response) end - local function new_request_id() - local id = next_request_id; - next_request_id = next_id(id) - return id - end - -- IO (WORKER FIBER) -- local function send_and_recv_iproto(timeout) local hdr, body_rpos, body_end = internal.send_and_recv_iproto( @@ -396,7 +386,7 @@ local function create_transport(host, port, user, password, callback, elseif response ~= '---\n...\n' then return error_sm(E_NO_CONNECTION, 'Unexpected response') end - local rid = next_request_id + local rid = requests:next_id() set_state('active') return console_sm(rid) elseif greeting.protocol == 'Binary' then @@ -413,7 +403,7 @@ local function create_transport(host, port, user, password, callback, return error_sm(err, response) else dispatch_response_console(rid, response) - return console_sm(next_id(rid)) + return console_sm(requests:next_id(rid)) end end @@ -423,7 +413,7 @@ local function create_transport(host, port, user, password, callback, set_state('fetch_schema') return iproto_schema_sm() end - encode_auth(send_buf, new_request_id(), user, password, salt) + encode_auth(send_buf, requests:new_id(), user, password, salt) local err, hdr, body_rpos = send_and_recv_iproto() if err then return error_sm(err, hdr) @@ -444,8 +434,8 @@ local function create_transport(host, port, user, password, callback, -- _vcollation view was added in 2.2.0-389-g3e3ef182f local peer_has_vcollation = version_at_least(greeting.version_id, 2, 2, 1) - local select1_id = new_request_id() - local select2_id = new_request_id() + local select1_id = requests:new_id() + local select2_id = requests:new_id() local select3_id local response = {} -- fetch everything from space _vspace, 2 = ITER_ALL @@ -456,7 +446,7 @@ local function create_transport(host, port, user, password, callback, 0xFFFFFFFF, nil) -- fetch everything from space _vcollation, 2 = ITER_ALL if peer_has_vcollation then - select3_id = new_request_id() + select3_id = requests:new_id() encode_method(M_SELECT, send_buf, select3_id, VCOLLATION_ID, 0, 2, 0, 0xFFFFFFFF, nil) end -- 2.25.1