Re: new heapcheck contrib module

Mark Dilger <mark.dilger@enterprisedb.com>

From: Mark Dilger <mark.dilger@enterprisedb.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Robert Haas <robertmhaas@gmail.com>, Peter Geoghegan <pg@bowt.ie>, "Andrey M. Borodin" <x4mmm@yandex-team.ru>, Stephen Frost <sfrost@snowman.net>, Michael Paquier <michael@paquier.xyz>, Amul Sul <sulamul@gmail.com>, Dilip Kumar <dilipbalaut@gmail.com>, Andres Freund <andres@anarazel.de>, PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2020-10-22T20:31:04Z
Lists: pgsql-hackers

> On Oct 22, 2020, at 1:23 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> 
> ... btw, having now looked more closely at get_xid_status(), I wonder
> how come there aren't more compilers bitching about it, because it
> is very very obviously broken.  In particular, the case of
> requesting status for an xid that is BootstrapTransactionId or
> FrozenTransactionId *will* fall through to perform
> FullTransactionIdPrecedesOrEquals with an uninitialized fxid.
> 
> The fact that most compilers seem to fail to notice that is quite scary.
> I suppose it has something to do with FullTransactionId being a struct,
> which makes me wonder if that choice was quite as wise as we thought.
> 
> Meanwhile, so far as this code goes, I wonder why you don't just change it
> to always set that value, ie
> 
> 	XidBoundsViolation result;
> 	FullTransactionId fxid;
> 	FullTransactionId clog_horizon;
> 
> +	fxid = FullTransactionIdFromXidAndCtx(xid, ctx);
> +
> 	/* Quick check for special xids */
> 	if (!TransactionIdIsValid(xid))
> 		result = XID_INVALID;
> 	else if (xid == BootstrapTransactionId || xid == FrozenTransactionId)
> 		result = XID_BOUNDS_OK;
> 	else
> 	{
> 		/* Check if the xid is within bounds */
> -		fxid = FullTransactionIdFromXidAndCtx(xid, ctx);
> 		if (!fxid_in_cached_range(fxid, ctx))
> 		{

Yeah, I reached the same conclusion before submitting the fix upthread.  I structured it a bit differently, but I believe fxid will now always get set before being used, though sometimes the function returns before doing either.

I had the same thought about compilers not catching that, too.

—
Mark Dilger
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company






Commits

  1. Add pg_amcheck, a CLI for contrib/amcheck.

  2. Refactor and generalize the ParallelSlot machinery.

  3. Generalize parallel slot result handling.

  4. Move some code from src/bin/scripts to src/fe_utils to permit reuse.

  5. Factor pattern-construction logic out of processSQLNamePattern.

  6. Doc: clean up verify_heapam() documentation.

  7. Fix more portability issues in new amcheck code.

  8. Fix portability issues in new amcheck test.

  9. Try to avoid a compiler warning about using fxid uninitialized.

  10. Extend amcheck to check heap pages.

  11. Adjust walsender usage of xlogreader, simplify APIs

  12. Improve checking of child pages in contrib/amcheck.

  13. Sanitize line pointers within contrib/amcheck.

  14. Fix possible sorting error when aborting use of abbreviated keys.