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 1nKOFA-0004EW-Bq for pgsql-hackers@arkaria.postgresql.org; Wed, 16 Feb 2022 17:37:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nKOF8-0002lw-Rr for pgsql-hackers@arkaria.postgresql.org; Wed, 16 Feb 2022 17:37:30 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nKOF8-0002lm-H2 for pgsql-hackers@lists.postgresql.org; Wed, 16 Feb 2022 17:37:30 +0000 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nKOF3-0000mW-BS for pgsql-hackers@postgresql.org; Wed, 16 Feb 2022 17:37:29 +0000 Received: by mail-pl1-x631.google.com with SMTP id l8so2534797pls.7 for ; Wed, 16 Feb 2022 09:37:25 -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=A1FhY3au7CALHbwogpqdV9HWBUUl0yPA4zlwWO9aYME=; b=BWaaFr1SMxcmBpCoJvC6yLKjxJRlHfr5SDnHfnkwQo97SneYJOfL8qEE5NNMuIg+gO dx70aE7DjurF6RGgu57ztjAsJJICgm3WNsx3HN5VMnmdHq0c6/t0++wAV1CFU2FKJs2+ AyPcIY2lmUB7vi1fCiuGdhfGMQ2ysP7tZdVptdqq6JErmv2UssERQ95O4Ae00rCrqznl EfzGGO68dcyqcUvT6GXh7s3JyZ0eCsyWbw6QVxYjhf/iFdjluGpK1dnWyZJCkyuVoCSK KuHbLjggYh21LdtFGFrOPRmDp2ullEebxUpgS7VS6XF02VOODFrEZVF9YY08FdgY81ZB BWlA== 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=A1FhY3au7CALHbwogpqdV9HWBUUl0yPA4zlwWO9aYME=; b=VBQy+sBR1odS7F1KJQ/kq2J+kZ9fPJNZJFEfGWfcCwg2FtJaigsd7lb5AIZEnc6qjU ikmKiMFqQ6WSoHcIfGonX0Xxqg54sZ4W532BCcoYW2Z+Qz+maEOf6TeKBY+kXP+5/qvg EZfv6t4AZP+9+rWqXheEDHVZethot1zrRK+alaxqibrI6J+8RGKod8R8Ut8MR2nVIs/x zHCE/+Rj8NE7lB9+6xc2zUA+nL3fwJIv9jnUwBGSqkH0FoiSkixBfuOJJGzdzdpE4MkJ BTD2lih6bgQQJwrqIwAS6K6oOJAISqRE0mQgvPq4aY5r8Ca0P88sf+kDyoPBxZJelLiY bi9Q== X-Gm-Message-State: AOAM530PrtnaKuFyXU0oH+8uIitc65a7oYy5P/z0RjdyYq94tWJdsFyF zX/cnS6D3gh+bLd4ojSPSOU= X-Google-Smtp-Source: ABdhPJzld0ZTaL92ML5p4Hzj+hdyMKFOGXA2kBduJ4Kb1lPcth/a58fEY0fQxHha3gImatLnS5Zwhg== X-Received: by 2002:a17:902:7892:b0:14e:c520:e47d with SMTP id q18-20020a170902789200b0014ec520e47dmr3442441pll.105.1645033044242; Wed, 16 Feb 2022 09:37:24 -0800 (PST) Received: from nathanxps13 ([50.54.155.70]) by smtp.gmail.com with ESMTPSA id oa10sm19653220pjb.54.2022.02.16.09.37.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Feb 2022 09:37:23 -0800 (PST) Date: Wed, 16 Feb 2022 09:37:21 -0800 From: Nathan Bossart To: Andres Freund Cc: Thomas Munro , pgsql-hackers Subject: Re: USE_BARRIER_SMGRRELEASE on Linux? Message-ID: <20220216173721.GA3007497@nathanxps13> References: <20220215235845.GA2665318@nathanxps13> <20220216045911.GA2791824@nathanxps13> <20220216050645.7u3nguccykpqaw7p@alap3.anarazel.de> <20220216061404.GA2813338@nathanxps13> <20220216065732.GA2932808@nathanxps13> <20220216164442.GA2935315@nathanxps13> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="W/nzBZO5zC0uMSeA" Content-Disposition: inline In-Reply-To: <20220216164442.GA2935315@nathanxps13> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --W/nzBZO5zC0uMSeA Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Feb 16, 2022 at 08:44:42AM -0800, Nathan Bossart wrote: > On Tue, Feb 15, 2022 at 10:57:32PM -0800, Nathan Bossart wrote: >> On Tue, Feb 15, 2022 at 10:14:04PM -0800, Nathan Bossart wrote: >>> It looks like register_unlink_segment() is called prior to the checkpoint, >>> but the checkpointer is not calling RememberSyncRequest() until after >>> SyncPreCheckpoint(). This means that the requests are registered with the >>> next checkpoint cycle count, so they aren't processed until the next >>> checkpoint. >> >> Calling AbsorbSyncRequests() before advancing the checkpoint cycle counter >> seems to fix the issue. However, this requires moving SyncPreCheckpoint() >> out of the critical section in CreateCheckPoint(). Patch attached. > > An alternative fix might be to call AbsorbSyncRequests() after increasing > the ckpt_started counter in CheckpointerMain(). AFAICT there is a window > just before checkpointing where new requests are registered for the > checkpoint following the one about to begin. Here's a patch that adds a call to AbsorbSyncRequests() in CheckpointerMain() instead of SyncPreCheckpoint(). I've also figured out a way to reproduce the issue without the pre-allocation patches applied: 1. In checkpointer.c, add a 30 second sleep before acquiring ckpt_lck to increment ckpt_started. 2. In session 1, run the following commands: a. CREATE TABLESPACE test LOCATION '/path/to/dir'; b. CREATE TABLE test TABLESPACE test AS SELECT 1; 3. In session 2, start a checkpoint. 4. In session 1, run these commands: a. ALTER TABLE test SET TABLESPACE pg_default; b. DROP TABLESPACE test; -- fails c. DROP TABLESPACE test; -- succeeds With the attached patch applied, the first attempt at dropping the tablespace no longer fails. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com --W/nzBZO5zC0uMSeA Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0001-call-AbsorbSyncRequests-after-indicating-checkpoi.patch" From e9707dfde25eaa9c447032c4b5a61e3011141dc9 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Wed, 16 Feb 2022 09:26:08 -0800 Subject: [PATCH v2 1/1] call AbsorbSyncRequests() after indicating checkpoint start --- src/backend/postmaster/checkpointer.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/backend/postmaster/checkpointer.c b/src/backend/postmaster/checkpointer.c index 4488e3a443..e93d34b71f 100644 --- a/src/backend/postmaster/checkpointer.c +++ b/src/backend/postmaster/checkpointer.c @@ -401,6 +401,18 @@ CheckpointerMain(void) ConditionVariableBroadcast(&CheckpointerShmem->start_cv); + /* + * Pick up any last minute requests. DROP TABLESPACE schedules a + * checkpoint to clean up any lingering files that are scheduled for + * deletion. If we don't absorb those requests now, they might not + * be absorbed until after incrementing the checkpoint cycle + * counter, so the files won't be deleted until the following + * checkpoint. By absorbing requests after indicating the + * checkpoint has started, operations like DROP TABLESPACE can be + * sure that the next checkpoint will clean up any such files. + */ + AbsorbSyncRequests(); + /* * The end-of-recovery checkpoint is a real checkpoint that's * performed while we're still in recovery. -- 2.25.1 --W/nzBZO5zC0uMSeA--