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 615EA718B1; Tue, 19 Jan 2021 15:46:54 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 615EA718B1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1611060414; bh=FgCfah0SDT5Fc5arLEBF7/LVLV9EqqP4TmpXnisnTd4=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=VduCbZiVF+4bIC8Jnmw1WcJk/E5qmjId5Q/evkl2rBAE7NETc4y85LZoSobSy6Xom T4fVvPd2+OMp+ej9y7UI+gQzCsiac3AJN1A3IBsdzZd30D4R5vVPZzZEbI5rgDb7te WAtm/vbOi++h5muAIdh6RA85XQ0ujdfYJ47+AYRo= Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) (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 D9630718B1 for ; Tue, 19 Jan 2021 15:46:52 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D9630718B1 Received: by mail-lf1-f50.google.com with SMTP id b26so28888433lff.9 for ; Tue, 19 Jan 2021 04:46:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=cy6zYgCMko8CzgYZWVSh7HQooi65IP0j8X99lZSVqD8=; b=dy0pPu8AO/QYYrpUkB8sPHaD5cuggyX+T65LUn4GIFIscLxm2hNR5ChhohKLNmTt5k xCrPoeA3uVqDypJ8BNyO2cjbRA8W2StmS36TGBAxZdObCRlv2jieIXdlQ0FPvqXlycmR KBDpiYRVfHeKt4sxi+9vN60a2Pai/1Sm412xrKF6hJmLVo/69VoIcWvnbY50W/irq3bA l8S+rYPnO/sK1QVIjznNg0NUfnAngcjzySYvTP3/k1haVfSfooZPYvtWXRtA3gRYcCtC ivVLroBEuesmN/JndyRzDJoKaaHTdtUNcWxvR6c1xFn90Mvua3Vpb5x1z/PBtlTWH/zx zpjQ== X-Gm-Message-State: AOAM532HI49uI9HXYLqVAdb/NUyhi/ichlIISctcSN7403cAqtW1PLRS 5/N5s04cOfkhwdN7uqHA7Zk/jpyr1M4= X-Google-Smtp-Source: ABdhPJzEhWRElCpVl6uSWBTCheU02Whk/gRUD93tIIgqgwNZLop2YH86uE9R5S8v6UaX/teeSyOtvg== X-Received: by 2002:a19:23cf:: with SMTP id j198mr1854500lfj.509.1611060411639; Tue, 19 Jan 2021 04:46:51 -0800 (PST) Received: from grain.localdomain ([5.18.91.94]) by smtp.gmail.com with ESMTPSA id y23sm35010lfy.158.2021.01.19.04.46.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Jan 2021 04:46:50 -0800 (PST) Received: by grain.localdomain (Postfix, from userid 1000) id 1446656010B; Tue, 19 Jan 2021 15:46:49 +0300 (MSK) Date: Tue, 19 Jan 2021 15:46:49 +0300 To: tml Cc: Vladislav Shpilevoy Message-ID: <20210119124649.GA2185@grain> References: <20210118203556.281700-1-gorcunov@gmail.com> <20210118203556.281700-5-gorcunov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210118203556.281700-5-gorcunov@gmail.com> User-Agent: Mutt/1.14.6 (2020-07-11) Subject: Re: [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 Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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 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 --- 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