Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1jHU4G-00075s-DS for pgsql-hackers@arkaria.postgresql.org; Thu, 26 Mar 2020 15:05:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jHU4D-0000yb-MA for pgsql-hackers@arkaria.postgresql.org; Thu, 26 Mar 2020 15:05:09 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jHU4D-0000yU-80 for pgsql-hackers@lists.postgresql.org; Thu, 26 Mar 2020 15:05:09 +0000 Received: from mail-qk1-x744.google.com ([2607:f8b0:4864:20::744]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jHU48-0008AX-Ov for pgsql-hackers@postgresql.org; Thu, 26 Mar 2020 15:05:08 +0000 Received: by mail-qk1-x744.google.com with SMTP id q188so6739479qke.8 for ; Thu, 26 Mar 2020 08:05:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=jfA4m594oD++ryIFnx1ZpN61RyvRehH1KtUsX/WfNLM=; b=to6UG8+dEDfNZU2QLOhX9Q1vPQXDAkujIc1RE+tdBWWGkyGVbWaHUUmsu3h9rt+jX1 DDxNenlTugCA1Wdeqq4qDqVc1DoCE9DSoWIOy5ekaYHF/LKT35D9zC1F/pGJDMHH6H9U sHFDtm69y8BDmklfcbV9Hha/uUKQya3e7rR8ioJjErBVYp9rUq9lZXutrSKraE4Z3uXG S5rL3xG5rYSulsTmyl7tU5gS9m6M7lDXlsxEXbPqb8+Pe3Yd4pC18Hl1GMgyLusMvYeb ezu+zUfLQZQiWwhfNghAYhuuq3ls1xaUcAtb4YBJJIeCYI+BBLKrM3ibDY2vH3GE120G bUoA== 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=jfA4m594oD++ryIFnx1ZpN61RyvRehH1KtUsX/WfNLM=; b=hoIViX0kY2MJ6JwnUjFEGu4Quxnq71D42kYszzoElwYy4dhqy8+iKYOklYRKAiHvq+ s4CLjro/KK03fAhPIvxqB6hqCW/jBYUFtWVRlb/N+ik2GkPq0L64nJ7EHyse5DB7nxhl EhHhpC7qZrbG1We1ePi8NVVg+69YP49TaUOD9qkG4Ft/wWyRBwRKqPVUD7ZFrmmgHmoP ykT/vY+yXCd3UtklRx7awYgLSmxyUpXsZOAWP49W/bnwCy+lkUkEpDznWfjIhdeEDl3G jwYv+VMfjAV8RRTH8HfA5WpXXOpa7A3rDoIZZvUcWsnUWefydtRWdn/Yt0OTOdFkZ/vn BdDg== X-Gm-Message-State: ANhLgQ1VQAx9V1CR21H1dCy+XXiVqqpMttq89s96eM/tSy0NS+UKFu8e iDcsxAJ8krdqrP0pxB3ZKritNA== X-Google-Smtp-Source: ADFU+vsSsYuH3okI62NB1OymiqK95zYvsD5yqHvJLMhy0CmgomQ8aYDmwdF32xmBWHIHIL0ys0er6w== X-Received: by 2002:a37:8cc1:: with SMTP id o184mr8190141qkd.187.1585235102536; Thu, 26 Mar 2020 08:05:02 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id 18sm1422212qkk.84.2020.03.26.08.04.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Mar 2020 08:04:59 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id 3DDE5800EBC; Thu, 26 Mar 2020 10:04:57 -0500 (CDT) Date: Thu, 26 Mar 2020 10:04:57 -0500 From: Justin Pryzby To: Masahiko Sawada Cc: Amit Kapila , Alvaro Herrera , Andres Freund , Michael Paquier , pgsql-hackers@postgresql.org Subject: Re: error context for vacuum to include block number Message-ID: <20200326150457.GB17431@telsasoft.com> References: <20200325101229.GR21443@telsasoft.com> <20200325124155.GU21443@telsasoft.com> <20200326044115.GB28385@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Mar 26, 2020 at 08:56:54PM +0900, Masahiko Sawada wrote: > 1. > @@ -1844,9 +1914,15 @@ lazy_vacuum_page(Relation onerel, BlockNumber > blkno, Buffer buffer, > int uncnt = 0; > TransactionId visibility_cutoff_xid; > bool all_frozen; > + LVRelStats olderrcbarg; > > pgstat_progress_update_param(PROGRESS_VACUUM_HEAP_BLKS_VACUUMED, blkno); > > + /* Update error traceback information */ > + olderrcbarg = *vacrelstats; > + update_vacuum_error_cbarg(vacrelstats, VACUUM_ERRCB_PHASE_VACUUM_HEAP, > + blkno, NULL, false); > > Since we update vacrelstats->blkno during in the loop in > lazy_vacuum_heap() we unnecessarily update blkno twice to the same > value. Also I think we don't need to revert back the callback > arguments in lazy_vacuum_page(). Perhaps we can either remove the > change of lazy_vacuum_page() or move the code updating > vacrelstats->blkno to the beginning of lazy_vacuum_page(). I prefer > the latter. We want the error callback to be in place during lazy_scan_heap, since it calls ReadBufferExtended(). We can't remove the change in lazy_vacuum_page, since it's also called from lazy_scan_heap, if there are no indexes. We want lazy_vacuum_page to "revert back" since we go from "scanning heap" to "vacuuming heap". lazy_vacuum_page was the motivation for saving and restoring the called arguments, otherwise lazy_scan_heap() would have to clean up after the function it called, which was unclean. Now, every function cleans up after itself. Does that address your comment ? > +static void > +update_vacuum_error_cbarg(LVRelStats *errcbarg, int phase, BlockNumber blkno, > + char *indname, bool free_oldindname) > > I'm not sure why "free_oldindname" is necessary. Since we initialize > vacrelstats->indname with NULL and revert the callback arguments at > the end of functions that needs update them, vacrelstats->indname is > NULL at the beginning of lazy_vacuum_index() and lazy_cleanup_index(). > And we make a copy of index name in update_vacuum_error_cbarg(). So I > think we can pfree the old index name if errcbarg->indname is not NULL. We want to avoid doing this: olderrcbarg = *vacrelstats // saves a pointer update_vacuum_error_cbarg(... NULL); // frees the pointer and sets indname to NULL update_vacuum_error_cbarg(... olderrcbarg.oldindnam) // puts back the pointer, which has been freed // hit an error, and the callback accesses the pfreed pointer I think that's only an issue for lazy_vacuum_index(). And I think you're right: we only save state when the calling function has a indname=NULL, so we never "put back" a non-NULL indname. We go from having a indname=NULL at lazy_scan_heap to not not-NULL at lazy_vacuum_index, and never the other way around. So once we've "reverted back", 1) the pointer is null; and, 2) the callback function doesn't access it for the previous/reverted phase anyway. Hm, I was just wondering what happens if an error happens *during* update_vacuum_error_cbarg(). It seems like if we set errcbarg->phase=VACUUM_INDEX before setting errcbarg->indname=indname, then an error would cause a crash. And if we pfree and set indname before phase, it'd be a problem when going from an index phase to non-index phase. So maybe we have to set errcbarg->phase=VACUUM_ERRCB_PHASE_UNKNOWN while in the function, and errcbarg->phase=phase last. -- Justin