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 40BDC6C7D4; Wed, 3 Feb 2021 01:16:14 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 40BDC6C7D4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1612304174; bh=9ctrBZt07xzWlYPn3LnQlCYpYd9xcFT7RiVJH9E4dTA=; 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=e6cfiJoEYEOEcqqUDshj8gZ+ZFDGTLu4wef6xWeLwLXmHHSRZjk7EzSpStosKFjuY QtR8JJ9DvUk5qjbazcVIegPaCnZB047MffiokeYVvtkljERJ34UOYVLiGhYzFfW/G4 rE54Kn8C2Zw6WfKtBOS+xbkEhuV5NefBSIyWB0zA= Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (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 C3FF5795FF for ; Wed, 3 Feb 2021 01:13:50 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org C3FF5795FF Received: by mail-lf1-f45.google.com with SMTP id b2so30409474lfq.0 for ; Tue, 02 Feb 2021 14:13:50 -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=iIXHKZwc6XvBa+rA4KWEsuTt9nW8uoBaU/mUElp+vY0=; b=GFXSrrJK3PCsjYO2umJ6yOQomWYG5l3bd+yVwEqwCUie38MBqsMhtLCeEo0im6/AE1 h+dYIe0JZGViV1Q7T4XF80rXzdgqFCISgkdYfOmf2e8pRNaD3T1mjJWc1lrR17iEyuz6 i5mVKlt2Vuhj1Plmj1mRZbJwryZvIdsTyY91DrTi7qgYd0V7vR1Qx5v17Eu0XJRHuzPJ ZZwMkxx+OGWQbYgd3vdel2QFo1hvWtwn3jfn2EEtPjg3hUe8x5g1fjDY5TXVJzw9+qqH ipJ8EzeCbNbLtbgErEHqKcG3F/OrC3ivq2A7uzKgNgQmMMBXGU+vWqBzUr5vYtNdnCrg cq7Q== X-Gm-Message-State: AOAM530KkBN6g5oFwMi0uA+JQKxYZvNsF0KCMJOfQhY7a12XHOFnYJPw YL1SdS158OluIB2XnCaOeKcNhYA1V/0= X-Google-Smtp-Source: ABdhPJyjJleoamJiQlfm6BLow0BZnN8aFzpNcwibNGQjTRNBef+RCSCs02lVDdExFPCo0Bx7T1CwjQ== X-Received: by 2002:a19:3fd3:: with SMTP id m202mr40438lfa.550.1612304029292; Tue, 02 Feb 2021 14:13:49 -0800 (PST) Received: from grain.localdomain ([5.18.103.226]) by smtp.gmail.com with ESMTPSA id g22sm29145lfh.232.2021.02.02.14.13.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Feb 2021 14:13:48 -0800 (PST) Received: by grain.localdomain (Postfix, from userid 1000) id 967E45602A1; Wed, 3 Feb 2021 01:12:08 +0300 (MSK) To: tml Date: Wed, 3 Feb 2021 01:12:03 +0300 Message-Id: <20210202221207.383101-9-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 08/12] module_cache: make module to carry hash it belongs to 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" We will need two hashes for backward compatibility sake, thus make module structure to carry the hash it belongs. Part-of #4642 Signed-off-by: Cyrill Gorcunov --- src/box/module_cache.c | 66 ++++++++++++++++++++++++------------------ src/box/module_cache.h | 4 +++ 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/src/box/module_cache.c b/src/box/module_cache.c index bb6ef39cd..d09947719 100644 --- a/src/box/module_cache.c +++ b/src/box/module_cache.c @@ -72,12 +72,13 @@ func_split_name(const char *str, struct func_name *name) * Look up a module in the modules cache. */ static struct module * -module_cache_find(const char *name, const char *name_end) +module_cache_find(struct mh_strnptr_t *h, const char *name, + const char *name_end) { - mh_int_t e = mh_strnptr_find_inp(mod_hash, name, name_end - name); - if (e == mh_end(mod_hash)) + mh_int_t e = mh_strnptr_find_inp(h, name, name_end - name); + if (e == mh_end(h)) return NULL; - return mh_strnptr_node(mod_hash, e)->val; + return mh_strnptr_node(h, e)->val; } /** @@ -86,6 +87,7 @@ module_cache_find(const char *name, const char *name_end) static int module_cache_add(struct module *module) { + struct mh_strnptr_t *h = module->hash; size_t package_len = strlen(module->package); const struct mh_strnptr_node_t nd = { .str = module->package, @@ -94,7 +96,7 @@ module_cache_add(struct module *module) .val = module, }; - if (mh_strnptr_put(mod_hash, &nd, NULL, NULL) == mh_end(mod_hash)) { + if (mh_strnptr_put(h, &nd, NULL, NULL) == mh_end(h)) { diag_set(OutOfMemory, sizeof(nd), "malloc", "module cache node"); return -1; @@ -107,14 +109,17 @@ module_cache_add(struct module *module) * key based it is safe to just update the value. */ static int -module_cache_update(const char *name, const char *name_end, - struct module *module) +module_cache_update(struct module *module) { - mh_int_t e = mh_strnptr_find_inp(mod_hash, name, name_end - name); - if (e == mh_end(mod_hash)) + struct mh_strnptr_t *h = module->hash; + const char *name = module->package; + size_t len = strlen(module->package); + + mh_int_t e = mh_strnptr_find_inp(h, name, len); + if (e == mh_end(h)) return -1; - mh_strnptr_node(mod_hash, e)->str = module->package; - mh_strnptr_node(mod_hash, e)->val = module; + mh_strnptr_node(h, e)->str = module->package; + mh_strnptr_node(h, e)->val = module; return 0; } @@ -122,11 +127,15 @@ module_cache_update(const char *name, const char *name_end, * Delete a module from the modules cache. */ static void -module_cache_del(const char *name, const char *name_end) +module_cache_del(struct module *module) { - mh_int_t e = mh_strnptr_find_inp(mod_hash, name, name_end - name); - if (e != mh_end(mod_hash)) - mh_strnptr_del(mod_hash, e, NULL); + struct mh_strnptr_t *h = module->hash; + const char *name = module->package; + size_t len = strlen(module->package); + + mh_int_t e = mh_strnptr_find_inp(h, name, len); + if (e != mh_end(h)) + mh_strnptr_del(h, e, NULL); } /** @@ -135,7 +144,7 @@ module_cache_del(const char *name, const char *name_end) static void module_set_orphan(struct module *module) { - module->package[0] = '\0'; + module->hash = NULL; } /** @@ -144,7 +153,7 @@ module_set_orphan(struct module *module) static bool module_is_orphan(struct module *module) { - return module->package[0] == '\0'; + return module->hash == NULL; } /** @@ -256,11 +265,8 @@ module_unref(struct module *module) { assert(module->refs > 0); if (module->refs-- == 1) { - if (!module_is_orphan(module)) { - size_t len = strlen(module->package); - module_cache_del(module->package, - &module->package[len]); - } + if (!module_is_orphan(module)) + module_cache_del(module); module_delete(module); } } @@ -273,7 +279,8 @@ module_unref(struct module *module) * for cases of a function reload. */ static struct module * -module_load(const char *package, const char *package_end) +module_load(struct mh_strnptr_t *h, const char *package, + const char *package_end) { char path[PATH_MAX]; if (module_find(package, package_end, path, sizeof(path)) != 0) @@ -290,6 +297,7 @@ module_load(const char *package, const char *package_end) module->package[package_len] = 0; rlist_create(&module->funcs_list); module->refs = 0; + module->hash = h; const char *tmpdir = getenv("TMPDIR"); if (tmpdir == NULL) @@ -396,9 +404,9 @@ module_sym_load(struct module_sym *mod_sym) * loading and take it from the cache. */ struct module *cached, *module; - cached = module_cache_find(name.package, name.package_end); + cached = module_cache_find(mod_hash, name.package, name.package_end); if (cached == NULL) { - module = module_load(name.package, name.package_end); + module = module_load(mod_hash, name.package, name.package_end); if (module == NULL) return -1; if (module_cache_add(module) != 0) { @@ -498,13 +506,15 @@ module_sym_call(struct module_sym *mod_sym, struct port *args, int module_reload(const char *package, const char *package_end) { - struct module *old = module_cache_find(package, package_end); + struct module *old, *new; + + old = module_cache_find(mod_hash, package, package_end); if (old == NULL) { diag_set(ClientError, ER_NO_SUCH_MODULE, package); return -1; } - struct module *new = module_load(package, package_end); + new = module_load(mod_hash, package, package_end); if (new == NULL) return -1; @@ -531,7 +541,7 @@ module_reload(const char *package, const char *package_end) module_unref(old); } - if (module_cache_update(package, package_end, new) != 0) { + if (module_cache_update(new) != 0) { /* * Module cache must be consistent at this moment, * we've looked up for the package recently. If diff --git a/src/box/module_cache.h b/src/box/module_cache.h index fa62628c3..874cc081c 100644 --- a/src/box/module_cache.h +++ b/src/box/module_cache.h @@ -36,6 +36,10 @@ struct module { * Module dlhandle. */ void *handle; + /** + * Package hash module belongs to. + */ + struct mh_strnptr_t *hash; /** * List of associated symbols (functions). */ -- 2.29.2