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 233B585DED; Mon, 18 Jan 2021 23:38:06 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 233B585DED DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1611002286; bh=hO0a8y/xIBnoACfKiDOfvzOF0X/6sXjZ+Zgpdehw104=; 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=Q++2o8ZvlSI1wfvPxIpVhVulIuTtfyLi6sbetXJyIuZkRBER6MLdRfRMiuJ60Q4sb gC/TqUaVgae/bYtFvuu8Bx2cV4MeAEZeB/iyqz0cHaspKZiXoXoXaEjwl1YEhjf0Xm ZDMMzOVV3AmDsdviUCSwH6pjoEhL5JWGWsLY3vYU= Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (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 D5EEC645E6 for ; Mon, 18 Jan 2021 23:36:49 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D5EEC645E6 Received: by mail-lf1-f41.google.com with SMTP id o17so25944387lfg.4 for ; Mon, 18 Jan 2021 12:36:49 -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=hJi7UGR6aw9ZV7PHeLlKTTEa7+O/N9TxS0x+oKHAyUU=; b=FAWt53tM/3Hajnn4WSVT45AtFlpkssJsdqIahXWaEyYfVy5f7Uj6CaoK92+uZekvON Ryj9ezJMrRYIWSARf1xDjL/UBnaB/NH5Wyvu7TmphUA5pINphdL+bljBeiy1KQmStjCH 1zHwIcIhiAhH3Fq9brzcLkHWKsnaUZY0Hz90k3BlvKqswm1fwo75j9MP2weVp2rd8vpo Pc4FX7zxMwARPF+LcuMq9CKCytTXk1pWewi/BPwNOjRfNoPTiKLEQzPraW80wR+vJkxs lGoy9SjIENO70lZ925F+SenQvwQuw2xiRErACrD4b4rZrgh/IzTpLY8zNIEVyL1UvJQm alrA== X-Gm-Message-State: AOAM530me7I+rarGS0mza7CJiGWRW49vD3C6RseGgq+u90PFDUR0vumQ 4vNBgUUXLipBtprxQqUXWSmUQ2NlDxc= X-Google-Smtp-Source: ABdhPJy7bPX2W6qT75MxlLBPGHqyx+q9RFnRueSpOYAtfshgamA1BYT+cD4HfGM8SRMEl3dLjOS3hA== X-Received: by 2002:a19:4cf:: with SMTP id 198mr371740lfe.136.1611002208744; Mon, 18 Jan 2021 12:36:48 -0800 (PST) Received: from grain.localdomain ([5.18.91.94]) by smtp.gmail.com with ESMTPSA id e11sm2017426lfn.28.2021.01.18.12.36.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 12:36:47 -0800 (PST) Received: by grain.localdomain (Postfix, from userid 1000) id 66537560149; Mon, 18 Jan 2021 23:35:59 +0300 (MSK) To: tml Date: Mon, 18 Jan 2021 23:35:52 +0300 Message-Id: <20210118203556.281700-5-gorcunov@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210118203556.281700-1-gorcunov@gmail.com> References: <20210118203556.281700-1-gorcunov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v12 4/8] 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 | 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