From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 0880E441841 for ; Thu, 26 Mar 2020 19:54:15 +0300 (MSK) Received: by mail-lj1-f196.google.com with SMTP id i20so7153290ljn.6 for ; Thu, 26 Mar 2020 09:54:15 -0700 (PDT) Date: Thu, 26 Mar 2020 19:54:13 +0300 From: Konstantin Osipov Message-ID: <20200326165413.GD21134@atlas> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Subject: Re: [Tarantool-patches] [PATCH v2 06/10] box: introduce stacked diagnostic area List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Nikita Pettik Cc: tarantool-patches@dev.tarantool.org, v.shpilevoy@tarantool.org * Nikita Pettik [20/03/25 09:32]: > + /* > + * Make sure that adding error won't result in cycles. > + * Don't bother with sophisticated cycle-detection > + * algorithms, simple iteration is OK since as a rule > + * list contains a dozen errors at maximum. > + */ > + struct error *tmp = prev; > + while (tmp != NULL) { > + if (tmp == e) > + return -1; > + tmp = tmp->cause; > + } If you have to do it, better use rlist, rlist_del(e) rlist_add(e), this will make sure there are no cycles and the cost is constant. > + if (prev != NULL) { > + error_unlink_effect(prev); > + prev->effect = e; > + error_ref(prev); > + } cause and effect can be just wrappers around rlist_prev/next, if you have to. But error stack is not always cause and effect: imagine an SQL update which runs a bunch of triggers which all set add some errors to the diag, which one of these triggers errors is the cause of update error?. -- Konstantin Osipov, Moscow, Russia