Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org
Cc: vdavydov.dev@gmail.com
Subject: [PATCH 1/4] sql: remove sync from sql_request/response
Date: Tue, 11 Dec 2018 00:40:38 +0300	[thread overview]
Message-ID: <f471e3db468bb0bbabfc57225ce9baf9786a25c7.1544477760.git.v.shpilevoy@tarantool.org> (raw)
In-Reply-To: <cover.1544477760.git.v.shpilevoy@tarantool.org>
In-Reply-To: <cover.1544477760.git.v.shpilevoy@tarantool.org>

sql_request is now decoded entirely in iproto thread
in iproto_msg_decode unlike other similar requests
like CALL or UPDATE which could be decoded in iproto
too.

But iproto thread pays for this optimization with a
leak - sql_request.bind array is allocated on iproto
thread region and never freed.

A fix is to decode, apply and free bind array in tx
thread in one place: tx_process_sql. For this
sql_request should look like other requests: do not
decode arrays, do not store sync, store fields as
raw MsgPack.

First step - remove sync.

Part of #3828
---
 src/box/execute.c | 2 --
 src/box/execute.h | 3 ---
 src/box/iproto.cc | 3 ++-
 3 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/src/box/execute.c b/src/box/execute.c
index 3a6cadf49..894625c71 100644
--- a/src/box/execute.c
+++ b/src/box/execute.c
@@ -269,7 +269,6 @@ error:
 	request->sql_text = NULL;
 	request->bind = NULL;
 	request->bind_count = 0;
-	request->sync = row->sync;
 	for (uint32_t i = 0; i < map_size; ++i) {
 		uint8_t key = *data;
 		if (key != IPROTO_SQL_BIND && key != IPROTO_SQL_TEXT) {
@@ -615,7 +614,6 @@ sql_prepare_and_execute(const struct sql_request *request,
 	assert(stmt != NULL);
 	port_tuple_create(&response->port);
 	response->prep_stmt = stmt;
-	response->sync = request->sync;
 	if (sql_bind(request, stmt) == 0 &&
 	    sql_execute(db, stmt, &response->port, region) == 0)
 		return 0;
diff --git a/src/box/execute.h b/src/box/execute.h
index 5f3d5eb59..fa7820b0b 100644
--- a/src/box/execute.h
+++ b/src/box/execute.h
@@ -55,7 +55,6 @@ struct xrow_header;
 
 /** EXECUTE request. */
 struct sql_request {
-	uint64_t sync;
 	/** SQL statement text. */
 	const char *sql_text;
 	/** Length of the SQL statement text. */
@@ -68,8 +67,6 @@ struct sql_request {
 
 /** Response on EXECUTE request. */
 struct sql_response {
-	/** Request sync. */
-	uint64_t sync;
 	/** Port with response data if any. */
 	struct port port;
 	/** Prepared SQL statement with metadata. */
diff --git a/src/box/iproto.cc b/src/box/iproto.cc
index 7c11d05b3..f24a56e4e 100644
--- a/src/box/iproto.cc
+++ b/src/box/iproto.cc
@@ -1602,7 +1602,8 @@ tx_process_sql(struct cmsg *m)
 		obuf_rollback_to_svp(out, &header_svp);
 		goto error;
 	}
-	iproto_reply_sql(out, &header_svp, response.sync, schema_version, keys);
+	iproto_reply_sql(out, &header_svp, msg->header.sync, schema_version,
+			 keys);
 	iproto_wpos_create(&msg->wpos, out);
 	return;
 error:
-- 
2.17.2 (Apple Git-113)

  reply	other threads:[~2018-12-10 21:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-10 21:40 [PATCH 0/4] Fix sql_bind leak Vladislav Shpilevoy
2018-12-10 21:40 ` Vladislav Shpilevoy [this message]
2018-12-10 21:40 ` [PATCH 2/4] Revert "box: store sql text and length in sql_request" Vladislav Shpilevoy
2018-12-10 21:40 ` [PATCH 3/4] sql: decode bind parameters in TX thread Vladislav Shpilevoy
2018-12-10 21:40 ` [PATCH 4/4] sql: move sql_request and xrow_decode_sql to xrow lib Vladislav Shpilevoy
2018-12-18 12:02 ` [PATCH 0/4] Fix sql_bind leak Vladimir Davydov

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=f471e3db468bb0bbabfc57225ce9baf9786a25c7.1544477760.git.v.shpilevoy@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=vdavydov.dev@gmail.com \
    --subject='Re: [PATCH 1/4] sql: remove sync from sql_request/response' \
    /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