Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitef07221

Browse files
committed
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 goingto elog anyway, let md.c issue the elog messages itself. This allows bettererror 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 conditionexcept when InRecovery or zero_damaged_pages = true. (Hash indexes used torequire that behavior, but no more.) Also, enforce that mdwrite() is to beused for rewriting existing blocks while mdextend() is to be used forextending the relation EOF. This restriction lets us get rid of the oldad-hoc defense against creating huge files by an accidental reference toa bogus block number: we'll only create new segments in mdextend() notmdwrite() or mdread(). (Again, when InRecovery we allow it anyway, sincewe need to allow updates of blocks that were later truncated away.)Also, clean up the original makeshift patch for bug #2737: move theresponsibility for padding relation segments to full length into md.c.
1 parent990fea8 commitef07221

File tree

6 files changed

+402
-398
lines changed

6 files changed

+402
-398
lines changed

‎src/backend/access/hash/hashpage.c

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/hash/hashpage.c,v 1.61 2006/11/19 21:33:23 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/hash/hashpage.c,v 1.62 2007/01/03 18:11:01 tgl Exp $
1212
*
1313
* NOTES
1414
* Postgres hash pages look like ordinary relation pages. The opaque
@@ -533,10 +533,8 @@ _hash_expandtable(Relation rel, Buffer metabuf)
533533
*
534534
* This does not need to initialize the new bucket pages; we'll do that as
535535
* each one is used by _hash_expandtable(). But we have to extend the logical
536-
* EOF to the end of the splitpoint; otherwise the first overflow page
537-
* allocated beyond the splitpoint will represent a noncontiguous access,
538-
* which can confuse md.c (and will probably be forbidden by future changes
539-
* to md.c).
536+
* EOF to the end of the splitpoint; this keeps smgr's idea of the EOF in
537+
* sync with ours, so that overflow-page allocation works correctly.
540538
*
541539
* We do this by writing a page of zeroes at the end of the splitpoint range.
542540
* We expect that the filesystem will ensure that the intervening pages read
@@ -559,7 +557,6 @@ _hash_alloc_buckets(Relation rel, uint32 nblocks)
559557
{
560558
BlockNumberfirstblock;
561559
BlockNumberlastblock;
562-
BlockNumberendblock;
563560
charzerobuf[BLCKSZ];
564561

565562
/*
@@ -577,24 +574,9 @@ _hash_alloc_buckets(Relation rel, uint32 nblocks)
577574
if (lastblock<firstblock||lastblock==InvalidBlockNumber)
578575
returnInvalidBlockNumber;
579576

580-
/* Note: we assume RelationGetNumberOfBlocks did RelationOpenSmgr for us */
581-
582577
MemSet(zerobuf,0,sizeof(zerobuf));
583578

584-
/*
585-
* XXX If the extension results in creation of new segment files,
586-
* we have to make sure that each non-last file is correctly filled out to
587-
* RELSEG_SIZE blocks. This ought to be done inside mdextend, but
588-
* changing the smgr API seems best left for development cycle not late
589-
* beta. Temporary fix for bug #2737.
590-
*/
591-
#ifndefLET_OS_MANAGE_FILESIZE
592-
for (endblock=firstblock | (RELSEG_SIZE-1);
593-
endblock<lastblock;
594-
endblock+=RELSEG_SIZE)
595-
smgrextend(rel->rd_smgr,endblock,zerobuf,rel->rd_istemp);
596-
#endif
597-
579+
/* Note: we assume RelationGetNumberOfBlocks did RelationOpenSmgr for us */
598580
smgrextend(rel->rd_smgr,lastblock,zerobuf,rel->rd_istemp);
599581

600582
returnfirstblock;

‎src/backend/access/nbtree/nbtsort.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
* that is of no value (since other backends have no interest in them yet)
3737
* and it created locking problems for CHECKPOINT, because the upper-level
3838
* pages were held exclusive-locked for long periods. Now we just build
39-
* the pages in local memory and smgrwrite()them as we finish them. They
40-
* will need to be re-read into shared buffers on first use after the build
41-
* finishes.
39+
* the pages in local memory and smgrwrite or smgrextendthem as we finish
40+
*them. Theywill need to be re-read into shared buffers on first use after
41+
*the buildfinishes.
4242
*
4343
* Since the index will never be used unless it is completely built,
4444
* from a crash-recovery point of view there is no need to WAL-log the
@@ -57,7 +57,7 @@
5757
* Portions Copyright (c) 1994, Regents of the University of California
5858
*
5959
* IDENTIFICATION
60-
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsort.c,v 1.107 2006/10/04 00:29:49 momjian Exp $
60+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsort.c,v 1.108 2007/01/03 18:11:01 tgl Exp $
6161
*
6262
*-------------------------------------------------------------------------
6363
*/
@@ -309,20 +309,27 @@ _bt_blwritepage(BTWriteState *wstate, Page page, BlockNumber blkno)
309309
{
310310
if (!wstate->btws_zeropage)
311311
wstate->btws_zeropage= (Page)palloc0(BLCKSZ);
312-
smgrwrite(wstate->index->rd_smgr,wstate->btws_pages_written++,
313-
(char*)wstate->btws_zeropage,
314-
true);
312+
smgrextend(wstate->index->rd_smgr,wstate->btws_pages_written++,
313+
(char*)wstate->btws_zeropage,
314+
true);
315315
}
316316

317317
/*
318318
* Now write the page.We say isTemp = true even if it's not a temp
319319
* index, because there's no need for smgr to schedule an fsync for this
320320
* write; we'll do it ourselves before ending the build.
321321
*/
322-
smgrwrite(wstate->index->rd_smgr,blkno, (char*)page, true);
323-
324322
if (blkno==wstate->btws_pages_written)
323+
{
324+
/* extending the file... */
325+
smgrextend(wstate->index->rd_smgr,blkno, (char*)page, true);
325326
wstate->btws_pages_written++;
327+
}
328+
else
329+
{
330+
/* overwriting a block we zero-filled before */
331+
smgrwrite(wstate->index->rd_smgr,blkno, (char*)page, true);
332+
}
326333

327334
pfree(page);
328335
}

‎src/backend/commands/tablecmds.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.208 2006/12/30 21:21:53 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.209 2007/01/03 18:11:01 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -6083,7 +6083,7 @@ copy_relation_data(Relation rel, SMgrRelation dst)
60836083
* rel, because there's no need for smgr to schedule an fsync for this
60846084
* write; we'll do it ourselves below.
60856085
*/
6086-
smgrwrite(dst,blkno,buf, true);
6086+
smgrextend(dst,blkno,buf, true);
60876087
}
60886088

60896089
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp