[Tarantool-patches] [PATCH v12 4/8] module_cache: direct update a cache value on reload
Cyrill Gorcunov
gorcunov at gmail.com
Mon Jan 18 23:35:52 MSK 2021
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 at gmail.com>
---
src/box/module_cache.c | 27 ++++++++++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/src/box/module_cache.c b/src/box/module_cache.c
index 8ae61a883..48e55f421 100644
--- a/src/box/module_cache.c
+++ b/src/box/module_cache.c
@@ -422,6 +422,21 @@ module_sym_call(struct module_sym *mod_sym, struct port *args,
return rc;
}
+/**
+ * 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)->val = module;
+ return 0;
+}
+
int
module_reload(const char *package, const char *package_end,
struct module **module)
@@ -453,9 +468,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
More information about the Tarantool-patches
mailing list