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.89) (envelope-from ) id 1ilf0k-0005SA-El for pgsql-hackers@arkaria.postgresql.org; Sun, 29 Dec 2019 20:18:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ilf0i-00029I-2V for pgsql-hackers@arkaria.postgresql.org; Sun, 29 Dec 2019 20:18:00 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ilf0h-000299-Hm for pgsql-hackers@lists.postgresql.org; Sun, 29 Dec 2019 20:17:59 +0000 Received: from mail-yb1-xb42.google.com ([2607:f8b0:4864:20::b42]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ilf0a-000202-Di for pgsql-hackers@postgresql.org; Sun, 29 Dec 2019 20:17:58 +0000 Received: by mail-yb1-xb42.google.com with SMTP id b145so13382340yba.8 for ; Sun, 29 Dec 2019 12:17:51 -0800 (PST) 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=231383gY1lpMTHera7sTfBOTrqfWedp3YJgLDEEIcY4=; b=sxrAIepGcBDYoCRKk40TFrW6GpDLrjov0nCTIRgNadWFAjyTcRkmrps+v+ee6gKKLF Pr7V+ycu31SWDkzWZihfXG8so6Raz+mdLhbrm8rpSESS3K7Mwr9CCazbzRV8ZY29uo2d p+oluzRu8xGnqcUsxiHlT2r+kczFZNy6zi9CM7cKQwe070vb/vBwAWVXeMudTsOGc+rQ LbFf0YQnaKynPaZyvNjYo7Ycoh7F/AnUlu/HjTOytpZZiuZXgTEpDHAiyGC/Ci7ed+hr 0sQPoeV4kywmcjgD91Exw9FML6e3BPvrTKF9NAdy/vH1NhberAawzbx3C8iGOxRPaUWJ Uunw== 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=231383gY1lpMTHera7sTfBOTrqfWedp3YJgLDEEIcY4=; b=XmhS3IEudi5TBXx/yG+RRpFmfRTAuHE0y9+iT49JGGylg008QEZvfPQAgpCD65vNI4 vjgUhvi47xCX1hWT3xCPQhMmD4Ry5tiAxpMXl9rVu4YynA5BPSBjkC4KV7zbgIC/pfPc l7OR+XDIMY9dSsklaWzh3XnGobYY42HTaVKwoX26cCptZVIuizgJpFVPmybSVt4q+5ic 3ncgDscI0ss27v+nodPaSF5ZAuY0emcKCrV5CYsyShsMb3qsNXOHdyCYYP6SpSGahcxJ IIAGuBwhDEnyAS71U42F6fFQxjkYhLPTD30DL08V86K3flqbkYF0kAOVYXvWL40y1ehn DYOA== X-Gm-Message-State: APjAAAX0ftVWe1YN4+vHBUsYrAXtg2K/ZEOyRacyokgdYoiG1/JZdfNM Jfd5DMqqztSvjPNiDjXFjTz2dw== X-Google-Smtp-Source: APXvYqxf9XTAu9fY9UuhEmQzIuFL8RCwLu+qDcdak6FOFIKBsDb8vpL8TTUpfX1eyqm3A1aU3hqDuw== X-Received: by 2002:a25:44c5:: with SMTP id r188mr44231252yba.97.1577650670744; Sun, 29 Dec 2019 12:17:50 -0800 (PST) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id h184sm16670202ywa.70.2019.12.29.12.17.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Dec 2019 12:17:49 -0800 (PST) Received: by pryzbyj (Postfix, from userid 1000) id 08E2C800964; Sun, 29 Dec 2019 14:17:47 -0600 (CST) Date: Sun, 29 Dec 2019 14:17:47 -0600 From: Justin Pryzby To: Robert Haas Cc: Michael Paquier , Alvaro Herrera , Andres Freund , pgsql-hackers@postgresql.org Subject: Re: error context for vacuum to include block number (atomic progress update) Message-ID: <20191229201747.GL12890@telsasoft.com> References: <20191213030831.GT2082@telsasoft.com> <20191213132850.GA103520@paquier.xyz> <20191213224735.GY2082@telsasoft.com> <20191215130708.GA19063@paquier.xyz> <20191215162712.GZ2082@telsasoft.com> <20191216024956.GC2344@paquier.xyz> <20191224012428.GK30414@telsasoft.com> <20191224041909.GA323806@paquier.xyz> <20191226155704.GA12890@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sat, Dec 28, 2019 at 07:21:31PM -0500, Robert Haas wrote: > On Thu, Dec 26, 2019 at 10:57 AM Justin Pryzby wrote: > > I agree that's better. > > I don't see any reason why the progress params need to be updated atomically. > > So rebasified against your patch. > > I am not sure whether it's important enough to make a stink about, but > it bothers me a bit that this is being dismissed as unimportant. The > problem is that, if the updates are not atomic, then somebody might > see the data after one has been updated and the other has not yet been > updated. The result is that when the phase is > PROGRESS_VACUUM_PHASE_VACUUM_INDEX, someone reading the information > can't tell whether the number of index scans reported is the number > *previously* performed or the number performed including the one that > just finished. The race to see the latter state is narrow, so it > probably wouldn't come up often, but it does seem like it would be > confusing if it did happen. What used to be atomic was this: - hvp_val[0] = PROGRESS_VACUUM_PHASE_VACUUM_HEAP; - hvp_val[1] = vacrelstats->num_index_scans + 1; => switch from PROGRESS_VACUUM_PHASE_VACUUM INDEX to HEAP and increment index_vacuum_count, which is documented as the "Number of completed index vacuum cycles." Now, it 1) increments the number of completed scans; and, 2) then progresses phase to HEAP, so there's a window where the number of completed scans is incremented, and it still says VACUUM_INDEX. Previously, if it said VACUUM_INDEX, one could assume that index_vacuum_count would increase at least once more, and that's no longer true. If someone sees VACUUM_INDEX and some NUM_INDEX_VACUUMS, and then later sees VACUUM_HEAP or other later stage, with same (maybe final) value of NUM_INDEX_VACUUMS, that's different than previous behavior. It seems to me that a someone or their tool monitoring pg_stat shouldn't be confused by this change, since: 1) there's no promise about how high NUM_INDEX_VACUUMS will or won't go; and, 2) index_vacuum_count didn't do anything strange like decreasing, or increased before the scans were done; and, 3) the vacuum can finish at any time, and the monitoring process presumably knows that when the PID is gone, it's finished, even if it missed intermediate updates; The behavior is different from before, but I think that's ok: the number of scans is accurate, and the PHASE is accurate, even though it'll change a moment later. I see there's similar case here: | /* report all blocks vacuumed; and that we're cleaning up */ | pgstat_progress_update_param(PROGRESS_VACUUM_HEAP_BLKS_VACUUMED, blkno); | pgstat_progress_update_param(PROGRESS_VACUUM_PHASE, | PROGRESS_VACUUM_PHASE_INDEX_CLEANUP); heap_blks_scanned is documented as "Number of heap blocks SCANNED", and it increments exactly to heap_blks_total. Would someone be confused if heap_blks_scanned==heap_blks_total AND phase=='scanning heap' ? I think they'd just expect PHASE to be updated a moment later. (And if it wasn't, I agree they should then be legitimately confused or concerned). Actually, the doc says: |If heap_blks_scanned is less than heap_blks_total, the system will return to |scanning the heap after this phase is completed; otherwise, it will begin |cleaning up indexes AFTER THIS PHASE IS COMPLETED. I read that to mean that it's okay if heap_blks_scanned==heap_blks_total when scanning/vacuuming heap. Justin