From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 7CEE763342; Wed, 3 Feb 2021 01:13:43 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 7CEE763342 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1612304023; bh=cegIxVC04hjfvzzQosRd9ECLTAAcGCXIMkBInUUl9Z0=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=xN8rbtDkh0wc2ez8s1C7Z5WNz5wPg8uYGw99bjyfFc++A3+n46Q23gyppjptMBsPR Vm9+MPxWciA/oxJs7LAC7ENxcEVV3k+N5N4V0WWIplKDMelsXEKWDoJGLIRn+XW948 fq0IPYRVVvCBrenFgtDrWiqUrW4XhuOJfE7ZiItA= Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id BF90A63342 for ; Wed, 3 Feb 2021 01:12:48 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org BF90A63342 Received: by mail-lf1-f46.google.com with SMTP id a12so30394264lfb.1 for ; Tue, 02 Feb 2021 14:12:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LIiybWflDuAZ17jRsIcKtVrAnR5fYGBgeVfw05yIAUU=; b=FKVY1j5xoOE87mmn0eG54nj8V3MC50epMqy505PEShTOs/doMUZixMRq/WoYXSg1lo rwkG29crygSgMi0JNEZMqYSSyH/4Rtlt0vvQiuWMsE5ggL6Spyksjb2rxCZU5y6bJ05r 29EvxbqPC7kBgEQSRoG4kyEGKtqAVBZEYlO+BlLuwnY5Eo+0UIFGWqaLYdsylfkNHHfx bNjdQVjV1mimhelD8dfbhda5mzzbOP1kgkOcBFzsdKdvjCEH+IJ+Bno85LKB7/D0lNOi J63mdHMsBy1X1wdW8KNVGnjXzbqdZ510wJLolH0Y7k8e6dP2UPl1cKJtkPtmxuaUdH3L mU0A== X-Gm-Message-State: AOAM531Sqz8LD+XhIu8PgSz9BCaM6k0uW6vZMYdSAXXOrFiT6LnoIpza y1i2YMTc6cusnEWrclDzC5PHI0oKQ6E= X-Google-Smtp-Source: ABdhPJxw/Qphuhd1JyKUyjrE7KJKZaslNNN/Zh9qrBawnas7VJLMafqzhOoM+PjjmrDBSMe1G4teoA== X-Received: by 2002:a19:7f13:: with SMTP id a19mr42218lfd.396.1612303967735; Tue, 02 Feb 2021 14:12:47 -0800 (PST) Received: from grain.localdomain ([5.18.103.226]) by smtp.gmail.com with ESMTPSA id d10sm8879ljl.116.2021.02.02.14.12.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Feb 2021 14:12:46 -0800 (PST) Received: by grain.localdomain (Postfix, from userid 1000) id 89E3056026C; Wed, 3 Feb 2021 01:12:08 +0300 (MSK) To: tml Date: Wed, 3 Feb 2021 01:11:58 +0300 Message-Id: <20210202221207.383101-4-gorcunov@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210202221207.383101-1-gorcunov@gmail.com> References: <20210202221207.383101-1-gorcunov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v14 03/12] module_cache: direct update a cache value on reload X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Cyrill Gorcunov via Tarantool-patches Reply-To: Cyrill Gorcunov Cc: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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 --- 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 a66b84efb..b3bfb4963 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