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 6607F2EFF9 for ; Tue, 27 Nov 2018 14:25:44 -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 JfidW3if_G2O for ; Tue, 27 Nov 2018 14:25:44 -0500 (EST) Received: from smtp63.i.mail.ru (smtp63.i.mail.ru [217.69.128.43]) (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 278802EFCC for ; Tue, 27 Nov 2018 14:25:44 -0500 (EST) From: imeevma@tarantool.org Subject: [tarantool-patches] [PATCH v3 3/7] iproto: remove iproto functions from execute.c Date: Tue, 27 Nov 2018 22:25:40 +0300 Message-Id: <987f4ddb6287ce3af8bfbf735e4967c4fadea265.1543344471.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: v.shpilevoy@tarantool.org, tarantool-patches@freelists.org To make functions in execute.h more universal we should reduce their dependence on IPROTO. This patch removes IPROTO functions from execute.c. Needed for #3505 --- src/box/execute.c | 48 ++++++++++++++++++++++++++++++------------------ src/box/execute.h | 13 ++----------- src/box/iproto.cc | 10 +++++++++- src/box/xrow.c | 45 --------------------------------------------- src/box/xrow.h | 19 ------------------- 5 files changed, 41 insertions(+), 94 deletions(-) diff --git a/src/box/execute.c b/src/box/execute.c index 72fcd6c..d73681d 100644 --- a/src/box/execute.c +++ b/src/box/execute.c @@ -534,9 +534,15 @@ sql_get_description(struct sqlite3_stmt *stmt, struct obuf *out, int column_count) { assert(column_count > 0); - if (iproto_reply_array_key(out, column_count, IPROTO_METADATA) != 0) + int size = mp_sizeof_uint(IPROTO_METADATA) + + mp_sizeof_array(column_count); + char *pos = (char *) obuf_alloc(out, size); + if (pos == NULL) { + diag_set(OutOfMemory, size, "obuf_alloc", "pos"); return -1; - + } + pos = mp_encode_uint(pos, IPROTO_METADATA); + pos = mp_encode_array(pos, column_count); for (int i = 0; i < column_count; ++i) { size_t size = mp_sizeof_map(2) + mp_sizeof_uint(IPROTO_FIELD_NAME) + @@ -621,27 +627,28 @@ sql_prepare_and_execute(const struct sql_request *request, } int -sql_response_dump(struct sql_response *response, struct obuf *out) +sql_response_dump(struct sql_response *response, int *keys, struct obuf *out) { - struct obuf_svp header_svp; - /* Prepare memory for the iproto header. */ - if (iproto_prepare_header(out, &header_svp, IPROTO_SQL_HEADER_LEN) != 0) - return -1; 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 keys, rc = 0, column_count = sqlite3_column_count(stmt); + int rc = 0, column_count = sqlite3_column_count(stmt); if (column_count > 0) { if (sql_get_description(stmt, out, column_count) != 0) { err: - obuf_rollback_to_svp(out, &header_svp); rc = -1; goto finish; } - keys = 2; - if (iproto_reply_array_key(out, port_tuple->size, - IPROTO_DATA) != 0) + *keys = 2; + int size = mp_sizeof_uint(IPROTO_DATA) + + mp_sizeof_array(port_tuple->size); + char *pos = (char *) obuf_alloc(out, size); + if (pos == NULL) { + diag_set(OutOfMemory, size, "obuf_alloc", "pos"); goto err; + } + pos = mp_encode_uint(pos, IPROTO_DATA); + pos = mp_encode_array(pos, port_tuple->size); /* * Just like SELECT, SQL uses output format compatible * with Tarantool 1.6 @@ -651,17 +658,24 @@ err: goto err; } } else { - keys = 1; + *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; - if (iproto_reply_map_key(out, map_size, IPROTO_SQL_INFO) != 0) + int size = 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_uint(pos, IPROTO_SQL_INFO); + pos = mp_encode_map(pos, map_size); uint64_t id_count = 0; int changes = db->nChange; - int size = mp_sizeof_uint(SQL_INFO_ROW_COUNT) + - mp_sizeof_uint(changes); + size = mp_sizeof_uint(SQL_INFO_ROW_COUNT) + + mp_sizeof_uint(changes); if (!stailq_empty(autoinc_id_list)) { struct autoinc_id_entry *id_entry; stailq_foreach_entry(id_entry, autoinc_id_list, link) { @@ -691,8 +705,6 @@ err: } } } - iproto_reply_sql(out, &header_svp, response->sync, schema_version, - keys); finish: port_destroy(&response->port); sqlite3_finalize(stmt); diff --git a/src/box/execute.h b/src/box/execute.h index 79cee69..5f3d5eb 100644 --- a/src/box/execute.h +++ b/src/box/execute.h @@ -104,13 +104,14 @@ struct sql_response { * | } | * +----------------------------------------------+ * @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, struct obuf *out); +sql_response_dump(struct sql_response *response, int *keys, struct obuf *out); /** * Parse the EXECUTE request. @@ -141,16 +142,6 @@ sql_prepare_and_execute(const struct sql_request *request, #if defined(__cplusplus) } /* extern "C" { */ -#include "diag.h" - -/** @copydoc sql_request_decode. Throws on error. */ -static inline void -xrow_decode_sql_xc(const struct xrow_header *row, struct sql_request *request, - struct region *region) -{ - if (xrow_decode_sql(row, request, region) != 0) - diag_raise(); -} #endif #endif /* TARANTOOL_SQL_EXECUTE_H_INCLUDED */ diff --git a/src/box/iproto.cc b/src/box/iproto.cc index cd61393..7c11d05 100644 --- a/src/box/iproto.cc +++ b/src/box/iproto.cc @@ -1593,8 +1593,16 @@ tx_process_sql(struct cmsg *m) * become out of date during yield. */ out = msg->connection->tx.p_obuf; - if (sql_response_dump(&response, out) != 0) + 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) goto error; + if (sql_response_dump(&response, &keys, out) != 0) { + obuf_rollback_to_svp(out, &header_svp); + goto error; + } + iproto_reply_sql(out, &header_svp, response.sync, schema_version, keys); iproto_wpos_create(&msg->wpos, out); return; error: diff --git a/src/box/xrow.c b/src/box/xrow.c index 567b7ed..76c6f81 100644 --- a/src/box/xrow.c +++ b/src/box/xrow.c @@ -445,51 +445,6 @@ iproto_prepare_header(struct obuf *buf, struct obuf_svp *svp, size_t size) return 0; } -struct PACKED iproto_key_bin { - uint8_t key; /* IPROTO_DATA/METADATA/SQL_INFO */ - uint8_t mp_type; - uint32_t mp_len; -}; - -/** - * Write the key to the buffer by the specified savepoint. - * @param buf Output buffer. - * @param type Value type (MP_ARRAY32=0xdd, MP_MAP32=0xdf, ...). - * @param size Value size (array or map length). - * @param key Key value (IPROTO_DATA/DESCRIPTION/SQL_INFO). - * - * @retval 0 Success. - * @retval -1 Memory error. - */ -static inline int -iproto_reply_key(struct obuf *buf, uint8_t type, uint32_t size, uint8_t key) -{ - char *pos = (char *) obuf_alloc(buf, IPROTO_KEY_HEADER_LEN); - if (pos == NULL) { - diag_set(OutOfMemory, IPROTO_KEY_HEADER_LEN, "obuf_alloc", - "pos"); - return -1; - } - struct iproto_key_bin bin; - bin.key = key; - bin.mp_type = type; - bin.mp_len = mp_bswap_u32(size); - memcpy(pos, &bin, sizeof(bin)); - return 0; -} - -int -iproto_reply_array_key(struct obuf *buf, uint32_t size, uint8_t key) -{ - return iproto_reply_key(buf, 0xdd, size, key); -} - -int -iproto_reply_map_key(struct obuf *buf, uint32_t size, uint8_t key) -{ - return iproto_reply_key(buf, 0xdf, size, key); -} - void iproto_reply_select(struct obuf *buf, struct obuf_svp *svp, uint64_t sync, uint32_t schema_version, uint32_t count) diff --git a/src/box/xrow.h b/src/box/xrow.h index 881d860..ca8d04d 100644 --- a/src/box/xrow.h +++ b/src/box/xrow.h @@ -53,11 +53,6 @@ enum { /** 7 = sizeof(iproto_body_bin). */ IPROTO_SELECT_HEADER_LEN = IPROTO_HEADER_LEN + 7, /** - * mp_sizeof(IPROTO_DATA/METADATA/SQL_INFO) + - * mp_sizeof_array(UINT32_MAX). - */ - IPROTO_KEY_HEADER_LEN = 1 + 5, - /** * 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). @@ -423,20 +418,6 @@ iproto_reply_select(struct obuf *buf, struct obuf_svp *svp, uint64_t sync, uint32_t schema_version, uint32_t count); /** - * Write header of the key to a preallocated buffer by svp. - * @param buf Buffer to write to. - * @param size Size of the key (length of the array or of the - * string). - * @param key Body key. - */ -int -iproto_reply_array_key(struct obuf *buf, uint32_t size, uint8_t key); - -/** @copydoc iproto_reply_array_key. */ -int -iproto_reply_map_key(struct obuf *buf, uint32_t size, uint8_t key); - -/** * Encode iproto header with IPROTO_OK response code. * @param out Encode to. * @param sync Request sync. -- 2.7.4