From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 7D58963342; Wed, 3 Feb 2021 01:16:44 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 7D58963342 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1612304204; bh=qB2EgrchCbY/zjCYFTfrNyEJKlQM/3TKiqAfgqAQKtM=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=wJ4tJAaFLuNRzyBjv0h9f0LbyonlVrYa1LBA+wtpt+g2Oi8Qkh6to63IJcd9jNtSM 0Up53hOUatERCaURubZpQkC2rPg/eUnkfKq0aBUx4Kd5XvqoXb0PHZadKnhGd3KApX Ei4cFbHpTBayjNtB9ZxAdrdPCcMyfkJKxDCCsTHM= Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id D5F1B63342 for ; Wed, 3 Feb 2021 01:14:02 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D5F1B63342 Received: by mail-lf1-f46.google.com with SMTP id f1so30386504lfu.3 for ; Tue, 02 Feb 2021 14:14:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4wW3eWCNG9p9R41XgJmA4EqJQnxudqfETvqU5eX2j1s=; b=BT0HxcB6NJLylokHP/NTQF3LzgNxwkWEVu4ZfkZrPRMX84s1zL8RSmND4TktX3y/0B aw4cQStYOKlZaHoFUXMFpZcp3Qk+DKppB89Wykm23BXmmNcwjBYxWMGdeSv7Mx5JjuHA GngG2NNfScaHJBh5XlZaJE583gcnsEW/YYFXOBcbFvq9PX3uq6FRftwXb+RDDo6teq9W Dx5AtCOELnEZDgVniv2URhGaMnmEJkplNmsMKHIHjHJjLLymOKyYOQNadhBuYBdfFFmj 8iyzXlqwUECG08K0Jzi9kTatk0pxiuexUxtVr0bkwj1kbBHn4tYQGlM2ZAzTxSNRCiiX ibSQ== X-Gm-Message-State: AOAM530G3qbDOu8aE0axxHZ+JPaj/FPzMlLUXpyqLcjWVqfj8v3NptLa TJKWo5QcOFBrOF+Xbw+icwDi6xbhcwM= X-Google-Smtp-Source: ABdhPJyNj+Do+4ak+zcgtU0YDgW0sX7KtCR3Wb9uR+SnYG1DBPv9InusmrIIDXQciCnqR6kBi8BPhg== X-Received: by 2002:a05:6512:752:: with SMTP id c18mr17868lfs.523.1612304041560; Tue, 02 Feb 2021 14:14:01 -0800 (PST) Received: from grain.localdomain ([5.18.103.226]) by smtp.gmail.com with ESMTPSA id z17sm30232lfe.135.2021.02.02.14.14.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Feb 2021 14:14:00 -0800 (PST) Received: by grain.localdomain (Postfix, from userid 1000) id 98D4A5602A2; Wed, 3 Feb 2021 01:12:08 +0300 (MSK) To: tml Date: Wed, 3 Feb 2021 01:12:04 +0300 Message-Id: <20210202221207.383101-10-gorcunov@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210202221207.383101-1-gorcunov@gmail.com> References: <20210202221207.383101-1-gorcunov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v14 09/12] module_cache: use own hash for box.schema.func requests X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Cyrill Gorcunov via Tarantool-patches Reply-To: Cyrill Gorcunov Cc: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" This is needed to distinguish requests from future `cmod` module (which gonna be detecting modules renew automatically) and old `box.schema.func` interface. To make it clear use `box_schema_hash` for such modules. Part-of #4642 Signed-off-by: Cyrill Gorcunov --- src/box/module_cache.c | 48 ++++++++++++++++++++++++++++-------------- src/box/module_cache.h | 3 ++- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/box/module_cache.c b/src/box/module_cache.c index d09947719..f9ed6e7d8 100644 --- a/src/box/module_cache.c +++ b/src/box/module_cache.c @@ -23,7 +23,7 @@ #include "module_cache.h" /** Modules name to descriptor hash. */ -static struct mh_strnptr_t *mod_hash = NULL; +static struct mh_strnptr_t *box_schema_hash = NULL; /** * Parsed symbol and package names. @@ -45,6 +45,16 @@ struct func_name { const char *package_end; }; +/** + * Return module hash depending on where request comes + * from: if it is legacy `box.schema.func` interface or not. + */ +static inline struct mh_strnptr_t * +hash_tbl(bool is_box_schema) +{ + return is_box_schema ? box_schema_hash : NULL; +} + /*** * Split function name to symbol and package names. * @@ -391,7 +401,7 @@ module_sym(struct module *module, const char *name) } int -module_sym_load(struct module_sym *mod_sym) +module_sym_load(struct module_sym *mod_sym, bool is_box_schema) { assert(mod_sym->addr == NULL); @@ -404,9 +414,10 @@ module_sym_load(struct module_sym *mod_sym) * loading and take it from the cache. */ struct module *cached, *module; - cached = module_cache_find(mod_hash, name.package, name.package_end); + struct mh_strnptr_t *h = hash_tbl(is_box_schema); + cached = module_cache_find(h, name.package, name.package_end); if (cached == NULL) { - module = module_load(mod_hash, name.package, name.package_end); + module = module_load(h, name.package, name.package_end); if (module == NULL) return -1; if (module_cache_add(module) != 0) { @@ -463,7 +474,7 @@ module_sym_call(struct module_sym *mod_sym, struct port *args, * compatibility sake! */ if (mod_sym->addr == NULL) { - if (module_sym_load(mod_sym) != 0) + if (module_sym_load(mod_sym, true) != 0) return -1; } @@ -508,13 +519,17 @@ module_reload(const char *package, const char *package_end) { struct module *old, *new; - old = module_cache_find(mod_hash, package, package_end); + /* + * Explicit module reloading is deprecated interface, + * so always use box_schema_hash. + */ + old = module_cache_find(box_schema_hash, package, package_end); if (old == NULL) { diag_set(ClientError, ER_NO_SUCH_MODULE, package); return -1; } - new = module_load(mod_hash, package, package_end); + new = module_load(box_schema_hash, package, package_end); if (new == NULL) return -1; @@ -591,10 +606,10 @@ module_reload(const char *package, const char *package_end) int module_init(void) { - mod_hash = mh_strnptr_new(); - if (mod_hash == NULL) { - diag_set(OutOfMemory, sizeof(*mod_hash), - "malloc", "modules hash table"); + box_schema_hash = mh_strnptr_new(); + if (box_schema_hash == NULL) { + diag_set(OutOfMemory, sizeof(*box_schema_hash), + "malloc", "modules box_schema_hash"); return -1; } return 0; @@ -603,11 +618,12 @@ module_init(void) void module_free(void) { - while (mh_size(mod_hash) > 0) { - mh_int_t i = mh_first(mod_hash); - struct module *m = mh_strnptr_node(mod_hash, i)->val; + struct mh_strnptr_t *h = box_schema_hash; + while (mh_size(h) > 0) { + mh_int_t i = mh_first(h); + struct module *m = mh_strnptr_node(h, i)->val; module_unref(m); } - mh_strnptr_delete(mod_hash); - mod_hash = NULL; + mh_strnptr_delete(box_schema_hash); + box_schema_hash = NULL; } diff --git a/src/box/module_cache.h b/src/box/module_cache.h index 874cc081c..875f2eb3c 100644 --- a/src/box/module_cache.h +++ b/src/box/module_cache.h @@ -80,11 +80,12 @@ struct module_sym { * Load a new module symbol. * * @param mod_sym symbol to load. + * @param is_box_schema flag if request comes from `box.schema.func`. * * @returns 0 on succse, -1 otherwise, diag is set. */ int -module_sym_load(struct module_sym *mod_sym); +module_sym_load(struct module_sym *mod_sym, bool is_box_schema); /** * Unload a module's symbol. -- 2.29.2