pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Logging corruption error codes
12+ messages / 5 participants
[nested] [flat]

Commits from this thread:
  2019-08-01 fd6ec93bf8  Add error codes to some corruption log messages
* Logging corruption error codes
@ 2019-06-20 09:57 Andrey Borodin <x4mmm@yandex-team.ru>
  2019-06-20 17:09 ` Re: Logging corruption error codes Alvaro Herrera <alvherre@2ndquadrant.com>
  2019-07-22 11:16 ` Re: Logging corruption error codes Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  0 siblings, 2 replies; 12+ messages in thread

From: Andrey Borodin @ 2019-06-20 09:57 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org, Анна Крханбарова <annkpx@yandex-team.ru>; Dmitriy Sarafannikov <dsarafan@yandex-team.ru>

Hi!

We are fine-tuning our data corruption monitoring and found out that many corruption cases do not report proper error code.
This makes automatic log analyzer way too smart program.
We think that corruption error codes should be given in cases when B-tree or TOAST do not know how to interpret data.
PFA patch with cases that we have found in logs and consider evidence of corruption.

Best regards, Andrey Borodin.

Attachments:

0001-Log-corruption-error-codes.patch (application/octet-stream, 5.7K) download From 197f997dc08dac80407c6158c8e61b1394702d1b Mon Sep 17 00:00:00 2001 From: Andrey <amborodin@acm.org> Date: Thu, 20 Jun 2019 14:40:52 +0500 Subject: [PATCH] Log corruption error codes In some cases we have elog(ERROR) while corruption is certain and we can give clear error code ERRCODE_DATA_CORRUPTED or ERRCODE_INDEX_CORRUPTED. --- src/backend/access/heap/tuptoaster.c | 25 +++++++++++++++---------- src/backend/access/nbtree/nbtinsert.c | 5 +++-- src/backend/access/nbtree/nbtpage.c | 5 +++-- src/backend/access/nbtree/nbtsearch.c | 5 +++-- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/backend/access/heap/tuptoaster.c b/src/backend/access/heap/tuptoaster.c index 55d6e91d1c..539842d46e 100644 --- a/src/backend/access/heap/tuptoaster.c +++ b/src/backend/access/heap/tuptoaster.c @@ -1966,35 +1966,39 @@ toast_fetch_datum(struct varlena *attr) * Some checks on the data we've found */ if (residx != nextidx) - elog(ERROR, "unexpected chunk number %d (expected %d) for toast value %u in %s", + ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("unexpected chunk number %d (expected %d) for toast value %u in %s", residx, nextidx, toast_pointer.va_valueid, - RelationGetRelationName(toastrel)); + RelationGetRelationName(toastrel)))); if (residx < numchunks - 1) { if (chunksize != TOAST_MAX_CHUNK_SIZE) - elog(ERROR, "unexpected chunk size %d (expected %d) in chunk %d of %d for toast value %u in %s", + ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("unexpected chunk size %d (expected %d) in chunk %d of %d for toast value %u in %s", chunksize, (int) TOAST_MAX_CHUNK_SIZE, residx, numchunks, toast_pointer.va_valueid, - RelationGetRelationName(toastrel)); + RelationGetRelationName(toastrel)))); } else if (residx == numchunks - 1) { if ((residx * TOAST_MAX_CHUNK_SIZE + chunksize) != ressize) - elog(ERROR, "unexpected chunk size %d (expected %d) in final chunk %d for toast value %u in %s", + ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("unexpected chunk size %d (expected %d) in final chunk %d for toast value %u in %s", chunksize, (int) (ressize - residx * TOAST_MAX_CHUNK_SIZE), residx, toast_pointer.va_valueid, - RelationGetRelationName(toastrel)); + RelationGetRelationName(toastrel)))); } else - elog(ERROR, "unexpected chunk number %d (out of range %d..%d) for toast value %u in %s", + ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("unexpected chunk number %d (out of range %d..%d) for toast value %u in %s", residx, 0, numchunks - 1, toast_pointer.va_valueid, - RelationGetRelationName(toastrel)); + RelationGetRelationName(toastrel)))); /* * Copy the data into proper place in our result @@ -2010,10 +2014,11 @@ toast_fetch_datum(struct varlena *attr) * Final checks that we successfully fetched the datum */ if (nextidx != numchunks) - elog(ERROR, "missing chunk number %d for toast value %u in %s", + ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("missing chunk number %d for toast value %u in %s", nextidx, toast_pointer.va_valueid, - RelationGetRelationName(toastrel)); + RelationGetRelationName(toastrel)))); /* * End scan and close relations diff --git a/src/backend/access/nbtree/nbtinsert.c b/src/backend/access/nbtree/nbtinsert.c index 602f8849d4..af56f747df 100644 --- a/src/backend/access/nbtree/nbtinsert.c +++ b/src/backend/access/nbtree/nbtinsert.c @@ -1568,10 +1568,11 @@ _bt_split(Relation rel, BTScanInsert itup_key, Buffer buf, Buffer cbuf, if (sopaque->btpo_prev != origpagenumber) { memset(rightpage, 0, BufferGetPageSize(rbuf)); - elog(ERROR, "right sibling's left-link doesn't match: " + ereport(ERROR, (errcode(ERRCODE_INDEX_CORRUPTED), + errmsg("right sibling's left-link doesn't match: " "block %u links to %u instead of expected %u in index \"%s\"", oopaque->btpo_next, sopaque->btpo_prev, origpagenumber, - RelationGetRelationName(rel)); + RelationGetRelationName(rel)))); } /* diff --git a/src/backend/access/nbtree/nbtpage.c b/src/backend/access/nbtree/nbtpage.c index de4d4efc46..f050b4a343 100644 --- a/src/backend/access/nbtree/nbtpage.c +++ b/src/backend/access/nbtree/nbtpage.c @@ -1952,10 +1952,11 @@ _bt_unlink_halfdead_page(Relation rel, Buffer leafbuf, bool *rightsib_empty) page = BufferGetPage(rbuf); opaque = (BTPageOpaque) PageGetSpecialPointer(page); if (opaque->btpo_prev != target) - elog(ERROR, "right sibling's left-link doesn't match: " + ereport(ERROR, (errcode(ERRCODE_INDEX_CORRUPTED), + errmsg("right sibling's left-link doesn't match: " "block %u links to %u instead of expected %u in index \"%s\"", rightsib, opaque->btpo_prev, target, - RelationGetRelationName(rel)); + RelationGetRelationName(rel)))); rightsib_is_rightmost = P_RIGHTMOST(opaque); *rightsib_empty = (P_FIRSTDATAKEY(opaque) > PageGetMaxOffsetNumber(page)); diff --git a/src/backend/access/nbtree/nbtsearch.c b/src/backend/access/nbtree/nbtsearch.c index 1f809c24a1..0e148a31c5 100644 --- a/src/backend/access/nbtree/nbtsearch.c +++ b/src/backend/access/nbtree/nbtsearch.c @@ -2113,8 +2113,9 @@ _bt_get_endpoint(Relation rel, uint32 level, bool rightmost, if (opaque->btpo.level == level) break; if (opaque->btpo.level < level) - elog(ERROR, "btree level %u not found in index \"%s\"", - level, RelationGetRelationName(rel)); + ereport(ERROR, (errcode(ERRCODE_INDEX_CORRUPTED), + errmsg("btree level %u not found in index \"%s\"", + level, RelationGetRelationName(rel)))); /* Descend to leftmost or rightmost child page */ if (rightmost) -- 2.20.1 =
^ permalink raw reply [nested|flat] 12+ messages in thread

