[Tarantool-patches] [PATCH v12 4/8] module_cache: direct update a cache value on reload

Cyrill Gorcunov gorcunov at gmail.com
Tue Jan 19 15:46:49 MSK 2021


On Mon, Jan 18, 2021 at 11:35:52PM +0300, Cyrill Gorcunov wrote:
> 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.

This approach doesn't work. An update patch attached. I force pushed the update.
---
From: Cyrill Gorcunov <gorcunov at gmail.com>
Date: Tue, 12 Jan 2021 11:53:50 +0300
Subject: [PATCH v12 4/8] module_cache: panic if module cache update failed

Currently when we reload modules we remove old instance
from the module cache and then try to insert a new one
back. If error happens inbetween (say machine reached
lack of memory and hash resize failed) we try to restore
functions on old module. This is fine but we can't continue
working with modules -- next reload action won't find
the module in hash and won't reload. Since this is a really
rare case plain panic should be fine here.

Part-of #4642

Signed-off-by: Cyrill Gorcunov <gorcunov at gmail.com>
---
 src/box/module_cache.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/src/box/module_cache.c b/src/box/module_cache.c
index 8ae61a883..ccf079d7a 100644
--- a/src/box/module_cache.c
+++ b/src/box/module_cache.c
@@ -422,6 +422,24 @@ module_sym_call(struct module_sym *mod_sym, struct port *args,
 	return rc;
 }
 
+/**
+ * Update the module cache.
+ */
+static void
+module_cache_update(const char *package, const char *package_end,
+		    struct module *module)
+{
+	/*
+	 * Due to hash internals we need to remove old node
+	 * and insert a new one. If there some memory pressure
+	 * happen between these actions we would loose the hash
+	 * node and this make inconsistent the next modules reload.
+	 */
+	module_cache_del(package, package_end);
+	if (module_cache_add(module) != 0)
+		panic("module: can't update module cache (%s)", package);
+}
+
 int
 module_reload(const char *package, const char *package_end,
 	      struct module **module)
@@ -453,10 +471,7 @@ 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;
-
+	module_cache_update(package, package_end, new);
 	module_gc(old);
 	*module = new;
 	return 0;
-- 
2.29.2



More information about the Tarantool-patches mailing list