Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qv7AA-003HJv-3M for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Oct 2023 02:28:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qv7A7-001ZCf-9J for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Oct 2023 02:28:55 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qv7A6-001ZBi-Mt for pgsql-hackers@lists.postgresql.org; Tue, 24 Oct 2023 02:28:55 +0000 Received: from mail-yb1-xb2e.google.com ([2607:f8b0:4864:20::b2e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qv7A4-0020AE-7Z for pgsql-hackers@postgresql.org; Tue, 24 Oct 2023 02:28:53 +0000 Received: by mail-yb1-xb2e.google.com with SMTP id 3f1490d57ef6-d84c24a810dso3554307276.2 for ; Mon, 23 Oct 2023 19:28:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1698114531; x=1698719331; darn=postgresql.org; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=y1gJckcK+LPU86jc7A0prsBzEJWAUgnyg3uEop39NNA=; b=dWR0iwSsDjdMpkvz8YbNCFt8oflLF6niCCnM6oyOgHzvzHetp2T7FRc0AverA8qfMd ssSWPEmczKbm7icwig/MAY7Y9tLlbsy60jdB2Wb4p2SjSWBr8CnuKwSq8nY+lEJeWmKO P85gU9iF5JCQQPO5wS6tnI+pkew0FOu4zGYf4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698114531; x=1698719331; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=y1gJckcK+LPU86jc7A0prsBzEJWAUgnyg3uEop39NNA=; b=c38Lw5cp0YThrGsSI9D8Iv64OMocJ7m0PvP806bMxiiu69SZr7A9i7P2PSFI+NbSzD 7l9kT011cW6uMGx5inErBhK2XwaF4/GNPJHc1u6YJ03DJIZO/FV2khIJe7+8pBrYyKrA 1vm9UwJSglVA++uqo81yRku1dhbqSHJkn6k2nRm6wLVntebXf2T7lkDfpAVMmbWeANZT gdLHtmL/P1VpK62DDq0ryqUX2lUrxArK1Js78zSqXTkvyzQ1Oss0bwcdYHcLGrwxIL00 QteR36mQAVgyjkklxaC8WNnjwFgOr1ySwP5AQftBfcW7uiuqQ7mTfqWhFzUHq9+tWFNd oYqg== X-Gm-Message-State: AOJu0YyyqaxAbuf8hgnC49tUQ8Eg1R7heF2xAi+yihO3xYkkSP75Sa5T KFQApHfbeG5Cd36Fleh4z7bkMg== X-Google-Smtp-Source: AGHT+IH6bT7E/6/WYGrBI8F1oxEslMFoRX5w3XSq4vIedYP7tDuutgoGlYibS1wF6tcuwHMbAEEfjw== X-Received: by 2002:a25:cb57:0:b0:d9a:5aa0:7a30 with SMTP id b84-20020a25cb57000000b00d9a5aa07a30mr10242173ybg.39.1698114531447; Mon, 23 Oct 2023 19:28:51 -0700 (PDT) Received: from google.com ([2600:1702:a20:5750::2e]) by smtp.gmail.com with ESMTPSA id s47-20020a25aa32000000b00d9ca5709f27sm310064ybi.37.2023.10.23.19.28.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Oct 2023 19:28:50 -0700 (PDT) Date: Mon, 23 Oct 2023 19:28:48 -0700 From: Noah Misch To: Peter Geoghegan Cc: pgsql-hackers@postgresql.org, Alexander Korotkov Subject: Re: post-recovery amcheck expectations Message-ID: <20231024022848.87.nmisch@google.com> References: <20231005025232.c7.nmisch@google.com> <20231021035457.cb.nmisch@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/2.2.12 (2023-09-09) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Oct 23, 2023 at 04:46:23PM -0700, Peter Geoghegan wrote: > On Fri, Oct 20, 2023 at 8:55 PM Noah Misch wrote: > > > > I lean toward fixing this by > > > > having amcheck scan left; if left links reach only half-dead or deleted pages, > > > > that's as good as the present child block being P_LEFTMOST. > > > > > > Also my preference. > > > > Done mostly that way, except I didn't accept deleted pages. Making this work > > on !readonly would take more than that, and readonly shouldn't need that. > > That makes sense to me. I believe that it's not possible to have a > string of consecutive sibling pages that are all half-dead (regardless > of the BlockNumber order of sibling pages, even). But I'd probably > have written the fix in roughly the same way. Although...maybe you > should try to detect a string of half-dead pages? Hard to say if it's > worth the trouble. I imagined a string of half-dead siblings could arise in structure like this: * 1 * / | \ * 4 <-> 2 <-> 3 With events like this: - DELETE renders blk 4 deletable. - Crash with concurrent VACUUM, leaving 4 half-dead after having visited 1-4. - DELETE renders blk 2 deletable. - Crash with concurrent VACUUM, leaving 2 half-dead after having visited 1-2. I didn't try to reproduce that, and something may well prevent it. > Suggest adding a CHECK_FOR_INTERRUPTS() call to the loop, too, just > for good luck. Added. That gave me the idea to check for circular links, like other parts of amcheck do. Net diff: --- a/contrib/amcheck/verify_nbtree.c +++ b/contrib/amcheck/verify_nbtree.c @@ -949,11 +949,16 @@ bt_leftmost_ignoring_half_dead(BtreeCheckState *state, Page page = palloc_btree_page(state, reached); BTPageOpaque reached_opaque = BTPageGetOpaque(page); + CHECK_FOR_INTERRUPTS(); + /* - * _bt_unlink_halfdead_page() writes that side-links will continue to - * point to the siblings. We can easily check btpo_next. + * Try to detect btpo_prev circular links. _bt_unlink_halfdead_page() + * writes that side-links will continue to point to the siblings. + * Check btpo_next for that property. */ - all_half_dead = P_ISHALFDEAD(reached_opaque) && + all_half_dead = P_ISHALFDEAD(reached_opaque); + reached != start && + reached != reached_from && reached_opaque->btpo_next == reached_from; if (all_half_dead) {