* Re: Logging corruption error codes
  2019-06-20 09:57 Logging corruption error codes Andrey Borodin <x4mmm@yandex-team.ru>
@ 2019-06-20 17:09 ` Alvaro Herrera <alvherre@2ndquadrant.com>
  2019-06-21 10:22   ` Re: Logging corruption error codes Andrey Borodin <x4mmm@yandex-team.ru>
  1 sibling, 1 reply; 12+ messages in thread

From: Alvaro Herrera @ 2019-06-20 17:09 UTC (permalink / raw)
  To: Andrey Borodin <x4mmm@yandex-team.ru>; +Cc: pgsql-bugs@lists.postgresql.org, Анна Крханбарова <annkpx@yandex-team.ru>; Dmitriy Sarafannikov <dsarafan@yandex-team.ru>

On 2019-Jun-20, Andrey Borodin wrote:

> Hi!
> 
> We are fine-tuning our data corruption monitoring and found out that many corruption cases do not report proper error code.
> This makes automatic log analyzer way too smart program.
> We think that corruption error codes should be given in cases when B-tree or TOAST do not know how to interpret data.
> PFA patch with cases that we have found in logs and consider evidence of corruption.

This is not totally insane -- other similar messages such as 'corrupted
page pointers' in bufpage.c get the same errcode.

