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 1rhp8g-00DYSV-NR for pgsql-bugs@arkaria.postgresql.org; Wed, 06 Mar 2024 11:08:47 +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 1rhp8e-0092it-GJ for pgsql-bugs@arkaria.postgresql.org; Wed, 06 Mar 2024 11:08:44 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rhp8e-0092iG-71 for pgsql-bugs@lists.postgresql.org; Wed, 06 Mar 2024 11:08:44 +0000 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rhp8b-0034Y9-8g for pgsql-bugs@lists.postgresql.org; Wed, 06 Mar 2024 11:08:43 +0000 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-33d6f26ff33so583212f8f.0 for ; Wed, 06 Mar 2024 03:08:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aiven.io; s=google; t=1709723320; x=1710328120; darn=lists.postgresql.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bhhDbTQGnvvWdfoy1qqS5pqWT09EfdGg8VJkfCJ8jYk=; b=gSgQqRIWq7HWdjz/lPzMZE8umJo5CqDek2wGo/ZEbWbHG0+axUpN9J399gHhF0NqwA zHEihySLwT0OJLoLXJqSNHjdfXIhjyOyCxBflBdLWH4vMpMb/BbqUt05wNVnzO4lXVKG Qio9trl0uEjkvp///D6Py4l+dlCTIWShOepms= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709723320; x=1710328120; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bhhDbTQGnvvWdfoy1qqS5pqWT09EfdGg8VJkfCJ8jYk=; b=aGu7rWmriPgmPIbzeVOiJurdmI3GvegVmN9qutP/SB9txPZzpH1MZz6JUMcXUHFM38 hmNC0IVlWghAimjmtA3kjfvobxFT465/41ny/l30rAVm6zKOftGqj8f98qK4IliftB2Y d+1ExZ7waFyQ+lqjOHizYan+XBJzeruHAPC5eN5tkaHHftKnR0qgMZSJ4QT05BCv/f7l CqCflqlwMK4Fw8appeHw7B+5cI0kfd/hHTCBJT2s3XTkbvvBaoks57w0Ss33yV9v84HX 7iVoeX+RUCGX705jGYuuAl6smn0JYXPa73npsYv4eEvyTKenzROAzPEX93IpU7DBBf8s FOwA== X-Gm-Message-State: AOJu0YzPPVNbc3jAjESvkt92Tp2YsW2eJ4jNYmelgRVNthVsAyf6stfM JuBPq8wTxBpACoAMFJQ255Fu00dQybtrppXaThBqNTcg8Shwc/UfZ35D2B+zeW8= X-Google-Smtp-Source: AGHT+IH1VBjvYpxnthADjtL+FvDKRxG2Cb/PJCUdwWYZa/l2NAhP5mz6eMLTucrCFlLAq9xq5B2e/w== X-Received: by 2002:a5d:4445:0:b0:33e:24c7:78c4 with SMTP id x5-20020a5d4445000000b0033e24c778c4mr8687553wrr.52.1709723320369; Wed, 06 Mar 2024 03:08:40 -0800 (PST) Received: from aivenlaptop.localnet ([45.13.105.93]) by smtp.gmail.com with ESMTPSA id bx10-20020a5d5b0a000000b0033df46f70dbsm17946781wrb.9.2024.03.06.03.08.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 03:08:39 -0800 (PST) From: Ronan Dunklau To: Noah Misch , Michael Paquier , Patrick =?ISO-8859-1?Q?St=E4hlin?= Cc: pgsql-bugs Subject: Re: FSM Corruption (was: Could not read block at end of the relation) Date: Wed, 06 Mar 2024 12:08:38 +0100 Message-ID: <1979116.usQuhbGJ8B@aivenlaptop> In-Reply-To: References: <1958756.PYKUYFuaPT@aivenlaptop> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart3470556.QJadu78ljV" Content-Transfer-Encoding: 7Bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --nextPart3470556.QJadu78ljV Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1" Le mercredi 6 mars 2024, 11:59:43 CET Patrick St=E4hlin a =E9crit : > On 3/6/24 10:31, Ronan Dunklau wrote: > > Le mardi 5 mars 2024, 00:05:03 CET Noah Misch a =E9crit : > >> I would guess this one is more risky from a performance perspective, > >> since > >> we'd be adding to a hotter path under RelationGetBufferForTuple().=20 > >> Still, > >> it's likely fine. > >=20 > > I ended up implementing this in the attached patch. The idea is that we > > detect if the FSM returns a page past the end of the relation, and igno= re > > it. In that case we will fallback through the extension mechanism. >=20 > @@ -582,7 +583,17 @@ RelationGetBufferForTuple(Relation relation, Size le= n, > * We have no cached target page, so ask the FSM for an=20 initial > * target. > */ > + nblocks =3D RelationGetNumberOfBlocks(relation); > targetBlock =3D GetPageWithFreeSpace(relation,=20 targetFreeSpace); >=20 > I'd move the fetching of nblocks to after getting the targetBlock. This > avoids extending the relation in the unlikely event of a FSM/relation > extension in-between those two calls. Good catch. Please find attached v2 of the patch.=20 =2D- Ronan Dunklau --nextPart3470556.QJadu78ljV Content-Disposition: attachment; filename="0002-Detect-invalid-FSM-when-finding-a-block.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="x-UTF_8J"; name="0002-Detect-invalid-FSM-when-finding-a-block.patch"