From: Cyrill Gorcunov via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: tml <tarantool-patches@dev.tarantool.org>
Cc: Mons Anderson <v.perepelitsa@corp.mail.ru>,
Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Subject: [Tarantool-patches] [PATCH v15 03/11] module_cache: direct update a cache value on reload
Date: Fri, 5 Feb 2021 21:54:28 +0300 [thread overview]
Message-ID: <20210205185436.638894-4-gorcunov@gmail.com> (raw)
In-Reply-To: <20210205185436.638894-1-gorcunov@gmail.com>
Currently when we reload modules we remove old instance
from the module cache and then try to insert a new one
back. Note that module cache is a string based hash table:
we lookup for a pointer to the module via package name.
Thus when reload initiated we simply remove same key
from hash and put it back with a new pointer. This is
too complex and completely useless. Instead we should
simply update the value associated this the key in the
hash table. For this sake we introduce module_cache_update
helper.
Part-of #4642
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
---
src/box/module_cache.c | 28 +++++++++++++++++++++++++---
1 file changed, 25 insertions(+), 3 deletions(-)
diff --git a/src/box/module_cache.c b/src/box/module_cache.c
index 4d89baf9b..90d18fa73 100644
--- a/src/box/module_cache.c
+++ b/src/box/module_cache.c
@@ -102,6 +102,22 @@ module_cache_add(struct module *module)
return 0;
}
+/**
+ * Update the module cache. Since the lookup is string
+ * 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)
+{
+ mh_int_t e = mh_strnptr_find_inp(mod_hash, name, name_end - name);
+ if (e == mh_end(mod_hash))
+ return -1;
+ mh_strnptr_node(mod_hash, e)->str = module->package;
+ mh_strnptr_node(mod_hash, e)->val = module;
+ return 0;
+}
+
/**
* Delete a module from the modules cache.
*/
@@ -475,9 +491,15 @@ module_reload(const char *package, const char *package_end,
rlist_move(&new->funcs_list, &mod_sym->item);
}
- module_cache_del(package, package_end);
- if (module_cache_add(new) != 0)
- goto restore;
+ if (module_cache_update(package, package_end, new) != 0) {
+ /*
+ * Module cache must be consistent at this moment,
+ * we've looked up for the package recently. If
+ * someone has updated the cache in unexpected way
+ * the consistency is lost and we must not continue.
+ */
+ panic("module: can't update module cache (%s)", package);
+ }
module_gc(old);
*module = new;
--
2.29.2
next prev parent reply other threads:[~2021-02-05 18:56 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-05 18:54 [Tarantool-patches] [PATCH v15 00/11] box: implement cmod Lua module Cyrill Gorcunov via Tarantool-patches
2021-02-05 18:54 ` [Tarantool-patches] [PATCH v15 01/11] box/func: factor out c function entry structure Cyrill Gorcunov via Tarantool-patches
2021-02-05 18:54 ` [Tarantool-patches] [PATCH v15 02/11] module_cache: move module handling into own subsystem Cyrill Gorcunov via Tarantool-patches
2021-02-07 17:20 ` Vladislav Shpilevoy via Tarantool-patches
2021-02-05 18:54 ` Cyrill Gorcunov via Tarantool-patches [this message]
2021-02-05 18:54 ` [Tarantool-patches] [PATCH v15 04/11] module_cache: rename calls to ref in module structure Cyrill Gorcunov via Tarantool-patches
2021-02-05 18:54 ` [Tarantool-patches] [PATCH v15 05/11] module_cache: add comment about weird resolving Cyrill Gorcunov via Tarantool-patches
2021-02-05 18:54 ` [Tarantool-patches] [PATCH v15 06/11] module_cache: module_reload - drop redundant parameter Cyrill Gorcunov via Tarantool-patches
2021-02-05 18:54 ` [Tarantool-patches] [PATCH v15 07/11] module_cache: use references as a main usage counter Cyrill Gorcunov via Tarantool-patches
2021-02-07 17:20 ` Vladislav Shpilevoy via Tarantool-patches
2021-02-08 11:54 ` Cyrill Gorcunov via Tarantool-patches
2021-02-05 18:54 ` [Tarantool-patches] [PATCH v15 08/11] module_cache: make module to carry hash it belongs to Cyrill Gorcunov via Tarantool-patches
2021-02-07 17:20 ` Vladislav Shpilevoy via Tarantool-patches
2021-02-05 18:54 ` [Tarantool-patches] [PATCH v15 09/11] module_cache: use own hash for box.schema.func requests Cyrill Gorcunov via Tarantool-patches
2021-02-07 17:20 ` Vladislav Shpilevoy via Tarantool-patches
2021-02-05 18:54 ` [Tarantool-patches] [PATCH v15 10/11] box/cmod: implement cmod Lua module Cyrill Gorcunov via Tarantool-patches
2021-02-07 17:20 ` Vladislav Shpilevoy via Tarantool-patches
2021-02-05 18:54 ` [Tarantool-patches] [PATCH v15 11/11] test: box/cfunc -- add cmod test Cyrill Gorcunov via Tarantool-patches
2021-02-07 17:20 ` Vladislav Shpilevoy via Tarantool-patches
2021-02-07 17:21 ` Vladislav Shpilevoy via Tarantool-patches
2021-02-06 17:55 ` [Tarantool-patches] [PATCH v15 00/11] box: implement cmod Lua module Vladislav Shpilevoy 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=20210205185436.638894-4-gorcunov@gmail.com \
--to=tarantool-patches@dev.tarantool.org \
--cc=gorcunov@gmail.com \
--cc=v.perepelitsa@corp.mail.ru \
--cc=v.shpilevoy@tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH v15 03/11] module_cache: direct update a cache value on reload' \
/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