I would like to have a separate marking for messages indicating a
system-level permanent problem rather than user error ("table/column X
does not exist"), retryable condition ("serializability violation"), or
resource exhaustion ("out of memory", "too many clients"), but that's
probably a separate patch: things like "could not open/read/write file"
for a data file, or "xlog flush request XYZ not satisfied", and so on,
which also indicate a kind of corruption.  As you say, currently we have
to have much too smart programs to weed out the serious errors that
ought to show up in an alerting system from run-of-the-mill problems.

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services





^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Logging corruption error codes
  2019-06-20 09:57 Logging corruption error codes Andrey Borodin <x4mmm@yandex-team.ru>
  2019-06-20 17:09 ` Re: Logging corruption error codes Alvaro Herrera <alvherre@2ndquadrant.com>
@ 2019-06-21 10:22   ` Andrey Borodin <x4mmm@yandex-team.ru>
  2019-06-24 01:59     ` Re: Logging corruption error codes Michael Paquier <michael@paquier.xyz>
  0 siblings, 1 reply; 12+ messages in thread

From: Andrey Borodin @ 2019-06-21 10:22 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: pgsql-bugs@lists.postgresql.org, Анна Крханбарова <annkpx@yandex-team.ru>; Dmitriy Sarafannikov <dsarafan@yandex-team.ru>



> 20 июня 2019 г., в 22:09, Alvaro Herrera <alvherre@2ndquadrant.com> написал(а):
> 
> On 2019-Jun-20, Andrey Borodin wrote:
> 
>> Hi!
>> 
>> We are fine-tuning our data corruption monitoring and found out that many corruption cases do not report proper error code.
>> This makes automatic log analyzer way too smart program.
>> We think that corruption error codes should be given in cases when B-tree or TOAST do not know how to interpret data.
>> PFA patch with cases that we have found in logs and consider evidence of corruption.
> 
> This is not totally insane -- other similar messages such as 'corrupted
> page pointers' in bufpage.c get the same errcode.
On master there is only
elog(ERROR, "incorrect index offsets supplied");
in bufpage.c. But this indicate misuse, not corrupted data on disk.
Others already use ERRCODE_DATA_CORRUPTED.
> 
> I would like to have a separate marking for messages indicating a
> system-level permanent problem rather than user error ("table/column X
> does not exist"), retryable condition ("serializability violation"), or
> resource exhaustion ("out of memory", "too many clients"),
Good idea, but there must be standards to which we comply?

> but that's
> probably a separate patch: things like "could not open/read/write file"
> for a data file, or "xlog flush request XYZ not satisfied", and so on,
> which also indicate a kind of corruption.
I believe we should not report hardware problems as corruption. But this worries us (YC) too. Do you think that this problem deserve a patch?
If we introduce new error code - this is, kind of, new feature. Should I send it to pgsql-hackers?

>  As you say, currently we have
> to have much too smart programs to weed out the serious errors that
> ought to show up in an alerting system from run-of-the-mill problems.

Thanks!

Best regards, Andrey Borodin.




^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Logging corruption error codes
  2019-06-20 09:57 Logging corruption error codes Andrey Borodin <x4mmm@yandex-team.ru>
  2019-06-20 17:09 ` Re: Logging corruption error codes Alvaro Herrera <alvherre@2ndquadrant.com>
  2019-06-21 10:22   ` Re: Logging corruption error codes Andrey Borodin <x4mmm@yandex-team.ru>
@ 2019-06-24 01:59     ` Michael Paquier <michael@paquier.xyz>
  2019-06-25 10:01       ` Re: Logging corruption error codes Andrey Borodin <x4mmm@yandex-team.ru>
  0 siblings, 1 reply; 12+ messages in thread

From: Michael Paquier @ 2019-06-24 01:59 UTC (permalink / raw)
  To: Andrey Borodin <x4mmm@yandex-team.ru>; +Cc: Alvaro Herrera <alvherre@2ndquadrant.com>; pgsql-bugs@lists.postgresql.org, Анна Крханбарова <annkpx@yandex-team.ru>; Dmitriy Sarafannikov <dsarafan@yandex-team.ru>

On Fri, Jun 21, 2019 at 03:22:15PM +0500, Andrey Borodin wrote:
> 20 июня 2019 г., в 22:09, Alvaro Herrera <alvherre@2ndquadrant.com> написал(а):
>> This is not totally insane -- other similar messages such as 'corrupted
>> page pointers' in bufpage.c get the same errcode.
>
> On master there is only
> elog(ERROR, "incorrect index offsets supplied");
> in bufpage.c. But this indicate misuse, not corrupted data on disk.
> Others already use ERRCODE_DATA_CORRUPTED.

Yeah.  We may be able to expand the use of ERRCODE_DATA_CORRUPTED a
bit more in the area.  No objections against that.

>> I would like to have a separate marking for messages indicating a
>> system-level permanent problem rather than user error ("table/column X
>> does not exist"), retryable condition ("serializability violation"), or
>> resource exhaustion ("out of memory", "too many clients"),
>
> Good idea, but there must be standards to which we comply?

I am not completely sure what you are going at here?  Are you aiming
at creating more wrappers which are errno-specific, like
errcode_for_file_access() and such?

There is a set of categories in errcodes.txt which make a rather clear
classification of the different types of failures which can happen:
- Corruption cases are part of the "cannot happen" case.
- Serializable functions are related to transactionability.
- OOM is system-related.
- Too many clients is a Postgres-specific limitation.
So these look rather clear to me.

> I believe we should not report hardware problems as corruption. But
> this worries us (YC) too. Do you think that this problem deserve a
> patch?

The difference may not be easy here.  Postgres has no idea if the
problem comes from the FS, the kernel or the hardware itself.  We just
report the problem that the OS tells us about so I don't think that we
should try to be smarter than the OS telling us something.  elog()
points to an internal error which should never happen.  By that, it
seems to me that we should use elog() for cases where some code paths
should never be logically reached.  Now, there is no hard line here,
sometimes we finish by using elog() on purpose as a sanity check if
for example catalog data gets corrupted (you cannot use an assertion
if you rely on an on-page state, obviously), so improving things with
a case-by-case approach is fine in my opinion..

> If we introduce new error code - this is, kind of, new
> feature. Should I send it to pgsql-hackers?

Yes, I don't think that new error codes would gain a back-patch.
So discussing that on -hackers would be more adapted in my opinion.

Looking at the patch you propose, I don't have an argument against
applying what you propose FWIW.  These suggestions seem sensible.  But
that's not really a bug as the code works properly even without your
changes.

Note: the indentation of the patch is incorrect everywhere.  A
committer applying your patch would apply pgindent anyway.  :)
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Logging corruption error codes
  2019-06-20 09:57 Logging corruption error codes Andrey Borodin <x4mmm@yandex-team.ru>
  2019-06-20 17:09 ` Re: Logging corruption error codes Alvaro Herrera <alvherre@2ndquadrant.com>
  2019-06-21 10:22   ` Re: Logging corruption error codes Andrey Borodin <x4mmm@yandex-team.ru>
  2019-06-24 01:59     ` Re: Logging corruption error codes Michael Paquier <michael@paquier.xyz>
@ 2019-06-25 10:01       ` Andrey Borodin <x4mmm@yandex-team.ru>
  2019-06-26 01:59         ` Re: Logging corruption error codes Michael Paquier <michael@paquier.xyz>
  0 siblings, 1 reply; 12+ messages in thread

From: Andrey Borodin @ 2019-06-25 10:01 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; +Cc: Alvaro Herrera <alvherre@2ndquadrant.com>; pgsql-bugs@lists.postgresql.org, Анна Крханбарова <annkpx@yandex-team.ru>; Dmitriy Sarafannikov <dsarafan@yandex-team.ru>

Hi Michael!

> 24 июня 2019 г., в 6:59, Michael Paquier <michael@paquier.xyz> написал(а):
>> If we introduce new error code - this is, kind of, new
>> feature. Should I send it to pgsql-hackers?
> 
> Yes, I don't think that new error codes would gain a back-patch.
> So discussing that on -hackers would be more adapted in my opinion.
> 
> Looking at the patch you propose, I don't have an argument against
> applying what you propose FWIW.  These suggestions seem sensible.  But
> that's not really a bug as the code works properly even without your
> changes.

Ok, if it's not a bug, should I re-send it to pgsql-hackers@ ? Or just register on CF as a new thing...

> 
> Note: the indentation of the patch is incorrect everywhere.  A
> committer applying your patch would apply pgindent anyway.  :)
Oh, sorry. I'm trying to write "like a code around", but do not understand clearly how pgindent formats...

