From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 2DA5023C58 for ; Fri, 28 Dec 2018 13:11:16 -0500 (EST) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Pijwm3PJk9n3 for ; Fri, 28 Dec 2018 13:11:16 -0500 (EST) Received: from smtp46.i.mail.ru (smtp46.i.mail.ru [94.100.177.106]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id D8D2123C4F for ; Fri, 28 Dec 2018 13:11:15 -0500 (EST) From: imeevma@tarantool.org Subject: [tarantool-patches] [PATCH v6 1/5] iproto: move map creation to sql_response_dump() Date: Fri, 28 Dec 2018 21:11:13 +0300 Message-Id: <70f96240bbfade8f07380ee2b72b4b14d06dbaeb.1546017932.git.imeevma@gmail.com> In-Reply-To: References: Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org, v.shpilevoy@tarantool.org Currently, function sql_response_dump() puts data into an already created map. Moving the map creation to sql_response_dump() simplifies the code and allows us to use sql_response_dump() as one of the port_sql methods. Needed for #3505 --- src/box/execute.c | 23 ++++++++++++++++------- src/box/execute.h | 3 +-- src/box/iproto.cc | 8 +++----- src/box/xrow.c | 8 +------- src/box/xrow.h | 9 +-------- 5 files changed, 22 insertions(+), 29 deletions(-) diff --git a/src/box/execute.c b/src/box/execute.c index 7fff5fd..38b6cbc 100644 --- a/src/box/execute.c +++ b/src/box/execute.c @@ -555,22 +555,29 @@ sql_prepare_and_execute(const char *sql, int len, const struct sql_bind *bind, } int -sql_response_dump(struct sql_response *response, int *keys, struct obuf *out) +sql_response_dump(struct sql_response *response, struct obuf *out) { sqlite3 *db = sql_get(); struct sqlite3_stmt *stmt = (struct sqlite3_stmt *) response->prep_stmt; struct port_tuple *port_tuple = (struct port_tuple *) &response->port; int rc = 0, column_count = sqlite3_column_count(stmt); if (column_count > 0) { + int keys = 2; + int size = mp_sizeof_map(keys); + char *pos = (char *) obuf_alloc(out, size); + if (pos == NULL) { + diag_set(OutOfMemory, size, "obuf_alloc", "pos"); + goto err; + } + pos = mp_encode_map(pos, keys); if (sql_get_description(stmt, out, column_count) != 0) { err: rc = -1; goto finish; } - *keys = 2; - int size = mp_sizeof_uint(IPROTO_DATA) + - mp_sizeof_array(port_tuple->size); - char *pos = (char *) obuf_alloc(out, size); + size = mp_sizeof_uint(IPROTO_DATA) + + mp_sizeof_array(port_tuple->size); + pos = (char *) obuf_alloc(out, size); if (pos == NULL) { diag_set(OutOfMemory, size, "obuf_alloc", "pos"); goto err; @@ -586,18 +593,20 @@ err: goto err; } } else { - *keys = 1; + int keys = 1; assert(port_tuple->size == 0); struct stailq *autoinc_id_list = vdbe_autoinc_id_list((struct Vdbe *)stmt); uint32_t map_size = stailq_empty(autoinc_id_list) ? 1 : 2; - int size = mp_sizeof_uint(IPROTO_SQL_INFO) + + int size = mp_sizeof_map(keys) + + mp_sizeof_uint(IPROTO_SQL_INFO) + mp_sizeof_map(map_size); char *pos = (char *) obuf_alloc(out, size); if (pos == NULL) { diag_set(OutOfMemory, size, "obuf_alloc", "pos"); goto err; } + pos = mp_encode_map(pos, keys); pos = mp_encode_uint(pos, IPROTO_SQL_INFO); pos = mp_encode_map(pos, map_size); uint64_t id_count = 0; diff --git a/src/box/execute.h b/src/box/execute.h index 9c1bc4f..60b8f31 100644 --- a/src/box/execute.h +++ b/src/box/execute.h @@ -105,14 +105,13 @@ sql_bind_list_decode(const char *data, struct sql_bind **out_bind); * | } | * +----------------------------------------------+ * @param response EXECUTE response. - * @param[out] keys number of keys in dumped map. * @param out Output buffer. * * @retval 0 Success. * @retval -1 Memory error. */ int -sql_response_dump(struct sql_response *response, int *keys, struct obuf *out); +sql_response_dump(struct sql_response *response, struct obuf *out); /** * Prepare and execute an SQL statement. diff --git a/src/box/iproto.cc b/src/box/iproto.cc index 1debc3c..a08c8c5 100644 --- a/src/box/iproto.cc +++ b/src/box/iproto.cc @@ -1641,17 +1641,15 @@ tx_process_sql(struct cmsg *m) * become out of date during yield. */ out = msg->connection->tx.p_obuf; - int keys; struct obuf_svp header_svp; /* Prepare memory for the iproto header. */ - if (iproto_prepare_header(out, &header_svp, IPROTO_SQL_HEADER_LEN) != 0) + if (iproto_prepare_header(out, &header_svp, IPROTO_HEADER_LEN) != 0) goto error; - if (sql_response_dump(&response, &keys, out) != 0) { + if (sql_response_dump(&response, out) != 0) { obuf_rollback_to_svp(out, &header_svp); goto error; } - iproto_reply_sql(out, &header_svp, msg->header.sync, schema_version, - keys); + iproto_reply_sql(out, &header_svp, msg->header.sync, schema_version); iproto_wpos_create(&msg->wpos, out); return; error: diff --git a/src/box/xrow.c b/src/box/xrow.c index 67019a6..c4e3073 100644 --- a/src/box/xrow.c +++ b/src/box/xrow.c @@ -508,17 +508,11 @@ error: void iproto_reply_sql(struct obuf *buf, struct obuf_svp *svp, uint64_t sync, - uint32_t schema_version, int keys) + uint32_t schema_version) { char *pos = (char *) obuf_svp_to_ptr(buf, svp); iproto_header_encode(pos, IPROTO_OK, sync, schema_version, obuf_size(buf) - svp->used - IPROTO_HEADER_LEN); - /* - * MessagePack encodes value <= 15 as - * bitwise OR with 0x80. - */ - assert(keys <= 15); - *(pos + IPROTO_HEADER_LEN) = 0x80 | keys; } void diff --git a/src/box/xrow.h b/src/box/xrow.h index 6bab0a1..2654e35 100644 --- a/src/box/xrow.h +++ b/src/box/xrow.h @@ -52,12 +52,6 @@ enum { IPROTO_HEADER_LEN = 28, /** 7 = sizeof(iproto_body_bin). */ IPROTO_SELECT_HEADER_LEN = IPROTO_HEADER_LEN + 7, - /** - * Header of message + header of body with one or two - * keys: IPROTO_DATA and IPROTO_METADATA or - * IPROTO_SQL_INFO. 1 == mp_sizeof_map(<=15). - */ - IPROTO_SQL_HEADER_LEN = IPROTO_HEADER_LEN + 1, }; struct xrow_header { @@ -491,11 +485,10 @@ xrow_decode_sql(const struct xrow_header *row, struct sql_request *request); * @param svp Savepoint of the header beginning. * @param sync Request sync. * @param schema_version Schema version. - * @param keys Count of keys in the body. */ void iproto_reply_sql(struct obuf *buf, struct obuf_svp *svp, uint64_t sync, - uint32_t schema_version, int keys); + uint32_t schema_version); /** * Write an IPROTO_CHUNK header from a specified position in a -- 2.7.4