[PATCH 1/4] sql: remove sync from sql_request/response

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Tue Dec 11 00:40:38 MSK 2018


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)




More information about the Tarantool-patches mailing list