Best regards, Andrey Borodin. 






^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Logging corruption error codes
  2019-06-20 09:57 Logging corruption error codes Andrey Borodin <x4mmm@yandex-team.ru>
  2019-06-20 17:09 ` Re: Logging corruption error codes Alvaro Herrera <alvherre@2ndquadrant.com>
  2019-06-21 10:22   ` Re: Logging corruption error codes Andrey Borodin <x4mmm@yandex-team.ru>
  2019-06-24 01:59     ` Re: Logging corruption error codes Michael Paquier <michael@paquier.xyz>
  2019-06-25 10:01       ` Re: Logging corruption error codes Andrey Borodin <x4mmm@yandex-team.ru>
@ 2019-06-26 01:59         ` Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 12+ messages in thread

From: Michael Paquier @ 2019-06-26 01:59 UTC (permalink / raw)
  To: Andrey Borodin <x4mmm@yandex-team.ru>; +Cc: Alvaro Herrera <alvherre@2ndquadrant.com>; pgsql-bugs@lists.postgresql.org, Анна Крханбарова <annkpx@yandex-team.ru>; Dmitriy Sarafannikov <dsarafan@yandex-team.ru>

On Tue, Jun 25, 2019 at 03:01:23PM +0500, Andrey Borodin wrote:
> Ok, if it's not a bug, should I re-send it to pgsql-hackers@ ? Or
> just register on CF as a new thing...

If you wish to discard this patch and begin a more advanced discussion
about those errors, a new discussion on -hackers would be adapted.

Now, based on what I see you are suggesting for the couple of code
paths related to indexes, I don't see any problem in just applying
what you have (I'd need a second-look at it obviously), in which case
this thread is fine IMO.  I don't think that this should be
back-patched though as this is no bug fix, as mentioned upthread.

>> Note: the indentation of the patch is incorrect everywhere.  A
>> committer applying your patch would apply pgindent anyway.  :)
>
> Oh, sorry. I'm trying to write "like a code around", but do not
> understand clearly how pgindent formats...

No problem.  Trying to make the code consistent with the surroundings
is a good habit.
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Logging corruption error codes
  2019-06-20 09:57 Logging corruption error codes Andrey Borodin <x4mmm@yandex-team.ru>
@ 2019-07-22 11:16 ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2019-07-25 10:45   ` Re: Logging corruption error codes Andrey Borodin <x4mmm@yandex-team.ru>
  1 sibling, 1 reply; 12+ messages in thread

From: Peter Eisentraut @ 2019-07-22 11:16 UTC (permalink / raw)
  To: Andrey Borodin <x4mmm@yandex-team.ru>; pgsql-bugs@lists.postgresql.org, Анна Крханбарова <annkpx@yandex-team.ru>; Dmitriy Sarafannikov <dsarafan@yandex-team.ru>

On 2019-06-20 11:57, Andrey Borodin wrote:
> We are fine-tuning our data corruption monitoring and found out that many corruption cases do not report proper error code.
> This makes automatic log analyzer way too smart program.
> We think that corruption error codes should be given in cases when B-tree or TOAST do not know how to interpret data.
> PFA patch with cases that we have found in logs and consider evidence of corruption.
> 
> Best regards, Andrey Borodin.

Should we use errmsg_internal() in the adjusted calls, so that the error
messages are not picked up for translation?  I could go either way, but
it's something that should be considered.

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services





