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 70CA86C7D3; Fri, 5 Feb 2021 21:59:12 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 70CA86C7D3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1612551552; bh=bLWdfLwyUXwJZ+P2cgzXdUhrYCSDER55LrXmsl8Hk+o=; 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=U0W+NDhkM6xoSqWZUp7Cnfa3R1vIik5EMLB8iMR1EMyYpWEgjPZGhCss3Zhrf7TCk pNsYFlpAvK8Ix+JRtabqu3O3Yc0OF+n0TRidE8kMzjcdPSIUkLFsa1YCbo/edx6rSv lUe3glU3s34adS1Bxmd/PgGAtwZhEYdiDn/jRCuk= Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (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 655A16C7D3 for ; Fri, 5 Feb 2021 21:56:28 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 655A16C7D3 Received: by mail-lf1-f53.google.com with SMTP id f1so11369119lfu.3 for ; Fri, 05 Feb 2021 10:56:28 -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=R2x+OC2d5MRk360qFdyhSLramsv+fZTX/aXXz1+0OJE=; b=HKxMy7qvLWs6AZmJvxCQO8sKjkDEX7w7WCfKoq6o9k0k04tIXpdHht53ztNLbGGqWe Zfc/ayJvY4uO8lgPPFrygr9XzXM5Ua+oyAfGruu5eZ3zcZB7s4dTSOjFv5h+ktTp+jMM EReBWB2p17iw9X6mxquXVjJtI5iT/fIa8h5DYU+z0ZRGoMHR9dHtG5lzhMYafNdqu+Ft QGxviNjGZVv8LefgbFJ0jjGAfxeGY5d41uqOuWi76Nb5ycixm6puQ5Tx0YQeWnXEbw8y ou3FKpX2+F2g6Elh22gL6TUTvb2nwK9N/9Nm9JaJ/w2zNSdtlmpB8jme+cRPVe+jrNLq FgVw== X-Gm-Message-State: AOAM531Ft2TIiaUckvXseFjlzw2CiuDfXRzXlQaijSbIM4XVeejI04DP cUJ9uaAJVP+Zk6TdjXevJb4= X-Google-Smtp-Source: ABdhPJwSJRVvGCDjJveEq48eZUR84VzhvRB6JQOgXdgKUsCDAFlsRwYdjdCUstI1ycprRvuz+FHXiw== X-Received: by 2002:a19:341:: with SMTP id 62mr3274277lfd.196.1612551387978; Fri, 05 Feb 2021 10:56:27 -0800 (PST) Received: from grain.localdomain ([5.18.103.226]) by smtp.gmail.com with ESMTPSA id f19sm1106342ljn.111.2021.02.05.10.56.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Feb 2021 10:56:25 -0800 (PST) Received: by grain.localdomain (Postfix, from userid 1000) id A4A3D56029B; Fri, 5 Feb 2021 21:54:37 +0300 (MSK) To: tml Date: Fri, 5 Feb 2021 21:54:34 +0300 Message-Id: <20210205185436.638894-10-gorcunov@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210205185436.638894-1-gorcunov@gmail.com> References: <20210205185436.638894-1-gorcunov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v15 09/11] 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: Mons Anderson , 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 786e49cba..22b906fd7 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