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.96) (envelope-from ) id 1w2R2u-000Hob-17 for pgsql-hackers@arkaria.postgresql.org; Tue, 17 Mar 2026 09:49:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w2R2s-00HYA6-2s for pgsql-hackers@arkaria.postgresql.org; Tue, 17 Mar 2026 09:49:02 +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.96) (envelope-from ) id 1w2R2s-00HY9y-1P for pgsql-hackers@lists.postgresql.org; Tue, 17 Mar 2026 09:49:02 +0000 Received: from mail-oo1-xc32.google.com ([2607:f8b0:4864:20::c32]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w2R2o-00000000ACB-3RRI for pgsql-hackers@postgresql.org; Tue, 17 Mar 2026 09:49:01 +0000 Received: by mail-oo1-xc32.google.com with SMTP id 006d021491bc7-67bac077116so2868550eaf.1 for ; Tue, 17 Mar 2026 02:49:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1773740939; cv=none; d=google.com; s=arc-20240605; b=T5KCnX3PoFUH9WoFAJGS1ZHGCRQsxTXr14NTyZonh2kQRHdJ5DTrQfgTN5mCW0si6g pRXrCkoTRVAFf0KS1gdq1KEUZv8qfZgufFKBRASPEsqDasdrywzeZhVLHP5HN+j0oW+g PNKwfOiInhrAHZMjO9mZhJdNYEeDBpyIPJXGBsMLCAJS7ukCgLIpBeW7Q/81ejeLnBZE Ycjx7GcSoCy4mQjCdqtWgnkREwCOLZRoYTDmwD7z7ncAs9IdnzyH35Whfkieo9s42Fdx nY1aczFErMRmJoG1rAdJixjSghcxsqKFp7XeStlliDScp3DEJFPdrdynIbeVpJ1tyj1e DbuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=RbQ1qtD0QZJLvzz+pYX8IHatmtTZiuiqQozcKp4jXz0=; fh=2TUkWQJWrihgcwEYYWeSl5QrOQuzC++SPZOHNkzx6bI=; b=FpAbRaK+k33yjHab23gWjhh8QotA7lY7gEBxNUgvzbg3C1J/LVQnc+FVAHNfcetxfV 29R3dEeAI/xwqb6jhGm6MPy+hAnDX/4J7U16JdEYAupGMrL12quu7FFRvOrqf6YlVrDb y94xncdG4DSpkwcBUkB4f3O0AHA9m0AjNRh/MVglhH/LLiagxXcbJjsZ46BSf6WT2Dcg XmUjwE55q39qTnaWe0TGZ+PHrhTINWbi8JFoyLYEn8j3qrPrSvLp9dnyOoXgh9ZDHaRB lUi4nsy2B7ezhVXFchVzoh2mLIvTkEVzMlqW5gasdT+sP6h+r2t2kcTiqb0L+50CsIrJ hM4w==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773740939; x=1774345739; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=RbQ1qtD0QZJLvzz+pYX8IHatmtTZiuiqQozcKp4jXz0=; b=EYbdMlmE6D7Eaul+PZU3xxBmbdxM8ZDMekbluCYXjJJh+m2htmg+EkaQZ0ZuzSdl3e Ox+A82XO3bILxYvVJWeZPvt0ucWlq2mUZBPfiVCmH728BxgfEKaJ5ZN6gtXEe3KUF8/c maepsMFrXMTssKoyHMMIV1PVAaLhTr1yksNxKiCQw9xi/lUQ9p0hgJoXMBCP+tknNXEN gFRb/R1PQO5B7h+cYPtgxMWh+SL4aPbfKWtIxNBPgZyr0U2RnmOkhsIJ+YSqFopeVfKl UoM8htrLac3epmbDlScNT4N5kxsxqhiqLCUGFKzAK3OarSxFzxtHv1y3zCDi+IoiPPFF TORg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773740939; x=1774345739; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=RbQ1qtD0QZJLvzz+pYX8IHatmtTZiuiqQozcKp4jXz0=; b=rSuTwfiMBmuXn3LMCQXAFfuHVm4X5igvoVaLeYXqEk5Tpp75xFnny57JPztgvWhYdM vNPpjI7+WgYBNCYFstRyrle/VimTiUVGiGR3rYJC6LU1ScvCZ/7GHsx2p+6trcdrhgCT ES035DyPK29CZoYWKgz36nQ3qEqcM5B9ubeUpCnfe6Teu18rcc44HCESpjoeB23VBaUQ LSR+HSxSv5ePHt1+giOYGds8ijW+5xiAZWFet9KROEgfW16iHcTrLgEuOLGh2e/13K06 ScnCbWsitZIKFJjguNxhGbKEybUGlTIsZCBuEnKNGvwhnHBdX06DZklD7ZvjPJtjcMv1 L/tw== X-Forwarded-Encrypted: i=1; AJvYcCXbQAJu96RlhnqCf1gDAYbb569VaMg96XMJ7kx8/l+U0WyO6+ubY3yRi7m/gGhQbpdji1+o4CKX/6sHzdFi@postgresql.org X-Gm-Message-State: AOJu0YyYPchScEBrhqOCrttsoO6RXN0ZDWHCTG39Uob/ufZTJK6steH3 ZRdyn9W38+l+7Nt0RGiTVuFSgoeEDkRWs9qxJQU9o+bQ06kKdUvVdgrN8/6ZjLPZ/hzFH/jdYfu M1a6AyAWUvtgsEPMPP/LGkwYUcBgB88Y= X-Gm-Gg: ATEYQzygSVLBYkWR+f4qRnEYxXgNr2/Y0w1pa8GKPFOjnYhLs60Zufad9DYb5HfQDPx 1ciT3jl4RQpihDo28NfLADh8FYgu6rL0WCmRcTREBnHHCIVb7X2lnoU8LKRhhPEuJ2YsyBtiHge FMKi4XeYY4pHLu4mP6WwlMe95ZvVJwpzAkAwCMwTutMfkf477gqehEqInGeCjS5C0gzrzo0Ulwn EPowjCDdw3oMji5XoHb09ANbJmzHhm+9HpKdm5mZ+uky3yj/KpCP5FhxyOPaq7lHiBEYYypgANr KBkZOF/AVhXf8kqMgCeWan4ExolxE6/lPmHH8CCBtQ== X-Received: by 2002:a05:6820:55d2:20b0:67b:e3cf:a416 with SMTP id 006d021491bc7-67be3cfa75cmr5719039eaf.25.1773740939257; Tue, 17 Mar 2026 02:48:59 -0700 (PDT) MIME-Version: 1.0 References: <0cbf5d34-f117-456f-bcc0-50fa9a8eafba@gmail.com> <1D505B52-9D58-4783-846D-600391C2A3B1@gmail.com> In-Reply-To: From: Fujii Masao Date: Tue, 17 Mar 2026 18:48:46 +0900 X-Gm-Features: AaiRm53YJYCDpYj7hWuGYy4ExnFMQTFmJWr25z571YivEv9014ckwmh6EedShIg Message-ID: Subject: Re: Propagate XLogFindNextRecord error to callers To: Anthonin Bonnefoy Cc: Chao Li , Mircea Cadariu , PostgreSQL Hackers , Japin Li Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Feb 26, 2026 at 5:19=E2=80=AFPM Anthonin Bonnefoy wrote: > > Thanks for the comments! > > On Tue, Feb 24, 2026 at 5:00=E2=80=AFAM Chao Li = wrote: > > From a design perspective, I=E2=80=99m not sure we need to add a new er= rormsg parameter to XLogFindNextRecord(). The new parameter ultimately just= exposes state->errormsg_buf, so the returned errormsg implicitly depends o= n the lifetime of state, and we also need extra handling for cases like err= ormsg =3D=3D NULL. > > > > Instead, perhaps we could add a helper function, say XLogReaderGetLastE= rror(XLogReaderState *state). which internally pstrdup()s state->errormsg_b= uf (after checking errormsg_deferred, etc.). That way the caller owns the r= eturned string explicitly, and there=E2=80=99s no hidden dependency on the = reader state=E2=80=99s lifetime. > > > > This would also avoid changing the XLogFindNextRecord() signature while= making the ownership semantics clearer. > > One issue I see is that it introduces another way to get the error, > with XLogReadRecord and XLogNextRecord using an errormsg parameter, > and XLogFindNextRecord using the helper function. Maybe the solution > would be to change both XLogReadRecord and XLogNextRecord to use this > new function to stay consistent, but that means changing their > signatures. > > Also, I see the errormsg parameter as a way to signal the caller that > "this function can fail, the detailed error will be available here". > With the XLogReaderGetLastError, it becomes the caller's > responsibility to know which function may fill the error message and > check it accordingly. > > The error message is likely printed shortly after the function's call, > so I suspect the risk of using the errormsg after its intended > lifetime is low. > > You bring up a good point about the errormsg's lifetime, which is > definitely something to mention in the function's comments. I've > updated the patch with the additional comments. Since this patch is marked Ready for Committer, I've started reviewing it. + * When set, *errormsg points to an internal buffer that's valid until the= next + * call to XLogReadRecord. Could that buffer also be invalidated by other functions that modify "XLogReaderState *state", such as XLogBeginRead()? +# Wrong WAL version. We copy an existing wal file and set the +# page's magic value to 0000. Would it be better to describe the purpose of this test at the top? For example: # Test that pg_waldump reports a detailed error message when dumping # a WAL file with an invalid magic number (0000). { # The broken WAL file is created by copying a valid WAL file an= d # overwriting its magic number with 0000. my $broken_wal_dir =3D PostgreSQL::Test::Utils::tempdir_short()= ; + open($fh, '+<', $broken_wal); + close($fh); Should we add error handling like: open(my $fh, '+<', $broken_wal) or BAIL_OUT("open($broken_wal) failed: $!"); close($fh) or BAIL_OUT("close failed: $!"); Also, other similar tests seem to call binmode. Is it really unnecessary in this case? Regards, --=20 Fujii Masao