src/backend/access/hash/hashpage.c
Buffer
_hash_getnewbuf(Relation rel, BlockNumber blkno, ForkNumber forkNum)
{
	BlockNumber nblocks = RelationGetNumberOfBlocksInFork(rel, forkNum);
	Buffer		buf;

	if (blkno == P_NEW)
		elog(ERROR, "hash AM does not use P_NEW");
	if (blkno > nblocks)
		elog(ERROR, "access to noncontiguous page in hash index \"%s\"",
			 RelationGetRelationName(rel));

	/* smgr insists we use P_NEW to extend the relation */
	if (blkno == nblocks)
	{
		buf = ReadBufferExtended(rel, forkNum, P_NEW, RBM_NORMAL, NULL);
		if (BufferGetBlockNumber(buf) != blkno)
			elog(ERROR, "unexpected hash relation size: %u, should be %u",
				 BufferGetBlockNumber(buf), blkno);
		LockBuffer(buf, HASH_WRITE);
	}
	else
	{
		buf = ReadBufferExtended(rel, forkNum, blkno, RBM_ZERO_AND_LOCK,
								 NULL);
	}

	/* ref count and lock type are correct */

	/* initialize the page */
	_hash_pageinit(BufferGetPage(buf), BufferGetPageSize(buf));

	return buf;
}
/*
 *	_hash_getnewbuf() -- Get a new page at the end of the index.
 *
 *		This has the same API as _hash_getinitbuf, except that we are adding
 *		a page to the index, and hence expect the page to be past the
 *		logical EOF.  (However, we have to support the case where it isn't,
 *		since a prior try might have crashed after extending the filesystem
 *		EOF but before updating the metapage to reflect the added page.)
 *
 *		It is caller's responsibility to ensure that only one process can
 *		extend the index at a time.  In practice, this function is called
 *		only while holding write lock on the metapage, because adding a page
 *		is always associated with an update of metapage data.
 */
- Get a new page at the end of the index.
This has the same API as _hash_getinitbuf, except that we are adding
a page to the index, and hence expect the page to be past the
logical EOF.  (However, we have to support the case where it isn't,
since a prior try might have crashed after extending the filesystem
EOF but before updating the metapage to reflect the added page.)

It is caller's responsibility to ensure that only one process can
extend the index at a time.  In practice, this function is called
only while holding write lock on the metapage, because adding a page
is always associated with an update of metapage data.
- Get a new page at the end of the index . This has the same API as _hash_getinitbuf except that we are adding a page to the index and hence expect the page to be past the logical EOF . ( However we have to support the case where it isn ' t since a prior try might have crashed after extending the filesystem EOF but before updating the metapage to reflect the added page . ) It is caller ' s responsibility to ensure that only one process can extend the index at a time . In practice this function is called only while holding write lock on the metapage because adding a page is always associated with an update of metapage data .
Buffer
_hash_getnewbuf(Relation rel, BlockNumber blkno, ForkNumber forkNum)
{
	BlockNumber nblocks = RelationGetNumberOfBlocksInFork(rel, forkNum);
	Buffer		buf;
	if (blkno == P_NEW)
		elog(ERROR, "hash AM does not use P_NEW");
	if (blkno > nblocks)
		elog(ERROR, "access to noncontiguous page in hash index \"%s\"",
			 RelationGetRelationName(rel));
	if (blkno == nblocks)
	{
		buf = ReadBufferExtended(rel, forkNum, P_NEW, RBM_NORMAL, NULL);
		if (BufferGetBlockNumber(buf) != blkno)
			elog(ERROR, "unexpected hash relation size: %u, should be %u",
				 BufferGetBlockNumber(buf), blkno);
		LockBuffer(buf, HASH_WRITE);
	}
	else
	{
		buf = ReadBufferExtended(rel, forkNum, blkno, RBM_ZERO_AND_LOCK,
								 NULL);
	}
	_hash_pageinit(BufferGetPage(buf), BufferGetPageSize(buf));
	return buf;
}
Buffer _hash_getnewbuf ( Relation rel , BlockNumber blkno , ForkNumber forkNum ) { BlockNumber nblocks = RelationGetNumberOfBlocksInFork ( rel , forkNum ) ; Buffer buf ; if ( blkno == P_NEW ) elog ( ERROR , " " ) ; if ( blkno > nblocks ) elog ( ERROR , " \" \" " , RelationGetRelationName ( rel ) ) ; if ( blkno == nblocks ) { buf = ReadBufferExtended ( rel , forkNum , P_NEW , RBM_NORMAL , NULL ) ; if ( BufferGetBlockNumber ( buf ) != blkno ) elog ( ERROR , " " , BufferGetBlockNumber ( buf ) , blkno ) ; LockBuffer ( buf , HASH_WRITE ) ; } else { buf = ReadBufferExtended ( rel , forkNum , blkno , RBM_ZERO_AND_LOCK , NULL ) ; } _hash_pageinit ( BufferGetPage ( buf ) , BufferGetPageSize ( buf ) ) ; return buf ; }
_hash_getnewbuf() -- Get a new page at the end of the index.
_hash_getnewbuf () -- Get a new page at the end of the index .
/* smgr insists we use P_NEW to extend the relation */ /* ref count and lock type are correct */ /* initialize the page */