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 1p2SNm-0004el-5V for pgsql-hackers@arkaria.postgresql.org; Tue, 06 Dec 2022 07:28:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p2SNk-0004Nj-Tw for pgsql-hackers@arkaria.postgresql.org; Tue, 06 Dec 2022 07:28:48 +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 1p2SNk-0004NZ-KP for pgsql-hackers@lists.postgresql.org; Tue, 06 Dec 2022 07:28:48 +0000 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1p2SNe-0005gz-31 for pgsql-hackers@postgresql.org; Tue, 06 Dec 2022 07:28:48 +0000 Received: by mail-wr1-x433.google.com with SMTP id d1so22154628wrs.12 for ; Mon, 05 Dec 2022 23:28:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=YtzZX1zU0ZtjTr5MuJJQ6iz9gl97XVhiCJuzJwf543U=; b=H1tAUuxdIQk0vRxuiHNHcUtHv5hhrZAODwpVP6TRPZoAcIHDs5k/ZSW75S2OlkGPR7 MRr6IQ1+Qdg7iSCboxidSl47VnllxBYgLzk3d+7mDgCk6q34NhhIqvowNsJOp0diFALU 48IUogTZjDC2hxPaFjNb3bE7F2umGHBR6nzn2yHRgftj9ByJHy3y2yS2AKKYlORfjLNN fgZuL49IVPBwbaG0bY9RJa9rRpNdPf6LxhP+rv5ZSGOaTc3EeNo9VpoYPOnhPIVpzUpz 31b2ghkLcyWW/FLq7PFejpVf+tqkQN+afuXR0j0hPJ+Tb2BkBRW504xRcn/9j8tUA8RB BStQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=YtzZX1zU0ZtjTr5MuJJQ6iz9gl97XVhiCJuzJwf543U=; b=YpzcOyu3c/Ld1UTGGHMPyVbR+pajCD0mmNk6q/SNzCDuqXwDEmA63UGiWeYjSTjHmn peHdp2BOLnaSs6TdVGuiowg6ueraW8Spp9uEDAEMZJ3ETYC9pvZKhamv35S69RHWxS2Y n5/q2fqI/uHpTHvbxfZ8NZXcdBaM4PgZwbXqeI2dn1VcGloIrHeZI/16q4DkFYeSS1jY FgAIDhbYkvZWJQtU8/dfGY3sVjrU5xQtuBkbY2LAbKECZNru6tHL9q37d5HpruHxlTUF FmdT80TPQCQNR+KdfeJTfnA64ZQQDWjYyw/tbQvII85a9gYvk3iOVVCNFpe6iXuCC/2m bRwg== X-Gm-Message-State: ANoB5pmC5BiZjCGtVLElLPDvdEfw8DV84hzsimBEi2e9VhOML0AM0d2/ I0ro21NjoVviDTgftG/u2dBRKKXveYwocpzRMfE= X-Google-Smtp-Source: AA0mqf6UCWH37YuZaQF51fw07u5hU/8LWI98P+BZseEKRM9ag0m2dY4aOU4AEcqY4zyMLiduqBeb/dZwRysfg4nLeL4= X-Received: by 2002:a5d:4344:0:b0:22e:3430:475d with SMTP id u4-20020a5d4344000000b0022e3430475dmr52995390wrr.65.1670311720332; Mon, 05 Dec 2022 23:28:40 -0800 (PST) MIME-Version: 1.0 References: <20221128183129.ip3g5vrcbjrngpp2@awork3.anarazel.de> <20221128234039.GA1119654@nathanxps13> <20221130035653.GA1594993@nathanxps13> <20221130051833.GB1677223@nathanxps13> <20221201214026.GA1799688@nathanxps13> <20221202191507.GA2277157@nathanxps13> In-Reply-To: <20221202191507.GA2277157@nathanxps13> From: Bharath Rupireddy Date: Tue, 6 Dec 2022 12:58:28 +0530 Message-ID: Subject: Re: O(n) tasks cause lengthy startups and checkpoints To: Nathan Bossart Cc: Simon Riggs , Robert Haas , Andres Freund , "Bossart, Nathan" , Maxim Orlov , Amul Sul , Bruce Momjian , "pgsql-hackers@postgresql.org" Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sat, Dec 3, 2022 at 12:45 AM Nathan Bossart wrote: > > On Fri, Dec 02, 2022 at 12:11:35PM +0530, Bharath Rupireddy wrote: > > On Fri, Dec 2, 2022 at 3:10 AM Nathan Bossart wrote: > >> The test appears to reliably create snapshot and mapping files, so if the > >> directories are empty at some point after the checkpoint at the end, we can > >> be reasonably certain the custodian took action. I didn't add explicit > >> checks that there are files in the directories before the checkpoint > >> because a concurrent checkpoint could make such checks unreliable. > > > > I think you're right. I added sqls to see if the snapshot and mapping > > files count > 0, see [1] and the cirrus-ci members are happy too - > > https://github.com/BRupireddy/postgres/tree/custodian_review_2. I > > think we can consider adding these count > 0 checks to tests. > > My worry about adding "count > 0" checks is that a concurrent checkpoint > could make them unreliable. In other words, those checks might ordinarily > work, but if an automatic checkpoint causes the files be cleaned up just > beforehand, they will fail. Hm. It would have been better with a TAP test module for testing the custodian code reliably. Anyway, that mustn't stop the patch getting in. If required, we can park the TAP test module for later - IMO. Others may have different thoughts here. > > Having said above, I'm okay to process ShutdownRequestPending as early > > as possible, however, should we also add CHECK_FOR_INTERRUPTS() > > alongside ShutdownRequestPending? > > I'm not seeing a need for CHECK_FOR_INTERRUPTS. Do you see one? Since the custodian has SignalHandlerForShutdownRequest as SIGINT and SIGTERM handlers, unlike StatementCancelHandler and die respectively, no need of CFI I guess. And also none of the CFI signal handler flags applies to the custodian. > > While thinking about this, one thing that really struck me is what > > happens if we let the custodian exit, say after processing > > ShutdownRequestPending immediately or after a restart, leaving other > > queued tasks? The custodian will never get to work on those tasks > > unless the requestors (say checkpoint or some other process) requests > > it to do so after restart. Maybe, we don't need to worry about it. > > Maybe we need to worry about it. Maybe it's an overkill to save the > > custodian's task state to disk so that it can come up and do the > > leftover tasks upon restart. > > Yes, tasks will need to be retried when the server starts again. The ones > in this patch set should be requested again during the next checkpoint. > Temporary file cleanup would always be requested during server start, so > that should be handled as well. Even today, the server might abruptly shut > down while executing these tasks, and we don't have any special handling > for that. Right. The v18 patch set posted upthread https://www.postgresql.org/message-id/20221201214026.GA1799688%40nathanxps13 looks good to me. I see the CF entry is marked RfC - https://commitfest.postgresql.org/41/3448/. -- Bharath Rupireddy PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com