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 08D9D257E7 for ; Mon, 4 Jun 2018 15:21:20 -0400 (EDT) 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 2FvjYzZKBRTX for ; Mon, 4 Jun 2018 15:21:19 -0400 (EDT) Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (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 AF985257CA for ; Mon, 4 Jun 2018 15:21:19 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH v1 3/4] box: introduce box_space_id_by_name References: <95c32aa69c7040aa5a63164e19de8ac8f06d9ce3.1527765756.git.kshcherbatov@tarantool.org> <91765db9-575c-9d10-c678-ff1f3b230735@tarantool.org> From: Kirill Shcherbatov Message-ID: Date: Mon, 4 Jun 2018 22:21:17 +0300 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit 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 Cc: "v.shpilevoy@tarantool.org" > 1. Lets change commit title: the patch does not introduce > box_space_id_by_name. It was before the patch. box: port schema_find_id to C Part of #3273. > 2. How can you return -1, when the return type is unsigned? > 3. It is not 'space_id' speaking in general. This function is used in > user.cc also to search user id by the name. Please, find another name > for the parameter. > 4. "new slab" -> "key". OutOfMemory takes size, alloc function and > the result variable name. > 5. You should avoid 'goto cleanup' here. diff --git a/src/box/schema.cc b/src/box/schema.cc index c5055ee..a85a09f 100644 --- a/src/box/schema.cc +++ b/src/box/schema.cc @@ -222,11 +222,11 @@ sc_space_new(uint32_t id, const char *name, struct key_def *key_def, trigger_run_xc(&on_alter_space, space); } -uint32_t +int schema_find_id(uint32_t system_space_id, uint32_t index_id, - const char *name, uint32_t len, uint32_t *space_id) + const char *name, uint32_t len, uint32_t *object_id) { - *space_id = BOX_ID_NIL; + *object_id = BOX_ID_NIL; if (len > BOX_NAME_MAX) { diag_set(SystemError, "name length %d is greater than BOX_NAME_MAX", len); @@ -248,7 +248,7 @@ schema_find_id(uint32_t system_space_id, uint32_t index_id, uint32_t used = region_used(region); char *key = (char *)region_alloc(region, size); if (key == NULL) { - diag_set(OutOfMemory, size, "region", "new slab"); + diag_set(OutOfMemory, size, "region", "key"); return -1; } mp_encode_str(key, name, len); @@ -261,13 +261,10 @@ schema_find_id(uint32_t system_space_id, uint32_t index_id, struct tuple *tuple; if (iterator_next(it, &tuple) != 0) { rc = -1; - goto cleanup; - } - if (tuple) { + } else if (tuple) { /* id is always field #1 */ - *space_id = tuple_field_u32_xc(tuple, 0); + *object_id = tuple_field_u32_xc(tuple, 0); } -cleanup: iterator_delete(it); region_truncate(region, used); return rc; > 6. Same. Do not mention space. It is a function to find ID of > any system object. Not only space. This function is applicable > for _index, _space, _user, _func. diff --git a/src/box/schema.h b/src/box/schema.h index 099f9b0..cd9bb5b 100644 --- a/src/box/schema.h +++ b/src/box/schema.h @@ -107,16 +107,16 @@ sequence_by_id(uint32_t id); * * @param system_space_id identifier of the system space. * @param index_id identifier of the index to lookup. - * @param name space to lookup name. + * @param name of object to lookup. * @param len length of a name. - * @param space_id[out] space_id BOX_ID_NIL - not found. + * @param object_id[out] object_id or BOX_ID_NIL - not found. * * @retval 0 on success. * @retval -1 on error. */ -uint32_t +int schema_find_id(uint32_t system_space_id, uint32_t index_id, - const char *name, uint32_t len, uint32_t *space_id); + const char *name, uint32_t len, uint32_t *object_id); #if defined(__cplusplus) } /* extern "C" */