Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nME3o-0005tY-Hr for pgsql-hackers@arkaria.postgresql.org; Mon, 21 Feb 2022 19:09:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nME3n-0002ba-Gz for pgsql-hackers@arkaria.postgresql.org; Mon, 21 Feb 2022 19:09:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nME3n-0002bR-5U for pgsql-hackers@lists.postgresql.org; Mon, 21 Feb 2022 19:09:23 +0000 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nME3f-0001y2-Gs for pgsql-hackers@postgresql.org; Mon, 21 Feb 2022 19:09:22 +0000 Received: by mail-pl1-x632.google.com with SMTP id i10so13675223plr.2 for ; Mon, 21 Feb 2022 11:09:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=D0jghIGKc1hQoRY+ZM8oTProi+M0LhX6gfKesOpcpPs=; b=NtT/6+yz0Nf9ZnOtXdUoyBvaYQsTDrrIJFVIWAFpj6F2ArstiIrZW04mK1IBHLQ/Hy 4Pv/qVlirvuKJ1HtIX2sKw2isT6k3LiV3QRbLVvaPI6Am2XRuUMBwI51GamaC+4ox68Y 7eU33qpe7M+dxylN8clr5/RWnwvgbHPxDLR11o3LAnTr5xwmE4Ye8ET25f+lRGQwRkkl 30CA5gmh4WJH+izpA1COjN6sGSTLM4MCN7c7yaqZcJ52VMnYCbX7rit0Vu966z8U9BfQ XwPcl78haBdtl19D2RiKoPBfnBItpLlMA+MWT42aOl6E1u16r42dVw0Mg7iRPy5NQ9PW nZxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=D0jghIGKc1hQoRY+ZM8oTProi+M0LhX6gfKesOpcpPs=; b=St9ZknlvXDPnLC+59osLWNYWk45faN21Ge5aNmTEgwLbhwUz/e3zEMABT1wPEdqNlg mIA/heyyMrKsVDd/T+5Cihgt0GioXNqnGyTwOpKRaQRI4I5Kl9GrG+jcyC20L2pItS0x tV3NU930vHfrX4Kx+FiUYRvXbOWnq3mAnntRlETGH03J0QehqxdBlzzZ3yGogS0+c87z vjwbnm6Mt6O2AsYFLat7AVuAJFsA6VWCEFigJjEk5vScFKUq1JQHaIT3EYyBoWB4YwM2 OmrqVtfQUv4giIrsCYWLcdGoWSvygo01pgj+PeS81zpDXUqp6tA7SIYXXrreHC8weWZ7 xXUQ== X-Gm-Message-State: AOAM531Ha6HxOLRPUSBkzRJfK/jlU6AHKG9FQIRG/VN8xh0UMF8fAlDQ RK3zXqcUUgtYDJfqlGNuWz0= X-Google-Smtp-Source: ABdhPJy8y9QMGwKRdr37N0yIbxGUilFwD0MJzXim8JRkgAYSnDC+guNH0fMes9R7Uip5AONRz9AoLw== X-Received: by 2002:a17:90a:ac09:b0:1bc:3e9d:158 with SMTP id o9-20020a17090aac0900b001bc3e9d0158mr348056pjq.235.1645470552324; Mon, 21 Feb 2022 11:09:12 -0800 (PST) Received: from nathanxps13 ([50.54.155.70]) by smtp.gmail.com with ESMTPSA id ha2sm119363pjb.6.2022.02.21.11.09.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 11:09:11 -0800 (PST) Date: Mon, 21 Feb 2022 11:09:10 -0800 From: Nathan Bossart To: "Imseih (AWS), Sami" Cc: "Bossart, Nathan" , Masahiko Sawada , Justin Pryzby , Peter Geoghegan , "pgsql-hackers@postgresql.org" Subject: Re: Add index scan progress to pg_stat_progress_vacuum Message-ID: <20220221190910.GA3740885@nathanxps13> References: <6D2C60C2-C09E-4117-A6B8-DCA7A0F5B182@amazon.com> <22C9CB0C-9576-47AF-8A6E-F9573F73CD4E@amazon.com> <6753CC4A-D1D8-477D-9B82-CFE12169DFF5@amazon.com> <7A4B3BA8-0768-4463-9B25-25DBECF56B25@amazon.com> <96387867-CBAF-4CCF-861E-2F4ACBCBBD68@amazon.com> <441BA1FF-23AA-4CEE-9976-7FB693C30D00@amazon.com> <1E7CB510-FB91-4DDB-93E1-A19C05F299F3@amazon.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1E7CB510-FB91-4DDB-93E1-A19C05F299F3@amazon.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Feb 21, 2022 at 07:03:39PM +0000, Imseih (AWS), Sami wrote: > Sending again with patch files renamed to ensure correct apply order. I haven't had a chance to test this too much, but I did look through the patch set and have a couple of small comments. + + + indexes_total bigint + + + The number of indexes to be processed in the + vacuuming indexes or cleaning up indexes phase + of the vacuum. + + + + + + indexes_processed bigint + + + The number of indexes processed in the + vacuuming indexes or cleaning up indexes phase. + At the start of an index vacuum cycle, this value is set to 0. + + Will these be set to 0 for failsafe vacuums and vacuums with INDEX_CLEANUP turned off? +typedef struct VacWorkerProgressInfo +{ + int num_vacuums; /* number of active VACUUMS with parallel workers */ + int max_vacuums; /* max number of VACUUMS with parallel workers */ + slock_t mutex; + VacOneWorkerProgressInfo vacuums[FLEXIBLE_ARRAY_MEMBER]; +} VacWorkerProgressInfo; max_vacuums appears to just be a local copy of MaxBackends. Does this information really need to be stored here? Also, is there a strong reason for using a spinlock instead of an LWLock? +void +vacuum_worker_end(int leader_pid) +{ + SpinLockAcquire(&vacworkerprogress->mutex); + for (int i = 0; i < vacworkerprogress->num_vacuums; i++) + { + VacOneWorkerProgressInfo *vac = &vacworkerprogress->vacuums[i]; + + if (vac->leader_pid == leader_pid) + { + *vac = vacworkerprogress->vacuums[vacworkerprogress->num_vacuums - 1]; + vacworkerprogress->num_vacuums--; + SpinLockRelease(&vacworkerprogress->mutex); + break; + } + } + SpinLockRelease(&vacworkerprogress->mutex); +} I see this loop pattern in a couple of places, and it makes me wonder if this information would fit more naturally in a hash table. + if (callback) + callback(values, 3); Why does this need to be set up as a callback function? Could we just call the function if cmdtype == PROGRESS_COMMAND_VACUUM? ISTM that is pretty much all this is doing. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com