^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Logging corruption error codes
  2019-06-20 09:57 Logging corruption error codes Andrey Borodin <x4mmm@yandex-team.ru>
  2019-07-22 11:16 ` Re: Logging corruption error codes Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
@ 2019-07-25 10:45   ` Andrey Borodin <x4mmm@yandex-team.ru>
  2019-07-25 18:27     ` Re: Logging corruption error codes Peter Geoghegan <pg@bowt.ie>
  0 siblings, 1 reply; 12+ messages in thread

From: Andrey Borodin @ 2019-07-25 10:45 UTC (permalink / raw)
  To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: pgsql-bugs@lists.postgresql.org, Анна Крханбарова <annkpx@yandex-team.ru>; Dmitriy Sarafannikov <dsarafan@yandex-team.ru>



> 22 июля 2019 г., в 16:16, Peter Eisentraut <peter.eisentraut@2ndquadrant.com> написал(а):
> 
> On 2019-06-20 11:57, Andrey Borodin wrote:
>> We are fine-tuning our data corruption monitoring and found out that many corruption cases do not report proper error code.
>> This makes automatic log analyzer way too smart program.
>> We think that corruption error codes should be given in cases when B-tree or TOAST do not know how to interpret data.
>> PFA patch with cases that we have found in logs and consider evidence of corruption.
>> 
>> Best regards, Andrey Borodin.
> 
> Should we use errmsg_internal() in the adjusted calls, so that the error
> messages are not picked up for translation?  I could go either way, but
> it's something that should be considered.

Thanks for looking into this.

From my POV these messages provide meaningful information to cope with corruption. But they are definitely internal.
Translations already provide some information on toast chunks, mentions btree many times times and many other internal things.
So, I'm confused about status of these messages.
Such messages should be rare enough and those to whom they are addressed should be familiar with English.

We've encountered few more cases of messages, that potentially follow data corruption. In our test environment, we were experimenting with custom Linux kernel that had page cache bug. The bug manifested itself in reappearing stale page versions. This causes various data corruptions, always undetected by data checksums (do we want Merkle tree?).

Besides messages in this patch we also had:
could not read block 1751 in file "base/16452/358336": Bad address  // Probably mostly not only data corruption, but hardware fault
t_xmin is uncommitted in tuple to be updated // Probably on-disk corruption
failed to re-find parent key in index // Probably index corruption
left link changed unexpectedly in block // Probably on-disk data corruption
right sibling 45056 of block * is not next child * of block * in index // Definitely index corruption

Should I add corruption codes for these messages in the patch? Or make a separate discussion about these?

Thanks!

Best regards, Andrey Borodin.




^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Logging corruption error codes
  2019-06-20 09:57 Logging corruption error codes Andrey Borodin <x4mmm@yandex-team.ru>
  2019-07-22 11:16 ` Re: Logging corruption error codes Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2019-07-25 10:45   ` Re: Logging corruption error codes Andrey Borodin <x4mmm@yandex-team.ru>
@ 2019-07-25 18:27     ` Peter Geoghegan <pg@bowt.ie>
  2019-07-31 06:07       ` Re: Logging corruption error codes Andrey Borodin <x4mmm@yandex-team.ru>
  0 siblings, 1 reply; 12+ messages in thread

From: Peter Geoghegan @ 2019-07-25 18:27 UTC (permalink / raw)
  To: Andrey Borodin <x4mmm@yandex-team.ru>; +Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>; Анна Крханбарова <annkpx@yandex-team.ru>; Dmitriy Sarafannikov <dsarafan@yandex-team.ru>

On Thu, Jul 25, 2019 at 3:45 AM Andrey Borodin <x4mmm@yandex-team.ru> wrote:
> From my POV these messages provide meaningful information to cope with corruption. But they are definitely internal.
> Translations already provide some information on toast chunks, mentions btree many times times and many other internal things.
> So, I'm confused about status of these messages.
> Such messages should be rare enough and those to whom they are addressed should be familiar with English.

I agree that these don't need to be translated, which means you must
use errmsg_internal() with ereport(). A message like "failed to
re-find parent key in index..." doesn't mean anything to more than a
tiny number of experts. It is useful only because you can paste in
into a search engine. Users will want to search for the English string
anyway.

> This causes various data corruptions, always undetected by data checksums (do we want Merkle tree?).

I don't think that it's possible to verify the integrity of multiple
page images without amcheck support for the access method. It might be
possible to do slightly more in a generic way, but I doubt it.

> Besides messages in this patch we also had:
> could not read block 1751 in file "base/16452/358336": Bad address  // Probably mostly not only data corruption, but hardware fault
> t_xmin is uncommitted in tuple to be updated // Probably on-disk corruption
> failed to re-find parent key in index // Probably index corruption
> left link changed unexpectedly in block // Probably on-disk data corruption
> right sibling 45056 of block * is not next child * of block * in index // Definitely index corruption
>
> Should I add corruption codes for these messages in the patch? Or make a separate discussion about these?

I don't think that we need to worry too much about the difference
between data corruption and a hardware fault that could theoretically
self-correct. There is a cost to making fine distinctions like this in
the errcodes we use.

-- 
Peter Geoghegan





^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Logging corruption error codes
  2019-06-20 09:57 Logging corruption error codes Andrey Borodin <x4mmm@yandex-team.ru>
  2019-07-22 11:16 ` Re: Logging corruption error codes Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2019-07-25 10:45   ` Re: Logging corruption error codes Andrey Borodin <x4mmm@yandex-team.ru>
  2019-07-25 18:27     ` Re: Logging corruption error codes Peter Geoghegan <pg@bowt.ie>
@ 2019-07-31 06:07       ` Andrey Borodin <x4mmm@yandex-team.ru>
  2019-08-01 09:26         ` Re: Logging corruption error codes Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  0 siblings, 1 reply; 12+ messages in thread

From: Andrey Borodin @ 2019-07-31 06:07 UTC (permalink / raw)
  To: Peter Geoghegan <pg@bowt.ie>; +Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>; Анна Крханбарова <annkpx@yandex-team.ru>; Dmitriy Sarafannikov <dsarafan@yandex-team.ru>

Please find attached patch v2: added a little more cases with corruption.

> 25 июля 2019 г., в 23:27, Peter Geoghegan <pg@bowt.ie> написал(а):
> 
> On Thu, Jul 25, 2019 at 3:45 AM Andrey Borodin <x4mmm@yandex-team.ru> wrote:
>> From my POV these messages provide meaningful information to cope with corruption. But they are definitely internal.
>> Translations already provide some information on toast chunks, mentions btree many times times and many other internal things.
>> So, I'm confused about status of these messages.
>> Such messages should be rare enough and those to whom they are addressed should be familiar with English.
> 
> I agree that these don't need to be translated, which means you must
> use errmsg_internal() with ereport(). A message like "failed to
> re-find parent key in index..." doesn't mean anything to more than a
> tiny number of experts. It is useful only because you can paste in
> into a search engine. Users will want to search for the English string
> anyway.
We already have translations for messages like "index \"%s\" is not a btree" and "version mismatch in index \"%s\": file version %d, ".
Personally, I agree that we should try to make these messages googlable in mailing lists. Marking them errmsg_internal will discard some work of translators.
So I haven't marked them internal in this version.

>> This causes various data corruptions, always undetected by data checksums (do we want Merkle tree?).
> 
> I don't think that it's possible to verify the integrity of multiple
> page images without amcheck support for the access method. It might be
> possible to do slightly more in a generic way, but I doubt it.

Well, if you have a fork with LSNs of each page - you can guarantee that that you do not have stale version of single page. And you can have cheap block-level incremental backups, fast catchup of standbys etc. But this comes at a cost. Anyway, it's a discussion for another thread.

>> Besides messages in this patch we also had:
>> could not read block 1751 in file "base/16452/358336": Bad address  // Probably mostly not only data corruption, but hardware fault
>> t_xmin is uncommitted in tuple to be updated // Probably on-disk corruption
>> failed to re-find parent key in index // Probably index corruption
>> left link changed unexpectedly in block // Probably on-disk data corruption
>> right sibling 45056 of block * is not next child * of block * in index // Definitely index corruption
>> 
>> Should I add corruption codes for these messages in the patch? Or make a separate discussion about these?
> 
> I don't think that we need to worry too much about the difference
> between data corruption and a hardware fault that could theoretically
> self-correct. There is a cost to making fine distinctions like this in
> the errcodes we use.

Currently, that case with "could not read block" is marked by errcode_for_file_access(). I think that this code is better than corruption error code..

Thanks!

Best regards, Andrey Borodin.

Attachments:

0001-Log-corruption-error-codes-v2.patch (application/octet-stream, 9.5K) download From 65e0d8c079fb1ad8f69e0c530a11344f029bb691 Mon Sep 17 00:00:00 2001 From: Andrey <amborodin@acm.org> Date: Thu, 20 Jun 2019 14:40:52 +0500 Subject: [PATCH] Log corruption error codes v2 In some cases we have elog(ERROR) while corruption is certain and we can give clear error code ERRCODE_DATA_CORRUPTED or ERRCODE_INDEX_CORRUPTED. --- src/backend/access/heap/heapam_handler.c | 4 +- src/backend/access/heap/tuptoaster.c | 53 +++++++++++++----------- src/backend/access/nbtree/nbtinsert.c | 15 ++++--- src/backend/access/nbtree/nbtpage.c | 29 ++++++++----- src/backend/access/nbtree/nbtsearch.c | 5 ++- 5 files changed, 62 insertions(+), 44 deletions(-) diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c index a4a28e88ec..ac51d1f48e 100644 --- a/src/backend/access/heap/heapam_handler.c +++ b/src/backend/access/heap/heapam_handler.c @@ -426,7 +426,9 @@ tuple_lock_retry: /* otherwise xmin should not be dirty... */ if (TransactionIdIsValid(SnapshotDirty.xmin)) - elog(ERROR, "t_xmin is uncommitted in tuple to be updated"); + ereport(ERROR, + (errcode(ERRCODE_DATA_CORRUPTED), + errmsg(ERROR, "t_xmin is uncommitted in tuple to be updated"))); /* * If tuple is being updated by other transaction then we diff --git a/src/backend/access/heap/tuptoaster.c b/src/backend/access/heap/tuptoaster.c index 55d6e91d1c..13567ca22b 100644 --- a/src/backend/access/heap/tuptoaster.c +++ b/src/backend/access/heap/tuptoaster.c @@ -1966,35 +1966,39 @@ toast_fetch_datum(struct varlena *attr) * Some checks on the data we've found */ if (residx != nextidx) - elog(ERROR, "unexpected chunk number %d (expected %d) for toast value %u in %s", - residx, nextidx, - toast_pointer.va_valueid, - RelationGetRelationName(toastrel)); + ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("unexpected chunk number %d (expected %d) for toast value %u in %s", + residx, nextidx, + toast_pointer.va_valueid, + RelationGetRelationName(toastrel)))); if (residx < numchunks - 1) { if (chunksize != TOAST_MAX_CHUNK_SIZE) - elog(ERROR, "unexpected chunk size %d (expected %d) in chunk %d of %d for toast value %u in %s", - chunksize, (int) TOAST_MAX_CHUNK_SIZE, - residx, numchunks, - toast_pointer.va_valueid, - RelationGetRelationName(toastrel)); + ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("unexpected chunk size %d (expected %d) in chunk %d of %d for toast value %u in %s", + chunksize, (int) TOAST_MAX_CHUNK_SIZE, + residx, numchunks, + toast_pointer.va_valueid, + RelationGetRelationName(toastrel)))); } else if (residx == numchunks - 1) { if ((residx * TOAST_MAX_CHUNK_SIZE + chunksize) != ressize) - elog(ERROR, "unexpected chunk size %d (expected %d) in final chunk %d for toast value %u in %s", - chunksize, - (int) (ressize - residx * TOAST_MAX_CHUNK_SIZE), - residx, - toast_pointer.va_valueid, - RelationGetRelationName(toastrel)); + ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("unexpected chunk size %d (expected %d) in final chunk %d for toast value %u in %s", + chunksize, + (int) (ressize - residx * TOAST_MAX_CHUNK_SIZE), + residx, + toast_pointer.va_valueid, + RelationGetRelationName(toastrel)))); } else - elog(ERROR, "unexpected chunk number %d (out of range %d..%d) for toast value %u in %s", - residx, - 0, numchunks - 1, - toast_pointer.va_valueid, - RelationGetRelationName(toastrel)); + ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("unexpected chunk number %d (out of range %d..%d) for toast value %u in %s", + residx, + 0, numchunks - 1, + toast_pointer.va_valueid, + RelationGetRelationName(toastrel)))); /* * Copy the data into proper place in our result @@ -2010,10 +2014,11 @@ toast_fetch_datum(struct varlena *attr) * Final checks that we successfully fetched the datum */ if (nextidx != numchunks) - elog(ERROR, "missing chunk number %d for toast value %u in %s", - nextidx, - toast_pointer.va_valueid, - RelationGetRelationName(toastrel)); + ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), + errmsg("missing chunk number %d for toast value %u in %s", + nextidx, + toast_pointer.va_valueid, + RelationGetRelationName(toastrel)))); /* * End scan and close relations diff --git a/src/backend/access/nbtree/nbtinsert.c b/src/backend/access/nbtree/nbtinsert.c index 602f8849d4..002ccfad09 100644 --- a/src/backend/access/nbtree/nbtinsert.c +++ b/src/backend/access/nbtree/nbtinsert.c @@ -1568,10 +1568,11 @@ _bt_split(Relation rel, BTScanInsert itup_key, Buffer buf, Buffer cbuf, if (sopaque->btpo_prev != origpagenumber) { memset(rightpage, 0, BufferGetPageSize(rbuf)); - elog(ERROR, "right sibling's left-link doesn't match: " - "block %u links to %u instead of expected %u in index \"%s\"", - oopaque->btpo_next, sopaque->btpo_prev, origpagenumber, - RelationGetRelationName(rel)); + ereport(ERROR, (errcode(ERRCODE_INDEX_CORRUPTED), + errmsg("right sibling's left-link doesn't match: " + "block %u links to %u instead of expected %u in index \"%s\"", + oopaque->btpo_next, sopaque->btpo_prev, origpagenumber, + RelationGetRelationName(rel)))); } /* @@ -1827,8 +1828,10 @@ _bt_insert_parent(Relation rel, _bt_relbuf(rel, rbuf); if (pbuf == InvalidBuffer) - elog(ERROR, "failed to re-find parent key in index \"%s\" for split pages %u/%u", - RelationGetRelationName(rel), bknum, rbknum); + ereport(ERROR, + (errcode(ERRCODE_DATA_CORRUPTED), + errmsg(ERROR, "failed to re-find parent key in index \"%s\" for split pages %u/%u", + RelationGetRelationName(rel), bknum, rbknum))); /* Recursively update the parent */ _bt_insertonpg(rel, NULL, pbuf, buf, stack->bts_parent, diff --git a/src/backend/access/nbtree/nbtpage.c b/src/backend/access/nbtree/nbtpage.c index de4d4efc46..cda5c05fea 100644 --- a/src/backend/access/nbtree/nbtpage.c +++ b/src/backend/access/nbtree/nbtpage.c @@ -1233,8 +1233,10 @@ _bt_lock_branch_parent(Relation rel, BlockNumber child, BTStack stack, stack->bts_btentry = child; pbuf = _bt_getstackbuf(rel, stack); if (pbuf == InvalidBuffer) - elog(ERROR, "failed to re-find parent key in index \"%s\" for deletion target page %u", - RelationGetRelationName(rel), child); + ereport(ERROR, + (errcode(ERRCODE_INDEX_CORRUPTED), + errmsg(ERROR, "failed to re-find parent key in index \"%s\" for deletion target page %u", + RelationGetRelationName(rel), child))); parent = stack->bts_blkno; poffset = stack->bts_offset; @@ -1652,9 +1654,11 @@ _bt_mark_page_halfdead(Relation rel, Buffer leafbuf, BTStack stack) itemid = PageGetItemId(page, nextoffset); itup = (IndexTuple) PageGetItem(page, itemid); if (BTreeInnerTupleGetDownLink(itup) != rightsib) - elog(ERROR, "right sibling %u of block %u is not next child %u of block %u in index \"%s\"", - rightsib, target, BTreeInnerTupleGetDownLink(itup), - BufferGetBlockNumber(topparent), RelationGetRelationName(rel)); + ereport(ERROR, + (errcode(ERRCODE_INDEX_CORRUPTED), + errmsg(ERROR, "right sibling %u of block %u is not next child %u of block %u in index \"%s\"", + rightsib, target, BTreeInnerTupleGetDownLink(itup), + BufferGetBlockNumber(topparent), RelationGetRelationName(rel)))); /* * Any insert which would have gone on the leaf block will now go to its @@ -1919,8 +1923,10 @@ _bt_unlink_halfdead_page(Relation rel, Buffer leafbuf, bool *rightsib_empty) target, RelationGetRelationName(rel)); } if (opaque->btpo_prev != leftsib) - elog(ERROR, "left link changed unexpectedly in block %u of index \"%s\"", - target, RelationGetRelationName(rel)); + ereport(ERROR, + (errcode(ERRCODE_INDEX_CORRUPTED), + errmsg(ERROR, "left link changed unexpectedly in block %u of index \"%s\"", + target, RelationGetRelationName(rel)))); if (target == leafblkno) { @@ -1952,10 +1958,11 @@ _bt_unlink_halfdead_page(Relation rel, Buffer leafbuf, bool *rightsib_empty) page = BufferGetPage(rbuf); opaque = (BTPageOpaque) PageGetSpecialPointer(page); if (opaque->btpo_prev != target) - elog(ERROR, "right sibling's left-link doesn't match: " - "block %u links to %u instead of expected %u in index \"%s\"", - rightsib, opaque->btpo_prev, target, - RelationGetRelationName(rel)); + ereport(ERROR, (errcode(ERRCODE_INDEX_CORRUPTED), + errmsg("right sibling's left-link doesn't match: " + "block %u links to %u instead of expected %u in index \"%s\"", + rightsib, opaque->btpo_prev, target, + RelationGetRelationName(rel)))); rightsib_is_rightmost = P_RIGHTMOST(opaque); *rightsib_empty = (P_FIRSTDATAKEY(opaque) > PageGetMaxOffsetNumber(page)); diff --git a/src/backend/access/nbtree/nbtsearch.c b/src/backend/access/nbtree/nbtsearch.c index 1f809c24a1..0e148a31c5 100644 --- a/src/backend/access/nbtree/nbtsearch.c +++ b/src/backend/access/nbtree/nbtsearch.c @@ -2113,8 +2113,9 @@ _bt_get_endpoint(Relation rel, uint32 level, bool rightmost, if (opaque->btpo.level == level) break; if (opaque->btpo.level < level) - elog(ERROR, "btree level %u not found in index \"%s\"", - level, RelationGetRelationName(rel)); + ereport(ERROR, (errcode(ERRCODE_INDEX_CORRUPTED), + errmsg("btree level %u not found in index \"%s\"", + level, RelationGetRelationName(rel)))); /* Descend to leftmost or rightmost child page */ if (rightmost) -- 2.20.1 =
^ permalink raw reply [nested|flat] 12+ messages in thread

* Re: Logging corruption error codes
  2019-06-20 09:57 Logging corruption error codes Andrey Borodin <x4mmm@yandex-team.ru>
  2019-07-22 11:16 ` Re: Logging corruption error codes Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2019-07-25 10:45   ` Re: Logging corruption error codes Andrey Borodin <x4mmm@yandex-team.ru>
  2019-07-25 18:27     ` Re: Logging corruption error codes Peter Geoghegan <pg@bowt.ie>
  2019-07-31 06:07       ` Re: Logging corruption error codes Andrey Borodin <x4mmm@yandex-team.ru>
@ 2019-08-01 09:26         ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2019-08-01 09:42           ` Re: Logging corruption error codes Andrey Borodin <x4mmm@yandex-team.ru>
  0 siblings, 1 reply; 12+ messages in thread

From: Peter Eisentraut @ 2019-08-01 09:26 UTC (permalink / raw)
  To: Andrey Borodin <x4mmm@yandex-team.ru>; Peter Geoghegan <pg@bowt.ie>; +Cc: PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>; Анна Крханбарова <annkpx@yandex-team.ru>; Dmitriy Sarafannikov <dsarafan@yandex-team.ru>

On 2019-07-31 08:07, Andrey Borodin wrote:
> Please find attached patch v2: added a little more cases with corruption.

Committed with some adjustments.

Note that your patch didn't compile at all.  Please check that next time.

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services





^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Logging corruption error codes
  2019-06-20 09:57 Logging corruption error codes Andrey Borodin <x4mmm@yandex-team.ru>
  2019-07-22 11:16 ` Re: Logging corruption error codes Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2019-07-25 10:45   ` Re: Logging corruption error codes Andrey Borodin <x4mmm@yandex-team.ru>
  2019-07-25 18:27     ` Re: Logging corruption error codes Peter Geoghegan <pg@bowt.ie>
  2019-07-31 06:07       ` Re: Logging corruption error codes Andrey Borodin <x4mmm@yandex-team.ru>
  2019-08-01 09:26         ` Re: Logging corruption error codes Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
@ 2019-08-01 09:42           ` Andrey Borodin <x4mmm@yandex-team.ru>
  0 siblings, 0 replies; 12+ messages in thread

From: Andrey Borodin @ 2019-08-01 09:42 UTC (permalink / raw)
  To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: Peter Geoghegan <pg@bowt.ie>; PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>; Анна Крханбарова <annkpx@yandex-team.ru>; Dmitriy Sarafannikov <dsarafan@yandex-team.ru>



> 1 авг. 2019 г., в 14:26, Peter Eisentraut <peter.eisentraut@2ndquadrant.com> написал(а):
> 
> On 2019-07-31 08:07, Andrey Borodin wrote:
>> Please find attached patch v2: added a little more cases with corruption.
> 
> Committed with some adjustments.
Many thanks!

> 
> Note that your patch didn't compile at all.  Please check that next time.

Uh...sorry. I've tried to cope with formatting and finally check-world'ed without saved tab.
I see you adjusted ERRCODE_DATA_CORRUPTED -> ERRCODE_INDEX_CORRUPTED in one place, that is also my mistake.

Thank you!

Best regards, Andrey Borodin.




^ permalink  raw  reply  [nested|flat] 12+ messages in thread


end of thread, other threads:[~2019-08-01 09:42 UTC | newest]

Thread overview: 12+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-06-20 09:57 Logging corruption error codes Andrey Borodin <x4mmm@yandex-team.ru>
2019-06-20 17:09 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2019-06-21 10:22   ` Andrey Borodin <x4mmm@yandex-team.ru>
2019-06-24 01:59     ` Michael Paquier <michael@paquier.xyz>
2019-06-25 10:01       ` Andrey Borodin <x4mmm@yandex-team.ru>
2019-06-26 01:59         ` Michael Paquier <michael@paquier.xyz>
2019-07-22 11:16 ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2019-07-25 10:45   ` Andrey Borodin <x4mmm@yandex-team.ru>
2019-07-25 18:27     ` Peter Geoghegan <pg@bowt.ie>
2019-07-31 06:07       ` Andrey Borodin <x4mmm@yandex-team.ru>
2019-08-01 09:26         ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2019-08-01 09:42           ` Andrey Borodin <x4mmm@yandex-team.ru>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox