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 8EE706EC55; Fri, 23 Jul 2021 14:17:04 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8EE706EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1627039024; bh=fEqLa3BED4G/XHAkjKDkojAXPdRWN6k8RiUYUaYnb2c=; 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=aDJS0OFQ39FpjDJZ6mPb+7BZuY3eLDqLL8jKtYDOVt5wPDFoMkIQs3UoG+XOxpXl6 Y/UimdHnjLTtNe0najLNP/Ce15Pb8Hf5LN7gWTPViWmnUq1MqVgiV0IhqxXPMv5P2b uwinFSLjsO1oN4Y3HeqDV2aO9eyH5QW/UD6hPB/A= 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 3C6016EC55 for ; Fri, 23 Jul 2021 14:08:04 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 3C6016EC55 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1m6t2B-0004dl-KG; Fri, 23 Jul 2021 14:08:04 +0300 To: tarantool-patches@dev.tarantool.org Date: Fri, 23 Jul 2021 14:07:29 +0300 Message-Id: <56ac1dd920bd62571227c7f81690600ac685f1d5.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: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD941C43E597735A9C30288BCF456A452EC92BAB6D044D5CCDE182A05F538085040E052C446E4A5F59EF5270137E170F3765FA070F43ABD1AAF5921237380BE1BD5 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE783C1FBFE215D363AEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637BD378188104BC8BE8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8CA8BFE0E76601BFB1DDAB343055DC8CE117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC55D5BE2F85BDEC5FA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F4460429728776938767073520B1593CA6EC85F86D618001F51B5FD3F9D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6045A9A90E9EED90B089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 8BD88D57C5CADBC8B2710865C3867510E24B84BB11A6A852A3B1A56EE2B804F6B226C914C996894645FD9D8A29397D6EFF55FE49A3C2BFCFC8C84E951CD0BE2F296C473AB1E14218EA052B563B0B06C67866D6147AF826D8CA8BFE0E76601BFB1DDAB343055DC8CEF972CCD2F8FE1EF1CFC4036BBF6A4EA91D2D1417DB62FBB3BDAD6C7F3747799A X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3463DBE2ADA183F62F30B7B4FEE4405057E7CD6C9D55686ABBE22D78889094AE835145E908DBE8A3E51D7E09C32AA3244CDA83A36FA7DD303CCE89F4186A03737630363D8B7DA7DD44729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojbL9S8ysBdXiEX0g4jkpDtbQ+orrWaR6k X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D06B8D47934201372C2A489D019D72549274CEFED1673C562683ABF942079399BFB559BB5D741EB966A65DFF43FF7BE03240331F90058701C67EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH 19/20] net.box: merge new_id, new_request and encode_method 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" So as not to call tree C functions per each request, let's merge them and call the resulting function perform_async_request. --- src/box/lua/net_box.c | 55 +++++++++++++++++------------------------ src/box/lua/net_box.lua | 8 +++--- 2 files changed, 26 insertions(+), 37 deletions(-) diff --git a/src/box/lua/net_box.c b/src/box/lua/net_box.c index fde2a8772890..844a1de613f2 100644 --- a/src/box/lua/net_box.c +++ b/src/box/lua/net_box.c @@ -962,17 +962,13 @@ netbox_encode_inject(struct lua_State *L, int idx, struct ibuf *ibuf, } /* - * Encodes a request for the specified method. - * - * Takes three mandatory arguments: - * - method: a value from the netbox_method enumeration - * - ibuf: buffer to write the result to - * - sync: value of the IPROTO_SYNC key - * - * Other arguments are method-specific. + * Encodes a request for the specified method and writes the result to the + * provided buffer. Values to encode depend on the method and are passed via + * Lua stack starting at index idx. */ static int -netbox_encode_method(struct lua_State *L) +netbox_encode_method(struct lua_State *L, int idx, enum netbox_method method, + struct ibuf *ibuf, uint64_t sync) { typedef void (*method_encoder_f)(struct lua_State *L, int idx, struct ibuf *ibuf, uint64_t sync); @@ -996,11 +992,7 @@ netbox_encode_method(struct lua_State *L) [NETBOX_COUNT] = netbox_encode_call, [NETBOX_INJECT] = netbox_encode_inject, }; - enum netbox_method method = lua_tointeger(L, 1); - assert(method < netbox_method_MAX); - struct ibuf *ibuf = (struct ibuf *) lua_topointer(L, 2); - uint64_t sync = luaL_touint64(L, 3); - method_encoder[method](L, 4, ibuf, sync); + method_encoder[method](L, idx, ibuf, sync); return 0; } @@ -1404,15 +1396,6 @@ 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; -} - static int luaT_netbox_registry_reset(struct lua_State *L) { @@ -1624,33 +1607,43 @@ netbox_new_registry(struct lua_State *L) } /* - * Creates a request object (userdata) and pushes it to Lua stack. + * Writes a request to the send buffer and registers the request object + * ('future') that can be used for waiting for a response. * * Takes the following arguments: * - requests: registry to register the new request with - * - id: id (sync) to assign to the new request + * - send_buf: buffer (ibuf) to write the encoded request to * - buffer: buffer (ibuf) to write the result to or nil * - skip_header: whether to skip header when writing the result to the buffer * - method: a value from the netbox_method enumeration * - on_push: on_push trigger function * - on_push_ctx: on_push trigger function argument * - format: tuple format to use for decoding the body or nil + * - ...: method-specific arguments passed to the encoder */ static int -netbox_new_request(struct lua_State *L) +netbox_perform_async_request(struct lua_State *L) { struct netbox_request *request = lua_newuserdata(L, sizeof(*request)); netbox_request_create(request); luaL_getmetatable(L, netbox_request_typename); lua_setmetatable(L, -2); + + /* Encode and write the request to the send buffer. */ struct netbox_registry *registry = luaT_check_netbox_registry(L, 1); - request->sync = luaL_touint64(L, 2); + struct ibuf *send_buf = (struct ibuf *) lua_topointer(L, 2); + enum netbox_method method = lua_tointeger(L, 5); + assert(method < netbox_method_MAX); + uint64_t sync = registry->next_sync++; + netbox_encode_method(L, 9, method, send_buf, sync); + + /* Initialize and register the request object. */ + request->method = method; + request->sync = sync; request->buffer = (struct ibuf *) lua_topointer(L, 3); lua_pushvalue(L, 3); request->buffer_ref = luaL_ref(L, LUA_REGISTRYINDEX); request->skip_header = lua_toboolean(L, 4); - request->method = lua_tointeger(L, 5); - assert(request->method < netbox_method_MAX); lua_pushvalue(L, 6); request->on_push_ref = luaL_ref(L, LUA_REGISTRYINDEX); lua_pushvalue(L, 7); @@ -2015,7 +2008,6 @@ 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 }, { "reset", luaT_netbox_registry_reset }, { NULL, NULL } }; @@ -2033,10 +2025,9 @@ luaopen_net_box(struct lua_State *L) luaL_register_type(L, netbox_request_typename, netbox_request_meta); static const luaL_Reg net_box_lib[] = { - { "encode_method", netbox_encode_method }, { "decode_greeting",netbox_decode_greeting }, { "new_registry", netbox_new_registry }, - { "new_request", netbox_new_request }, + { "perform_async_request", netbox_perform_async_request }, { "iproto_auth", netbox_iproto_auth }, { "iproto_schema", netbox_iproto_schema }, { "iproto_loop", netbox_iproto_loop }, diff --git a/src/box/lua/net_box.lua b/src/box/lua/net_box.lua index 13def54de2c5..55d172a1f6b9 100644 --- a/src/box/lua/net_box.lua +++ b/src/box/lua/net_box.lua @@ -18,7 +18,6 @@ local check_index_arg = box.internal.check_index_arg local check_space_arg = box.internal.check_space_arg local check_primary_index = box.internal.check_primary_index -local encode_method = internal.encode_method local decode_greeting = internal.decode_greeting local TIMEOUT_INFINITY = 500 * 365 * 86400 @@ -273,10 +272,9 @@ local function create_transport(host, port, user, password, callback, if send_buf:size() == 0 then worker_fiber:wakeup() end - local id = requests:new_id() - encode_method(method, send_buf, id, ...) - return internal.new_request(requests, id, buffer, skip_header, method, - on_push, on_push_ctx, format) + return internal.perform_async_request(requests, send_buf, buffer, + skip_header, method, on_push, + on_push_ctx, format, ...) end -- -- 2.25.1