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 27F5E686CC; Fri, 5 Feb 2021 21:56:12 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 27F5E686CC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1612551372; bh=XE8kdB1rI7PNoWEv2vxPmbo1e4HJkNLajyePqV+uXFs=; 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=iff2PbVQpvM/aZIFD4w9aRLNS62tpQlXqUtdWeh3riNwXytGNi6ruRj3VHlrc0TI6 1xSetq2Ar6MPMuC6tPU1JHSi7YJPIsED2pSTHcVziYnz2cYC64/Aw5oMNNXdybXXOJ 5Gvik8LmPLVDF6Ny96oQOyR2Hj2mE1YYa8Iuh8gA= Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) (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 EC3C2686CC for ; Fri, 5 Feb 2021 21:55:14 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org EC3C2686CC Received: by mail-lj1-f179.google.com with SMTP id a25so9051829ljn.0 for ; Fri, 05 Feb 2021 10:55:14 -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=8+zUDsukgrtTbo67cMNpPNzlbhrfh2OROwlglllcxXg=; b=oeLHFffsus4R6VbCoEbBcIXHLPLDQq+koAxAyyCp6bUPCB34cLm5AWRljZjTXtCzFi ZTFqYYtxH+k42iNEoczztQSDdzFFt9InEFWLJGfq3m6d5adQu6i3/Rw/2BIobUArcjD8 1Ja8E1zj+2PDhHYjNf8OxwEa730HX7JmWs+o8BzueOeekvoFbnt8vDplTekeq9OWEWG4 ezdh3ccH/fDT3NeRcQBF2dhL5RXRwZqflCtjlGw8RmkmMtIV3rLvG65fHYT+XwwcJSWA tNnFS/nAV61ZXoBTOcaaB+lvJbndsEUt/FNzyScpYGIKo7fs6r4KzdfzrardB5iMCc14 BBdg== X-Gm-Message-State: AOAM531kZiOqbpGmPhxkDObzxFIwUhSJzE8/22BnvswIjPc6SlnD2opP o3DRBqr8myiFDbgrn97c9C8= X-Google-Smtp-Source: ABdhPJyCOWVuqJ+OfJ4HkRw614jkjRE+6kE/1Qf6ReqiJ02pc8aIoNbCf55BGXFMcWMgW5wb1WTG0A== X-Received: by 2002:a2e:9055:: with SMTP id n21mr3537517ljg.377.1612551314597; Fri, 05 Feb 2021 10:55:14 -0800 (PST) Received: from grain.localdomain ([5.18.103.226]) by smtp.gmail.com with ESMTPSA id y3sm1070677lfg.208.2021.02.05.10.55.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Feb 2021 10:55:13 -0800 (PST) Received: by grain.localdomain (Postfix, from userid 1000) id 7FF7A560272; Fri, 5 Feb 2021 21:54:37 +0300 (MSK) To: tml Date: Fri, 5 Feb 2021 21:54:28 +0300 Message-Id: <20210205185436.638894-4-gorcunov@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210205185436.638894-1-gorcunov@gmail.com> References: <20210205185436.638894-1-gorcunov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v15 03/11] 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: Mons Anderson , 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 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