pgsql: Improve error message for snapshot import in snapmgr.c, take two

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Improve error message for snapshot import in snapmgr.c, take two
Date: 2023-09-19 01:24:38
Message-ID: E1qiPTh-004fFq-Qm@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Improve error message for snapshot import in snapmgr.c, take two

When a snapshot file fails to be read in ImportSnapshot(), it would
issue an ERROR as "invalid snapshot identifier" when opening a stream
for it in read-only mode. The error handling is improved to be more
talkative in failure cases:
- If a snapshot identifier uses incorrect characters, complain with the
same error as before this commit.
- If the snapshot file cannot be found in pg_snapshots/, complain with a
"snapshot \"foo\" does not exist" instead. This maps to the case where
AllocateFile() fails on ENOENT. Based on a suggestion from Andres
Freund.
- If AllocateFile() throws something else than ENOENT as errno, report
it with more details in %m instead, as these failures are never
expected.

b29504eeb489 was the first improvement take. The older error message
exists since bb446b689b66 that introduced snapshot imports. Two test
cases are added to cover the cases of an identifier with an incorrect
format and of a missing snapshot.

Author: Bharath Rupireddy
Reviewed-by: Andres Freund, Daniel Gustafsson, Michael Paquier
Discussion: https://postgr.es/m/CALj2ACWmr=3KdxDkm8h7Zn1XxBoF6hdzq8WQyMn2y1OL5RYFrg@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/78a33bba4c634afc3c67dddeb359b5ce872a0b04

Modified Files
--------------
src/backend/utils/time/snapmgr.c | 18 +++++++++++++++---
src/test/regress/expected/transactions.out | 11 +++++++++++
src/test/regress/sql/transactions.sql | 9 +++++++++
3 files changed, 35 insertions(+), 3 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Eisentraut 2023-09-19 07:51:19 pgsql: Standardize type of extend_by counter
Previous Message Michael Paquier 2023-09-18 23:32:06 pgsql: Fix assertion failure with PL/Python exceptions