Tarantool development patches archive
 help / color / mirror / Atom feed
From: Cyrill Gorcunov via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: tml <tarantool-patches@dev.tarantool.org>
Cc: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Subject: [Tarantool-patches] [PATCH v14 09/12] module_cache: use own hash for box.schema.func requests
Date: Wed,  3 Feb 2021 01:12:04 +0300	[thread overview]
Message-ID: <20210202221207.383101-10-gorcunov@gmail.com> (raw)
In-Reply-To: <20210202221207.383101-1-gorcunov@gmail.com>

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 <gorcunov@gmail.com>
---
 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


  parent reply	other threads:[~2021-02-02 22:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-02 22:11 [Tarantool-patches] [PATCH v14 00/12] box: implement cmod Lua module Cyrill Gorcunov via Tarantool-patches
2021-02-02 22:11 ` [Tarantool-patches] [PATCH v14 01/12] box/func: factor out c function entry structure Cyrill Gorcunov via Tarantool-patches
2021-02-02 22:11 ` [Tarantool-patches] [PATCH v14 02/12] module_cache: move module handling into own subsystem Cyrill Gorcunov via Tarantool-patches
2021-02-02 22:11 ` [Tarantool-patches] [PATCH v14 03/12] module_cache: direct update a cache value on reload Cyrill Gorcunov via Tarantool-patches
2021-02-02 22:11 ` [Tarantool-patches] [PATCH v14 04/12] module_cache: rename calls to ref in module structure Cyrill Gorcunov via Tarantool-patches
2021-02-02 22:12 ` [Tarantool-patches] [PATCH v14 05/12] module_cache: add comment about weird resolving Cyrill Gorcunov via Tarantool-patches
2021-02-02 22:12 ` [Tarantool-patches] [PATCH v14 06/12] module_cache: module_reload - drop redundant parameter Cyrill Gorcunov via Tarantool-patches
2021-02-02 22:12 ` [Tarantool-patches] [PATCH v14 07/12] module_cache: use references as a main usage counter Cyrill Gorcunov via Tarantool-patches
2021-02-02 22:12 ` [Tarantool-patches] [PATCH v14 08/12] module_cache: make module to carry hash it belongs to Cyrill Gorcunov via Tarantool-patches
2021-02-02 22:12 ` Cyrill Gorcunov via Tarantool-patches [this message]
2021-02-02 22:12 ` [Tarantool-patches] [PATCH v14 10/12] module_cache: provide module_load/unload calls Cyrill Gorcunov via Tarantool-patches
2021-02-02 22:12 ` [Tarantool-patches] [PATCH v14 11/12] box/cmod: implement cmod Lua module Cyrill Gorcunov via Tarantool-patches
2021-02-02 22:12 ` [Tarantool-patches] [PATCH v14 12/12] test: box/cfunc -- add cmod test Cyrill Gorcunov via Tarantool-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210202221207.383101-10-gorcunov@gmail.com \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=gorcunov@gmail.com \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v14 09/12] module_cache: use own hash for box.schema.func requests' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox