Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH] func: clean the module cache on first load error
@ 2020-11-13 12:28 Cyrill Gorcunov
  2020-11-13 12:29 ` Cyrill Gorcunov
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Cyrill Gorcunov @ 2020-11-13 12:28 UTC (permalink / raw)
  To: tml; +Cc: Vladislav Shpilevoy

In case if we're loading a fresh module we put it
into a module's cache first which allows us to not
reload same module twice (say there could be several
functions in same module).

But if the module is loaded for the first time and
symbol resolution failed we continue keeping this
module loaded even if there may be no more use of
it. Thus make a cleanup if needed.

There is no portable way to verify via test as far
as I know, just manually via "lsof -p `pidof tarantool`".

Fixes #5475

Reported-by: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
---
 src/box/func.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/src/box/func.c b/src/box/func.c
index 8087c953f..9909cee45 100644
--- a/src/box/func.c
+++ b/src/box/func.c
@@ -528,10 +528,9 @@ func_c_load(struct func_c *func)
 	struct func_name name;
 	func_split_name(func->base.def->name, &name);
 
-	struct module *module = module_cache_find(name.package,
-						  name.package_end);
-	if (module == NULL) {
-		/* Try to find loaded module in the cache */
+	struct module *cached, *module;
+	cached = module_cache_find(name.package, name.package_end);
+	if (cached == NULL) {
 		module = module_load(name.package, name.package_end);
 		if (module == NULL)
 			return -1;
@@ -539,11 +538,27 @@ func_c_load(struct func_c *func)
 			module_delete(module);
 			return -1;
 		}
+	} else {
+		module = cached;
 	}
 
 	func->func = module_sym(module, name.sym);
-	if (func->func == NULL)
+	if (func->func == NULL) {
+		if (cached == NULL) {
+			/*
+			 * In case if it was a first load we should
+			 * clean the cache immediately otherwise
+			 * the module continue being referenced even
+			 * if there will be no use of it.
+			 *
+			 * Note the module_sym set an error thus be
+			 * careful to not wipe it.
+			 */
+			module_cache_del(name.package, name.package_end);
+			module_delete(module);
+		}
 		return -1;
+	}
 	func->module = module;
 	rlist_add(&module->funcs, &func->item);
 	return 0;
-- 
2.26.2

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Tarantool-patches] [PATCH] func: clean the module cache on first load error
  2020-11-13 12:28 [Tarantool-patches] [PATCH] func: clean the module cache on first load error Cyrill Gorcunov
@ 2020-11-13 12:29 ` Cyrill Gorcunov
  2020-11-18 21:30 ` Vladislav Shpilevoy
  2020-11-26 21:25 ` Vladislav Shpilevoy
  2 siblings, 0 replies; 5+ messages in thread
From: Cyrill Gorcunov @ 2020-11-13 12:29 UTC (permalink / raw)
  To: tml; +Cc: Vladislav Shpilevoy

On Fri, Nov 13, 2020 at 03:28:02PM +0300, Cyrill Gorcunov wrote:
> In case if we're loading a fresh module we put it
> into a module's cache first which allows us to not
> reload same module twice (say there could be several
> functions in same module).
>

branch gorcunov/gh-5475-c-load-fails
issue https://github.com/tarantool/tarantool/issues/5475 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Tarantool-patches] [PATCH] func: clean the module cache on first load error
  2020-11-13 12:28 [Tarantool-patches] [PATCH] func: clean the module cache on first load error Cyrill Gorcunov
  2020-11-13 12:29 ` Cyrill Gorcunov
@ 2020-11-18 21:30 ` Vladislav Shpilevoy
  2020-11-25  9:22   ` Alexander V. Tikhonov
  2020-11-26 21:25 ` Vladislav Shpilevoy
  2 siblings, 1 reply; 5+ messages in thread
From: Vladislav Shpilevoy @ 2020-11-18 21:30 UTC (permalink / raw)
  To: Cyrill Gorcunov, tml, Alexander V. Tikhonov

Hi! Thanks for the patch!

LGTM.

Alexander, please, verify it does not fail CI, and tell if I can
push it.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Tarantool-patches] [PATCH] func: clean the module cache on first load error
  2020-11-18 21:30 ` Vladislav Shpilevoy
@ 2020-11-25  9:22   ` Alexander V. Tikhonov
  0 siblings, 0 replies; 5+ messages in thread
From: Alexander V. Tikhonov @ 2020-11-25  9:22 UTC (permalink / raw)
  To: Cyrill Gorcunov, v.shpilevoy; +Cc: tarantool-patches

Hi Cyrill and Vlad, thanks for the patch, as I see no new degradation found in
gitlab-ci testing commit criteria pipeline [1], patch LGTM.

[1] - https://gitlab.com/tarantool/tarantool/-/pipelines/215733148

On Wed, Nov 18, 2020 at 10:30:20PM +0100, Vladislav Shpilevoy wrote:
> Hi! Thanks for the patch!
> 
> LGTM.
> 
> Alexander, please, verify it does not fail CI, and tell if I can
> push it.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Tarantool-patches] [PATCH] func: clean the module cache on first load error
  2020-11-13 12:28 [Tarantool-patches] [PATCH] func: clean the module cache on first load error Cyrill Gorcunov
  2020-11-13 12:29 ` Cyrill Gorcunov
  2020-11-18 21:30 ` Vladislav Shpilevoy
@ 2020-11-26 21:25 ` Vladislav Shpilevoy
  2 siblings, 0 replies; 5+ messages in thread
From: Vladislav Shpilevoy @ 2020-11-26 21:25 UTC (permalink / raw)
  To: Cyrill Gorcunov, tml

Pushed to master, 2.6, 2.5, 1.10.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-11-26 21:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-13 12:28 [Tarantool-patches] [PATCH] func: clean the module cache on first load error Cyrill Gorcunov
2020-11-13 12:29 ` Cyrill Gorcunov
2020-11-18 21:30 ` Vladislav Shpilevoy
2020-11-25  9:22   ` Alexander V. Tikhonov
2020-11-26 21:25 ` Vladislav Shpilevoy

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