From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp49.i.mail.ru (smtp49.i.mail.ru [94.100.177.109]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 6411F4696CC for ; Mon, 20 Apr 2020 01:25:21 +0300 (MSK) From: Leonid Vasiliev Date: Mon, 20 Apr 2020 01:25:11 +0300 Message-Id: <75b76072b2801ab49d6643d2ef4915549ad9cfc5.1587334824.git.lvasiliev@tarantool.org> In-Reply-To: References: In-Reply-To: References: Subject: [Tarantool-patches] [PATCH V6 09/10] iproto: rename IPROTO_ERROR and IPROTO_ERROR_STACK List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: v.shpilevoy@tarantool.org, alexander.turenko@tarantool.org Cc: tarantool-patches@dev.tarantool.org From: Vladislav Shpilevoy IPROTO_ERROR in fact is not an error. It is an error message. Secondly, this key is deprecated in favor of IPROTO_ERROR_STACK, which contains all attributes of the whole error stack. It uses MP_ERROR MessagePack extenstion for that. So IPROTO_ERROR is renamed to IPROTO_ERROR_24 (similar to how old call was renamed to IPROTO_CALL_16). IPROTO_ERROR_STACK becomes new IPROTO_ERROR. Follow up #4398 --- src/box/iproto_constants.h | 4 ++-- src/box/lua/net_box.lua | 25 +++++++++++++------------ src/box/xrow.c | 10 +++++----- test/box/iproto.result | 8 ++++---- test/box/iproto.test.lua | 6 +++--- 5 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/box/iproto_constants.h b/src/box/iproto_constants.h index b57d565..f8eee0f 100644 --- a/src/box/iproto_constants.h +++ b/src/box/iproto_constants.h @@ -101,7 +101,7 @@ enum iproto_key { /* Leave a gap between request keys and response keys */ IPROTO_DATA = 0x30, - IPROTO_ERROR = 0x31, + IPROTO_ERROR_24 = 0x31, /** * IPROTO_METADATA: [ * { IPROTO_FIELD_NAME: name }, @@ -126,7 +126,7 @@ enum iproto_key { /* Leave a gap between SQL keys and additional request keys */ IPROTO_REPLICA_ANON = 0x50, IPROTO_ID_FILTER = 0x51, - IPROTO_ERROR_STACK = 0x52, + IPROTO_ERROR = 0x52, IPROTO_KEY_MAX }; diff --git a/src/box/lua/net_box.lua b/src/box/lua/net_box.lua index 1e55eaa..1b2b6ac 100644 --- a/src/box/lua/net_box.lua +++ b/src/box/lua/net_box.lua @@ -44,8 +44,8 @@ local IPROTO_SQL_INFO_KEY = 0x42 local SQL_INFO_ROW_COUNT_KEY = 0 local IPROTO_FIELD_NAME_KEY = 0 local IPROTO_DATA_KEY = 0x30 -local IPROTO_ERROR_KEY = 0x31 -local IPROTO_ERROR_STACK = 0x52 +local IPROTO_ERROR_24 = 0x31 +local IPROTO_ERROR = 0x52 local IPROTO_GREETING_SIZE = 128 local IPROTO_CHUNK_KEY = 128 local IPROTO_OK_KEY = 0 @@ -150,7 +150,7 @@ local method_decoder = { push = decode_push, } -local function decode_error_stack(raw_data) +local function decode_error(raw_data) local ptr = buffer_reg.acucp ptr[0] = raw_data local err = ffi.C.error_unpack_unsafe(ptr) @@ -170,8 +170,8 @@ local function decode_error_stack(raw_data) end local response_decoder = { - [IPROTO_ERROR_KEY] = decode, - [IPROTO_ERROR_STACK] = decode_error_stack, + [IPROTO_ERROR_24] = decode, + [IPROTO_ERROR] = decode_error, } local function next_id(id) return band(id + 1, 0x7FFFFFFF) end @@ -614,15 +614,16 @@ local function create_transport(host, port, user, password, callback, end assert(body_end == body_rpos, "invalid xrow length") request.errno = band(status, IPROTO_ERRNO_MASK) - -- IPROTO_ERROR_STACK comprises error encoded with - -- IPROTO_ERROR_KEY, so we may ignore content of that key. - if body[IPROTO_ERROR_STACK] ~= nil then - request.response = body[IPROTO_ERROR_STACK] + -- IPROTO_ERROR comprises error encoded with + -- IPROTO_ERROR_24, so we may ignore content of that + -- key. + if body[IPROTO_ERROR] ~= nil then + request.response = body[IPROTO_ERROR] assert(type(request.response) == 'cdata') else request.response = box.error.new({ code = request.errno, - reason = body[IPROTO_ERROR_KEY] + reason = body[IPROTO_ERROR_24] }) end request.cond:broadcast() @@ -800,7 +801,7 @@ local function create_transport(host, port, user, password, callback, if hdr[IPROTO_STATUS_KEY] ~= 0 then local body body, body_end = decode(body_rpos) - return error_sm(E_NO_CONNECTION, body[IPROTO_ERROR_KEY]) + return error_sm(E_NO_CONNECTION, body[IPROTO_ERROR_24]) end set_state('fetch_schema') return iproto_schema_sm(hdr[IPROTO_SCHEMA_VERSION_KEY]) @@ -845,7 +846,7 @@ local function create_transport(host, port, user, password, callback, if status ~= 0 then local body body, body_end = decode(body_rpos) - return error_sm(E_NO_CONNECTION, body[IPROTO_ERROR_KEY]) + return error_sm(E_NO_CONNECTION, body[IPROTO_ERROR_24]) end if schema_version == nil then schema_version = response_schema_version diff --git a/src/box/xrow.c b/src/box/xrow.c index 06c6afb..1b3f3f9 100644 --- a/src/box/xrow.c +++ b/src/box/xrow.c @@ -379,7 +379,7 @@ iproto_header_encode(char *out, uint32_t type, uint64_t sync, struct PACKED iproto_body_bin { uint8_t m_body; /* MP_MAP */ - uint8_t k_data; /* IPROTO_DATA or IPROTO_ERROR */ + uint8_t k_data; /* IPROTO_DATA or errors */ uint8_t m_data; /* MP_STR or MP_ARRAY */ uint32_t v_data_len; /* string length of array size */ }; @@ -496,9 +496,9 @@ static void mpstream_iproto_encode_error(struct mpstream *stream, const struct error *error) { mpstream_encode_map(stream, 2); - mpstream_encode_uint(stream, IPROTO_ERROR); + mpstream_encode_uint(stream, IPROTO_ERROR_24); mpstream_encode_str(stream, error->errmsg); - mpstream_encode_uint(stream, IPROTO_ERROR_STACK); + mpstream_encode_uint(stream, IPROTO_ERROR); error_to_mpstream_noext(error, stream); } @@ -1109,7 +1109,7 @@ xrow_decode_error(struct xrow_header *row) continue; } uint8_t key = mp_decode_uint(&pos); - if (key == IPROTO_ERROR && mp_typeof(*pos) == MP_STR) { + if (key == IPROTO_ERROR_24 && mp_typeof(*pos) == MP_STR) { /* * Obsolete way of sending error responses. * To be deprecated but still should be supported @@ -1119,7 +1119,7 @@ xrow_decode_error(struct xrow_header *row) const char *str = mp_decode_str(&pos, &len); snprintf(error, sizeof(error), "%.*s", len, str); box_error_set(__FILE__, __LINE__, code, error); - } else if (key == IPROTO_ERROR_STACK) { + } else if (key == IPROTO_ERROR) { struct error *e = error_unpack_unsafe(&pos); if (e == NULL) goto error; diff --git a/test/box/iproto.result b/test/box/iproto.result index e4fe684..4b648d3 100644 --- a/test/box/iproto.result +++ b/test/box/iproto.result @@ -25,10 +25,10 @@ IPROTO_FUNCTION_NAME = 0x22 IPROTO_TUPLE = 0x21 --- ... -IPROTO_ERROR = 0x31 +IPROTO_ERROR_24 = 0x31 --- ... -IPROTO_ERROR_STACK = 0x52 +IPROTO_ERROR = 0x52 --- ... IPROTO_ERROR_CODE = 0x01 @@ -92,11 +92,11 @@ sock:close() ... -- Both keys (obsolete and stack ones) are present in response. -- -assert(response.body[IPROTO_ERROR_STACK] ~= nil) +assert(response.body[IPROTO_ERROR] ~= nil) --- - true ... -assert(response.body[IPROTO_ERROR] ~= nil) +assert(response.body[IPROTO_ERROR_24] ~= nil) --- - true ... diff --git a/test/box/iproto.test.lua b/test/box/iproto.test.lua index ec715e9..4af39cc 100644 --- a/test/box/iproto.test.lua +++ b/test/box/iproto.test.lua @@ -9,8 +9,8 @@ IPROTO_SYNC = 0x01 IPROTO_CALL = 0x0A IPROTO_FUNCTION_NAME = 0x22 IPROTO_TUPLE = 0x21 -IPROTO_ERROR = 0x31 -IPROTO_ERROR_STACK = 0x52 +IPROTO_ERROR_24 = 0x31 +IPROTO_ERROR = 0x52 IPROTO_ERROR_CODE = 0x01 IPROTO_ERROR_MESSAGE = 0x02 @@ -49,7 +49,7 @@ sock:close() -- Both keys (obsolete and stack ones) are present in response. -- -assert(response.body[IPROTO_ERROR_STACK] ~= nil) assert(response.body[IPROTO_ERROR] ~= nil) +assert(response.body[IPROTO_ERROR_24] ~= nil) box.schema.user.revoke('guest', 'read,write,execute', 'universe') -- 2.7.4