mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
Clean up smgr.c/md.c APIs as per discussion a couple months ago. Instead of
having md.c return a success/failure boolean to smgr.c, which was just going to elog anyway, let md.c issue the elog messages itself. This allows better error reporting, particularly in cases such as "short read" or "short write" which Peter was complaining of. Also, remove the kluge of allowing mdread() to return zeroes from a read-beyond-EOF: this is now an error condition except when InRecovery or zero_damaged_pages = true. (Hash indexes used to require that behavior, but no more.) Also, enforce that mdwrite() is to be used for rewriting existing blocks while mdextend() is to be used for extending the relation EOF. This restriction lets us get rid of the old ad-hoc defense against creating huge files by an accidental reference to a bogus block number: we'll only create new segments in mdextend() not mdwrite() or mdread(). (Again, when InRecovery we allow it anyway, since we need to allow updates of blocks that were later truncated away.) Also, clean up the original makeshift patch for bug #2737: move the responsibility for padding relation segments to full length into md.c.
This commit is contained in:
@@ -36,9 +36,9 @@
|
||||
* that is of no value (since other backends have no interest in them yet)
|
||||
* and it created locking problems for CHECKPOINT, because the upper-level
|
||||
* pages were held exclusive-locked for long periods. Now we just build
|
||||
* the pages in local memory and smgrwrite() them as we finish them. They
|
||||
* will need to be re-read into shared buffers on first use after the build
|
||||
* finishes.
|
||||
* the pages in local memory and smgrwrite or smgrextend them as we finish
|
||||
* them. They will need to be re-read into shared buffers on first use after
|
||||
* the build finishes.
|
||||
*
|
||||
* Since the index will never be used unless it is completely built,
|
||||
* from a crash-recovery point of view there is no need to WAL-log the
|
||||
@@ -57,7 +57,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsort.c,v 1.107 2006/10/04 00:29:49 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsort.c,v 1.108 2007/01/03 18:11:01 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -309,9 +309,9 @@ _bt_blwritepage(BTWriteState *wstate, Page page, BlockNumber blkno)
|
||||
{
|
||||
if (!wstate->btws_zeropage)
|
||||
wstate->btws_zeropage = (Page) palloc0(BLCKSZ);
|
||||
smgrwrite(wstate->index->rd_smgr, wstate->btws_pages_written++,
|
||||
(char *) wstate->btws_zeropage,
|
||||
true);
|
||||
smgrextend(wstate->index->rd_smgr, wstate->btws_pages_written++,
|
||||
(char *) wstate->btws_zeropage,
|
||||
true);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -319,10 +319,17 @@ _bt_blwritepage(BTWriteState *wstate, Page page, BlockNumber blkno)
|
||||
* index, because there's no need for smgr to schedule an fsync for this
|
||||
* write; we'll do it ourselves before ending the build.
|
||||
*/
|
||||
smgrwrite(wstate->index->rd_smgr, blkno, (char *) page, true);
|
||||
|
||||
if (blkno == wstate->btws_pages_written)
|
||||
{
|
||||
/* extending the file... */
|
||||
smgrextend(wstate->index->rd_smgr, blkno, (char *) page, true);
|
||||
wstate->btws_pages_written++;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* overwriting a block we zero-filled before */
|
||||
smgrwrite(wstate->index->rd_smgr, blkno, (char *) page, true);
|
||||
}
|
||||
|
||||
pfree(page);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user