From: Vladimir Davydov via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH 19/20] net.box: merge new_id, new_request and encode_method
Date: Fri, 23 Jul 2021 14:07:29 +0300 [thread overview]
Message-ID: <56ac1dd920bd62571227c7f81690600ac685f1d5.1627024646.git.vdavydov@tarantool.org> (raw)
In-Reply-To: <cover.1627024646.git.vdavydov@tarantool.org>
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
next prev parent reply other threads:[~2021-07-23 11:17 UTC|newest]
Thread overview: 80+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-23 11:07 [Tarantool-patches] [PATCH 00/20] Rewrite performance critical parts of net.box in C Vladimir Davydov via Tarantool-patches
2021-07-23 11:07 ` [Tarantool-patches] [PATCH 01/20] net.box: fix console connection breakage when request is discarded Vladimir Davydov via Tarantool-patches
2021-07-28 22:49 ` Vladislav Shpilevoy via Tarantool-patches
2021-07-29 10:40 ` Vladimir Davydov via Tarantool-patches
2021-07-23 11:07 ` [Tarantool-patches] [PATCH 02/20] net.box: wake up wait_result callers " Vladimir Davydov via Tarantool-patches
2021-07-29 10:47 ` Vladimir Davydov via Tarantool-patches
2021-07-23 11:07 ` [Tarantool-patches] [PATCH 03/20] net.box: do not check worker_fiber in request:result, is_ready Vladimir Davydov via Tarantool-patches
2021-07-23 11:07 ` [Tarantool-patches] [PATCH 04/20] net.box: remove decode_push from method_decoder table Vladimir Davydov via Tarantool-patches
2021-07-23 11:07 ` [Tarantool-patches] [PATCH 05/20] net.box: use decode_tuple instead of decode_get Vladimir Davydov via Tarantool-patches
2021-07-23 11:07 ` [Tarantool-patches] [PATCH 06/20] net.box: rename request.ctx to request.format Vladimir Davydov via Tarantool-patches
2021-07-28 22:49 ` Vladislav Shpilevoy via Tarantool-patches
2021-07-29 10:54 ` Vladimir Davydov via Tarantool-patches
2021-07-29 22:39 ` Vladislav Shpilevoy via Tarantool-patches
2021-07-30 8:15 ` Vladimir Davydov via Tarantool-patches
2021-07-23 11:07 ` [Tarantool-patches] [PATCH 07/20] net.box: use integer id instead of method name Vladimir Davydov via Tarantool-patches
2021-07-28 22:50 ` Vladislav Shpilevoy via Tarantool-patches
2021-07-29 11:30 ` Vladimir Davydov via Tarantool-patches
2021-07-23 11:07 ` [Tarantool-patches] [PATCH 08/20] net.box: remove useless encode optimization Vladimir Davydov via Tarantool-patches
2021-07-23 11:07 ` [Tarantool-patches] [PATCH 09/20] net.box: rewrite request encoder in C Vladimir Davydov via Tarantool-patches
2021-07-28 22:51 ` Vladislav Shpilevoy via Tarantool-patches
2021-07-29 14:08 ` Vladimir Davydov via Tarantool-patches
2021-07-29 14:10 ` Vladimir Davydov via Tarantool-patches
2021-07-23 11:07 ` [Tarantool-patches] [PATCH 10/20] lua/utils: make char ptr Lua CTIDs public Vladimir Davydov via Tarantool-patches
2021-07-23 11:07 ` [Tarantool-patches] [PATCH 11/20] net.box: rewrite response decoder in C Vladimir Davydov via Tarantool-patches
2021-07-27 14:07 ` Cyrill Gorcunov via Tarantool-patches
2021-07-27 14:14 ` Vladimir Davydov via Tarantool-patches
2021-07-29 22:39 ` Vladislav Shpilevoy via Tarantool-patches
2021-07-30 8:44 ` Vladimir Davydov via Tarantool-patches
2021-07-30 22:12 ` Vladislav Shpilevoy via Tarantool-patches
2021-08-02 7:36 ` Vladimir Davydov via Tarantool-patches
2021-07-23 11:07 ` [Tarantool-patches] [PATCH 12/20] net.box: rewrite error " Vladimir Davydov via Tarantool-patches
2021-07-30 22:13 ` Vladislav Shpilevoy via Tarantool-patches
2021-08-02 8:00 ` Vladimir Davydov via Tarantool-patches
2021-08-02 21:47 ` Vladislav Shpilevoy via Tarantool-patches
2021-07-23 11:07 ` [Tarantool-patches] [PATCH 13/20] net.box: rewrite send_and_recv_{iproto, console} " Vladimir Davydov via Tarantool-patches
2021-08-02 21:49 ` Vladislav Shpilevoy via Tarantool-patches
2021-08-03 15:44 ` Vladimir Davydov via Tarantool-patches
2021-08-03 23:06 ` Vladislav Shpilevoy via Tarantool-patches
2021-08-04 13:56 ` Vladimir Davydov via Tarantool-patches
2021-08-04 21:18 ` Vladislav Shpilevoy via Tarantool-patches
2021-08-05 8:37 ` Vladimir Davydov via Tarantool-patches
2021-07-23 11:07 ` [Tarantool-patches] [PATCH 14/20] net.box: rename netbox_{prepare, encode}_request to {begin, end} Vladimir Davydov via Tarantool-patches
2021-07-23 11:07 ` [Tarantool-patches] [PATCH 15/20] net.box: rewrite request implementation in C Vladimir Davydov via Tarantool-patches
2021-08-02 21:54 ` Vladislav Shpilevoy via Tarantool-patches
2021-08-04 12:30 ` Vladimir Davydov via Tarantool-patches
2021-08-04 15:35 ` Vladimir Davydov via Tarantool-patches
2021-08-04 16:14 ` Vladimir Davydov via Tarantool-patches
2021-08-04 21:20 ` Vladislav Shpilevoy via Tarantool-patches
2021-08-05 12:46 ` Vladimir Davydov via Tarantool-patches
2021-07-23 11:07 ` [Tarantool-patches] [PATCH 16/20] net.box: store next_request_id in C code Vladimir Davydov via Tarantool-patches
2021-08-03 23:06 ` Vladislav Shpilevoy via Tarantool-patches
2021-08-04 16:25 ` Vladimir Davydov via Tarantool-patches
2021-07-23 11:07 ` [Tarantool-patches] [PATCH 17/20] net.box: rewrite console handlers in C Vladimir Davydov via Tarantool-patches
2021-08-03 23:07 ` Vladislav Shpilevoy via Tarantool-patches
2021-08-05 11:53 ` Vladimir Davydov via Tarantool-patches
2021-07-23 11:07 ` [Tarantool-patches] [PATCH 18/20] net.box: rewrite iproto " Vladimir Davydov via Tarantool-patches
2021-08-03 23:08 ` Vladislav Shpilevoy via Tarantool-patches
2021-08-05 11:54 ` Vladimir Davydov via Tarantool-patches
2021-07-23 11:07 ` Vladimir Davydov via Tarantool-patches [this message]
2021-08-03 23:08 ` [Tarantool-patches] [PATCH 19/20] net.box: merge new_id, new_request and encode_method Vladislav Shpilevoy via Tarantool-patches
2021-08-05 11:55 ` Vladimir Davydov via Tarantool-patches
2021-07-23 11:07 ` [Tarantool-patches] [PATCH 20/20] net.box: do not create request object in Lua for sync requests Vladimir Davydov via Tarantool-patches
2021-08-03 23:09 ` Vladislav Shpilevoy via Tarantool-patches
2021-08-05 12:23 ` Vladimir Davydov via Tarantool-patches
2021-07-23 12:48 ` [Tarantool-patches] [PATCH 00/20] Rewrite performance critical parts of net.box in C Vladimir Davydov via Tarantool-patches
2021-07-26 7:26 ` Kirill Yukhin via Tarantool-patches
2021-07-27 9:59 ` Vladimir Davydov via Tarantool-patches
2021-07-28 22:51 ` Vladislav Shpilevoy via Tarantool-patches
2021-07-29 11:33 ` Vladimir Davydov via Tarantool-patches
2021-07-29 15:23 ` Vladimir Davydov via Tarantool-patches
2021-07-29 22:38 ` Vladislav Shpilevoy via Tarantool-patches
2021-07-30 10:04 ` Vladimir Davydov via Tarantool-patches
2021-07-29 22:40 ` Vladislav Shpilevoy via Tarantool-patches
2021-07-30 8:16 ` Vladimir Davydov via Tarantool-patches
2021-08-03 23:05 ` Vladislav Shpilevoy via Tarantool-patches
2021-08-04 12:40 ` Vladimir Davydov via Tarantool-patches
2021-08-05 20:59 ` Vladislav Shpilevoy via Tarantool-patches
2021-08-09 11:22 ` Igor Munkin via Tarantool-patches
2021-08-09 11:48 ` Vitaliia Ioffe via Tarantool-patches
2021-08-09 13:56 ` Vladimir Davydov via Tarantool-patches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56ac1dd920bd62571227c7f81690600ac685f1d5.1627024646.git.vdavydov@tarantool.org \
--to=tarantool-patches@dev.tarantool.org \
--cc=vdavydov@tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH 19/20] net.box: merge new_id, new_request and encode_method' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox