Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3f0e808

Browse files
committed
Introduce the concept of relation forks. An smgr relation can now consist
of multiple forks, and each fork can be created and grown separately. The bulk of this patch is about changing the smgr API to include an extra ForkNumber argument in every smgr function. Also, smgrscheduleunlink and smgrdounlink no longer implicitly call smgrclose, because other forks might still exist after unlinking one. The callers of those functions have been modified to call smgrclose instead. This patch in itself doesn't have any user-visible effect, but provides the infrastructure needed for upcoming patches. The additional forks envisioned are a rewritten FSM implementation that doesn't rely on a fixed-size shared memory block, and a visibility map to allow skipping portions of a table in VACUUM that have no dead tuples.
1 parent eca1388 commit 3f0e808

File tree

31 files changed

+733
-446
lines changed

31 files changed

+733
-446
lines changed

src/backend/access/hash/hashpage.c

+4-4
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.75 2008/05/12 00:00:44 alvherre Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/hash/hashpage.c,v 1.76 2008/08/11 11:05:10 heikki Exp $
1212
*
1313
* NOTES
1414
* Postgres hash pages look like ordinary relation pages. The opaque
@@ -158,7 +158,7 @@ _hash_getinitbuf(Relation rel, BlockNumber blkno)
158158
if (blkno == P_NEW)
159159
elog(ERROR, "hash AM does not use P_NEW");
160160

161-
buf = ReadOrZeroBuffer(rel, blkno);
161+
buf = ReadOrZeroBuffer(rel, MAIN_FORKNUM, blkno);
162162

163163
LockBuffer(buf, HASH_WRITE);
164164

@@ -203,7 +203,7 @@ _hash_getnewbuf(Relation rel, BlockNumber blkno)
203203
BufferGetBlockNumber(buf), blkno);
204204
}
205205
else
206-
buf = ReadOrZeroBuffer(rel, blkno);
206+
buf = ReadOrZeroBuffer(rel, MAIN_FORKNUM, blkno);
207207

208208
LockBuffer(buf, HASH_WRITE);
209209

@@ -737,7 +737,7 @@ _hash_alloc_buckets(Relation rel, BlockNumber firstblock, uint32 nblocks)
737737
MemSet(zerobuf, 0, sizeof(zerobuf));
738738

739739
RelationOpenSmgr(rel);
740-
smgrextend(rel->rd_smgr, lastblock, zerobuf, rel->rd_istemp);
740+
smgrextend(rel->rd_smgr, MAIN_FORKNUM, lastblock, zerobuf, rel->rd_istemp);
741741

742742
return true;
743743
}

src/backend/access/heap/heapam.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.261 2008/07/13 20:45:47 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.262 2008/08/11 11:05:10 heikki Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -3906,7 +3906,8 @@ log_heap_move(Relation reln, Buffer oldbuf, ItemPointerData from,
39063906
* not do anything that assumes we are touching a heap.
39073907
*/
39083908
XLogRecPtr
3909-
log_newpage(RelFileNode *rnode, BlockNumber blkno, Page page)
3909+
log_newpage(RelFileNode *rnode, ForkNumber forkNum, BlockNumber blkno,
3910+
Page page)
39103911
{
39113912
xl_heap_newpage xlrec;
39123913
XLogRecPtr recptr;
@@ -3916,6 +3917,7 @@ log_newpage(RelFileNode *rnode, BlockNumber blkno, Page page)
39163917
START_CRIT_SECTION();
39173918

39183919
xlrec.node = *rnode;
3920+
xlrec.forknum = forkNum;
39193921
xlrec.blkno = blkno;
39203922

39213923
rdata[0].data = (char *) &xlrec;
@@ -4714,7 +4716,7 @@ heap_sync(Relation rel)
47144716
/* main heap */
47154717
FlushRelationBuffers(rel);
47164718
/* FlushRelationBuffers will have opened rd_smgr */
4717-
smgrimmedsync(rel->rd_smgr);
4719+
smgrimmedsync(rel->rd_smgr, MAIN_FORKNUM);
47184720

47194721
/* toast heap, if any */
47204722
if (OidIsValid(rel->rd_rel->reltoastrelid))
@@ -4723,7 +4725,7 @@ heap_sync(Relation rel)
47234725

47244726
toastrel = heap_open(rel->rd_rel->reltoastrelid, AccessShareLock);
47254727
FlushRelationBuffers(toastrel);
4726-
smgrimmedsync(toastrel->rd_smgr);
4728+
smgrimmedsync(toastrel->rd_smgr, MAIN_FORKNUM);
47274729
heap_close(toastrel, AccessShareLock);
47284730
}
47294731
}

src/backend/access/heap/rewriteheap.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
* Portions Copyright (c) 1994-5, Regents of the University of California
9797
*
9898
* IDENTIFICATION
99-
* $PostgreSQL: pgsql/src/backend/access/heap/rewriteheap.c,v 1.14 2008/06/19 00:46:03 alvherre Exp $
99+
* $PostgreSQL: pgsql/src/backend/access/heap/rewriteheap.c,v 1.15 2008/08/11 11:05:10 heikki Exp $
100100
*
101101
*-------------------------------------------------------------------------
102102
*/
@@ -270,10 +270,11 @@ end_heap_rewrite(RewriteState state)
270270
{
271271
if (state->rs_use_wal)
272272
log_newpage(&state->rs_new_rel->rd_node,
273+
MAIN_FORKNUM,
273274
state->rs_blockno,
274275
state->rs_buffer);
275276
RelationOpenSmgr(state->rs_new_rel);
276-
smgrextend(state->rs_new_rel->rd_smgr, state->rs_blockno,
277+
smgrextend(state->rs_new_rel->rd_smgr, MAIN_FORKNUM, state->rs_blockno,
277278
(char *) state->rs_buffer, true);
278279
}
279280

@@ -606,6 +607,7 @@ raw_heap_insert(RewriteState state, HeapTuple tup)
606607
/* XLOG stuff */
607608
if (state->rs_use_wal)
608609
log_newpage(&state->rs_new_rel->rd_node,
610+
MAIN_FORKNUM,
609611
state->rs_blockno,
610612
page);
611613

@@ -616,8 +618,8 @@ raw_heap_insert(RewriteState state, HeapTuple tup)
616618
* end_heap_rewrite.
617619
*/
618620
RelationOpenSmgr(state->rs_new_rel);
619-
smgrextend(state->rs_new_rel->rd_smgr, state->rs_blockno,
620-
(char *) page, true);
621+
smgrextend(state->rs_new_rel->rd_smgr, MAIN_FORKNUM,
622+
state->rs_blockno, (char *) page, true);
621623

622624
state->rs_blockno++;
623625
state->rs_buffer_valid = false;

src/backend/access/nbtree/nbtsort.c

+9-6
Original file line numberDiff line numberDiff line change
@@ -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.116 2008/06/19 00:46:03 alvherre Exp $
60+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsort.c,v 1.117 2008/08/11 11:05:10 heikki Exp $
6161
*
6262
*-------------------------------------------------------------------------
6363
*/
@@ -267,7 +267,7 @@ _bt_blwritepage(BTWriteState *wstate, Page page, BlockNumber blkno)
267267
if (wstate->btws_use_wal)
268268
{
269269
/* We use the heap NEWPAGE record type for this */
270-
log_newpage(&wstate->index->rd_node, blkno, page);
270+
log_newpage(&wstate->index->rd_node, MAIN_FORKNUM, blkno, page);
271271
}
272272
else
273273
{
@@ -286,7 +286,8 @@ _bt_blwritepage(BTWriteState *wstate, Page page, BlockNumber blkno)
286286
{
287287
if (!wstate->btws_zeropage)
288288
wstate->btws_zeropage = (Page) palloc0(BLCKSZ);
289-
smgrextend(wstate->index->rd_smgr, wstate->btws_pages_written++,
289+
smgrextend(wstate->index->rd_smgr, MAIN_FORKNUM,
290+
wstate->btws_pages_written++,
290291
(char *) wstate->btws_zeropage,
291292
true);
292293
}
@@ -299,13 +300,15 @@ _bt_blwritepage(BTWriteState *wstate, Page page, BlockNumber blkno)
299300
if (blkno == wstate->btws_pages_written)
300301
{
301302
/* extending the file... */
302-
smgrextend(wstate->index->rd_smgr, blkno, (char *) page, true);
303+
smgrextend(wstate->index->rd_smgr, MAIN_FORKNUM, blkno,
304+
(char *) page, true);
303305
wstate->btws_pages_written++;
304306
}
305307
else
306308
{
307309
/* overwriting a block we zero-filled before */
308-
smgrwrite(wstate->index->rd_smgr, blkno, (char *) page, true);
310+
smgrwrite(wstate->index->rd_smgr, MAIN_FORKNUM, blkno,
311+
(char *) page, true);
309312
}
310313

311314
pfree(page);
@@ -809,6 +812,6 @@ _bt_load(BTWriteState *wstate, BTSpool *btspool, BTSpool *btspool2)
809812
if (!wstate->index->rd_istemp)
810813
{
811814
RelationOpenSmgr(wstate->index);
812-
smgrimmedsync(wstate->index->rd_smgr);
815+
smgrimmedsync(wstate->index->rd_smgr, MAIN_FORKNUM);
813816
}
814817
}

src/backend/access/transam/twophase.c

+31-23
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/access/transam/twophase.c,v 1.44 2008/08/01 13:16:08 alvherre Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/twophase.c,v 1.45 2008/08/11 11:05:10 heikki Exp $
1111
*
1212
* NOTES
1313
* Each global transaction is associated with a global transaction
@@ -141,12 +141,12 @@ static void RecordTransactionCommitPrepared(TransactionId xid,
141141
int nchildren,
142142
TransactionId *children,
143143
int nrels,
144-
RelFileNode *rels);
144+
RelFileFork *rels);
145145
static void RecordTransactionAbortPrepared(TransactionId xid,
146146
int nchildren,
147147
TransactionId *children,
148148
int nrels,
149-
RelFileNode *rels);
149+
RelFileFork *rels);
150150
static void ProcessRecords(char *bufptr, TransactionId xid,
151151
const TwoPhaseCallback callbacks[]);
152152

@@ -694,8 +694,8 @@ TwoPhaseGetDummyProc(TransactionId xid)
694694
*
695695
* 1. TwoPhaseFileHeader
696696
* 2. TransactionId[] (subtransactions)
697-
* 3. RelFileNode[] (files to be deleted at commit)
698-
* 4. RelFileNode[] (files to be deleted at abort)
697+
* 3. RelFileFork[] (files to be deleted at commit)
698+
* 4. RelFileFork[] (files to be deleted at abort)
699699
* 5. TwoPhaseRecordOnDisk
700700
* 6. ...
701701
* 7. TwoPhaseRecordOnDisk (end sentinel, rmid == TWOPHASE_RM_END_ID)
@@ -793,8 +793,8 @@ StartPrepare(GlobalTransaction gxact)
793793
TransactionId xid = gxact->proc.xid;
794794
TwoPhaseFileHeader hdr;
795795
TransactionId *children;
796-
RelFileNode *commitrels;
797-
RelFileNode *abortrels;
796+
RelFileFork *commitrels;
797+
RelFileFork *abortrels;
798798

799799
/* Initialize linked list */
800800
records.head = palloc0(sizeof(XLogRecData));
@@ -832,12 +832,12 @@ StartPrepare(GlobalTransaction gxact)
832832
}
833833
if (hdr.ncommitrels > 0)
834834
{
835-
save_state_data(commitrels, hdr.ncommitrels * sizeof(RelFileNode));
835+
save_state_data(commitrels, hdr.ncommitrels * sizeof(RelFileFork));
836836
pfree(commitrels);
837837
}
838838
if (hdr.nabortrels > 0)
839839
{
840-
save_state_data(abortrels, hdr.nabortrels * sizeof(RelFileNode));
840+
save_state_data(abortrels, hdr.nabortrels * sizeof(RelFileFork));
841841
pfree(abortrels);
842842
}
843843
}
@@ -1140,8 +1140,8 @@ FinishPreparedTransaction(const char *gid, bool isCommit)
11401140
TwoPhaseFileHeader *hdr;
11411141
TransactionId latestXid;
11421142
TransactionId *children;
1143-
RelFileNode *commitrels;
1144-
RelFileNode *abortrels;
1143+
RelFileFork *commitrels;
1144+
RelFileFork *abortrels;
11451145
int i;
11461146

11471147
/*
@@ -1169,10 +1169,10 @@ FinishPreparedTransaction(const char *gid, bool isCommit)
11691169
bufptr = buf + MAXALIGN(sizeof(TwoPhaseFileHeader));
11701170
children = (TransactionId *) bufptr;
11711171
bufptr += MAXALIGN(hdr->nsubxacts * sizeof(TransactionId));
1172-
commitrels = (RelFileNode *) bufptr;
1173-
bufptr += MAXALIGN(hdr->ncommitrels * sizeof(RelFileNode));
1174-
abortrels = (RelFileNode *) bufptr;
1175-
bufptr += MAXALIGN(hdr->nabortrels * sizeof(RelFileNode));
1172+
commitrels = (RelFileFork *) bufptr;
1173+
bufptr += MAXALIGN(hdr->ncommitrels * sizeof(RelFileFork));
1174+
abortrels = (RelFileFork *) bufptr;
1175+
bufptr += MAXALIGN(hdr->nabortrels * sizeof(RelFileFork));
11761176

11771177
/* compute latestXid among all children */
11781178
latestXid = TransactionIdLatest(xid, hdr->nsubxacts, children);
@@ -1215,12 +1215,20 @@ FinishPreparedTransaction(const char *gid, bool isCommit)
12151215
if (isCommit)
12161216
{
12171217
for (i = 0; i < hdr->ncommitrels; i++)
1218-
smgrdounlink(smgropen(commitrels[i]), false, false);
1218+
{
1219+
SMgrRelation srel = smgropen(commitrels[i].rnode);
1220+
smgrdounlink(srel, commitrels[i].forknum, false, false);
1221+
smgrclose(srel);
1222+
}
12191223
}
12201224
else
12211225
{
12221226
for (i = 0; i < hdr->nabortrels; i++)
1223-
smgrdounlink(smgropen(abortrels[i]), false, false);
1227+
{
1228+
SMgrRelation srel = smgropen(abortrels[i].rnode);
1229+
smgrdounlink(srel, abortrels[i].forknum, false, false);
1230+
smgrclose(srel);
1231+
}
12241232
}
12251233

12261234
/* And now do the callbacks */
@@ -1631,8 +1639,8 @@ RecoverPreparedTransactions(void)
16311639
bufptr = buf + MAXALIGN(sizeof(TwoPhaseFileHeader));
16321640
subxids = (TransactionId *) bufptr;
16331641
bufptr += MAXALIGN(hdr->nsubxacts * sizeof(TransactionId));
1634-
bufptr += MAXALIGN(hdr->ncommitrels * sizeof(RelFileNode));
1635-
bufptr += MAXALIGN(hdr->nabortrels * sizeof(RelFileNode));
1642+
bufptr += MAXALIGN(hdr->ncommitrels * sizeof(RelFileFork));
1643+
bufptr += MAXALIGN(hdr->nabortrels * sizeof(RelFileFork));
16361644

16371645
/*
16381646
* Reconstruct subtrans state for the transaction --- needed
@@ -1685,7 +1693,7 @@ RecordTransactionCommitPrepared(TransactionId xid,
16851693
int nchildren,
16861694
TransactionId *children,
16871695
int nrels,
1688-
RelFileNode *rels)
1696+
RelFileFork *rels)
16891697
{
16901698
XLogRecData rdata[3];
16911699
int lastrdata = 0;
@@ -1710,7 +1718,7 @@ RecordTransactionCommitPrepared(TransactionId xid,
17101718
{
17111719
rdata[0].next = &(rdata[1]);
17121720
rdata[1].data = (char *) rels;
1713-
rdata[1].len = nrels * sizeof(RelFileNode);
1721+
rdata[1].len = nrels * sizeof(RelFileFork);
17141722
rdata[1].buffer = InvalidBuffer;
17151723
lastrdata = 1;
17161724
}
@@ -1760,7 +1768,7 @@ RecordTransactionAbortPrepared(TransactionId xid,
17601768
int nchildren,
17611769
TransactionId *children,
17621770
int nrels,
1763-
RelFileNode *rels)
1771+
RelFileFork *rels)
17641772
{
17651773
XLogRecData rdata[3];
17661774
int lastrdata = 0;
@@ -1790,7 +1798,7 @@ RecordTransactionAbortPrepared(TransactionId xid,
17901798
{
17911799
rdata[0].next = &(rdata[1]);
17921800
rdata[1].data = (char *) rels;
1793-
rdata[1].len = nrels * sizeof(RelFileNode);
1801+
rdata[1].len = nrels * sizeof(RelFileFork);
17941802
rdata[1].buffer = InvalidBuffer;
17951803
lastrdata = 1;
17961804
}

0 commit comments

Comments
 (0)