Re: trap instead of error on 32 TiB table

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Christoph Berg <christoph(dot)berg(at)credativ(dot)de>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: trap instead of error on 32 TiB table
Date: 2021-09-09 14:25:27
Message-ID: 3606135.1631197527@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Christoph Berg <christoph(dot)berg(at)credativ(dot)de> writes:
>> Can you provide a stack trace from that?

> #2 0x0000558b6223d46e in ExceptionalCondition (conditionName=conditionName(at)entry=0x558b623b2577 "tagPtr->blockNum != P_NEW",
> errorType=errorType(at)entry=0x558b6229b016 "FailedAssertion",
> fileName=fileName(at)entry=0x558b623b2598 "./build/../src/backend/storage/buffer/buf_table.c", lineNumber=lineNumber(at)entry=125)
> at ./build/../src/backend/utils/error/assert.c:67
> #3 0x0000558b620bafb9 in BufTableInsert (tagPtr=tagPtr(at)entry=0x7ffec8919330, hashcode=hashcode(at)entry=960067002, buf_id=<optimized out>)
> at ./build/../src/backend/storage/buffer/buf_table.c:125
> #4 0x0000558b620bf827 in BufferAlloc (foundPtr=0x7ffec891932b, strategy=0x0, blockNum=4294967295, forkNum=MAIN_FORKNUM,
> relpersistence=112 'p', smgr=0x558b62ed4b38) at ./build/../src/backend/storage/buffer/bufmgr.c:1234

Ah, thanks. I don't think it's unreasonable for BufTableInsert to contain
that assertion --- we shouldn't be trying to allocate a buffer for an
illegal block number.

The regular error comes from mdextend, but that is too late under this
worldview, because smgrextend expects to be given a zero-filled buffer
to write out. I think where we ought to be making the check is right
where ReadBuffer_common replaces P_NEW:

/* Substitute proper block number if caller asked for P_NEW */
if (isExtend)
+ {
blockNum = smgrnblocks(smgr, forkNum);
+ if (blockNum == InvalidBlockNumber)
+ ereport(ERROR,
+ (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
+ errmsg("cannot extend file \"%s\" beyond %u blocks",
+ relpath(smgr->smgr_rnode, forkNum),
+ InvalidBlockNumber)));
+ }

Having done that, the check in md.c could be reduced to an Assert,
although there's something to be said for leaving it as-is as an
extra layer of defense.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Masahiko Sawada 2021-09-09 14:32:54 Re: Skipping logical replication transactions on subscriber side
Previous Message Vik Fearing 2021-09-09 14:08:04 Re: Non-decimal integer literals