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

Commit87bd956

Browse files
committed
Restructure smgr API as per recent proposal. smgr no longer depends on
the relcache, and so the notion of 'blind write' is gone. This shouldimprove efficiency in bgwriter and background checkpoint processes.Internal restructuring in md.c to remove the not-very-useful array ofMdfdVec objects --- might as well just use pointers.Also remove the long-dead 'persistent main memory' storage manager (mm.c),since it seems quite unlikely to ever get resurrected.
1 parentf06e795 commit87bd956

File tree

37 files changed

+923
-1766
lines changed

37 files changed

+923
-1766
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1994, Regents of the University of California
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtree.c,v 1.111 2004/02/06 19:36:17 wieck Exp $
15+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtree.c,v 1.112 2004/02/10 01:55:24 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -821,7 +821,9 @@ btvacuumcleanup(PG_FUNCTION_ARGS)
821821
/*
822822
* Do the physical truncation.
823823
*/
824-
new_pages=smgrtruncate(DEFAULT_SMGR,rel,new_pages);
824+
if (rel->rd_smgr==NULL)
825+
rel->rd_smgr=smgropen(rel->rd_node);
826+
new_pages=smgrtruncate(rel->rd_smgr,new_pages);
825827
rel->rd_nblocks=new_pages;/* update relcache
826828
* immediately */
827829
rel->rd_targblock=InvalidBlockNumber;

‎src/backend/access/transam/slru.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.10 2004/01/28 21:02:39 tgl Exp $
9+
* $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.11 2004/02/10 01:55:24 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -19,6 +19,7 @@
1919
#include<unistd.h>
2020

2121
#include"access/slru.h"
22+
#include"storage/fd.h"
2223
#include"storage/lwlock.h"
2324
#include"miscadmin.h"
2425

‎src/backend/access/transam/xact.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.161 2004/01/26 22:51:55 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.162 2004/02/10 01:55:24 tgl Exp $
1212
*
1313
* NOTES
1414
*Transaction aborts can now occur two ways:
@@ -159,6 +159,7 @@
159159
#include"executor/spi.h"
160160
#include"libpq/be-fsstubs.h"
161161
#include"miscadmin.h"
162+
#include"storage/fd.h"
162163
#include"storage/proc.h"
163164
#include"storage/sinval.h"
164165
#include"storage/smgr.h"

‎src/backend/access/transam/xlog.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.133 2004/01/26 22:35:31 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.134 2004/02/10 01:55:24 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -30,6 +30,7 @@
3030
#include"catalog/catversion.h"
3131
#include"catalog/pg_control.h"
3232
#include"storage/bufpage.h"
33+
#include"storage/fd.h"
3334
#include"storage/lwlock.h"
3435
#include"storage/pmsignal.h"
3536
#include"storage/proc.h"
@@ -3126,7 +3127,6 @@ ShutdownXLOG(int code, Datum arg)
31263127
MyXactMadeTempRelUpdate= false;
31273128

31283129
CritSectionCount++;
3129-
CreateDummyCaches();
31303130
CreateCheckPoint(true, true);
31313131
ShutdownCLOG();
31323132
CritSectionCount--;

‎src/backend/access/transam/xlogutils.c

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/backend/access/transam/xlogutils.c,v 1.28 2003/12/14 00:34:47 neilc Exp $
9+
* $PostgreSQL: pgsql/src/backend/access/transam/xlogutils.c,v 1.29 2004/02/10 01:55:24 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -261,14 +261,12 @@ _xl_remove_hash_entry(XLogRelDesc *rdesc)
261261
if (hentry==NULL)
262262
elog(PANIC,"_xl_remove_hash_entry: file was not found in cache");
263263

264-
if (rdesc->reldata.rd_fd >=0)
265-
smgrclose(DEFAULT_SMGR,&(rdesc->reldata));
264+
if (rdesc->reldata.rd_smgr!=NULL)
265+
smgrclose(rdesc->reldata.rd_smgr);
266266

267267
memset(rdesc,0,sizeof(XLogRelDesc));
268268
memset(tpgc,0,sizeof(FormData_pg_class));
269269
rdesc->reldata.rd_rel=tpgc;
270-
271-
return;
272270
}
273271

274272
staticXLogRelDesc*
@@ -296,7 +294,6 @@ _xl_new_reldesc(void)
296294
void
297295
XLogInitRelationCache(void)
298296
{
299-
CreateDummyCaches();
300297
_xl_init_rel_cache();
301298
}
302299

@@ -306,8 +303,6 @@ XLogCloseRelationCache(void)
306303
HASH_SEQ_STATUSstatus;
307304
XLogRelCacheEntry*hentry;
308305

309-
DestroyDummyCaches();
310-
311306
if (!_xlrelarr)
312307
return;
313308

@@ -347,11 +342,18 @@ XLogOpenRelation(bool redo, RmgrId rmid, RelFileNode rnode)
347342

348343
sprintf(RelationGetRelationName(&(res->reldata)),"%u",rnode.relNode);
349344

350-
/* unexisting DB id */
351-
res->reldata.rd_lockInfo.lockRelId.dbId=RecoveryDb;
352-
res->reldata.rd_lockInfo.lockRelId.relId=rnode.relNode;
353345
res->reldata.rd_node=rnode;
354346

347+
/*
348+
* We set up the lockRelId in case anything tries to lock the dummy
349+
* relation. Note that this is fairly bogus since relNode may be
350+
* different from the relation's OID. It shouldn't really matter
351+
* though, since we are presumably running by ourselves and can't
352+
* have any lock conflicts ...
353+
*/
354+
res->reldata.rd_lockInfo.lockRelId.dbId=rnode.tblNode;
355+
res->reldata.rd_lockInfo.lockRelId.relId=rnode.relNode;
356+
355357
hentry= (XLogRelCacheEntry*)
356358
hash_search(_xlrelcache, (void*)&rnode,HASH_ENTER,&found);
357359

@@ -364,18 +366,23 @@ XLogOpenRelation(bool redo, RmgrId rmid, RelFileNode rnode)
364366
hentry->rdesc=res;
365367

366368
res->reldata.rd_targblock=InvalidBlockNumber;
367-
res->reldata.rd_fd=-1;
368-
res->reldata.rd_fd=smgropen(DEFAULT_SMGR,&(res->reldata),
369-
true/* allow failure */ );
369+
res->reldata.rd_smgr=smgropen(res->reldata.rd_node);
370+
/*
371+
* Create the target file if it doesn't already exist. This lets
372+
* us cope if the replay sequence contains writes to a relation
373+
* that is later deleted. (The original coding of this routine
374+
* would instead return NULL, causing the writes to be suppressed.
375+
* But that seems like it risks losing valuable data if the filesystem
376+
* loses an inode during a crash. Better to write the data until we
377+
* are actually told to delete the file.)
378+
*/
379+
smgrcreate(res->reldata.rd_smgr,res->reldata.rd_istemp, true);
370380
}
371381

372382
res->moreRecently=&(_xlrelarr[0]);
373383
res->lessRecently=_xlrelarr[0].lessRecently;
374384
_xlrelarr[0].lessRecently=res;
375385
res->lessRecently->moreRecently=res;
376386

377-
if (res->reldata.rd_fd<0)/* file doesn't exist */
378-
return (NULL);
379-
380387
return (&(res->reldata));
381388
}

‎src/backend/bootstrap/bootstrap.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.175 2004/01/07 18:56:25 neilc Exp $
11+
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.176 2004/02/10 01:55:24 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -465,14 +465,12 @@ BootstrapMain(int argc, char *argv[])
465465
break;
466466

467467
caseBS_XLOG_CHECKPOINT:
468-
CreateDummyCaches();
469468
CreateCheckPoint(false, false);
470469
SetSavedRedoRecPtr();/* pass redo ptr back to
471470
* postmaster */
472471
proc_exit(0);/* done */
473472

474473
caseBS_XLOG_BGWRITER:
475-
CreateDummyCaches();
476474
BufferBackgroundWriter();
477475
proc_exit(0);/* done */
478476

‎src/backend/catalog/heap.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.257 2003/12/28 21:57:36 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.258 2004/02/10 01:55:24 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -298,9 +298,9 @@ heap_create(const char *relname,
298298
void
299299
heap_storage_create(Relationrel)
300300
{
301-
Assert(rel->rd_fd<0);
302-
rel->rd_fd=smgrcreate(DEFAULT_SMGR,rel);
303-
Assert(rel->rd_fd >=0);
301+
Assert(rel->rd_smgr==NULL);
302+
rel->rd_smgr=smgropen(rel->rd_node);
303+
smgrcreate(rel->rd_smgr,rel->rd_istemp, false);
304304
}
305305

306306
/* ----------------------------------------------------------------
@@ -1210,7 +1210,12 @@ heap_drop_with_catalog(Oid rid)
12101210
*/
12111211
if (rel->rd_rel->relkind!=RELKIND_VIEW&&
12121212
rel->rd_rel->relkind!=RELKIND_COMPOSITE_TYPE)
1213-
smgrunlink(DEFAULT_SMGR,rel);
1213+
{
1214+
if (rel->rd_smgr==NULL)
1215+
rel->rd_smgr=smgropen(rel->rd_node);
1216+
smgrscheduleunlink(rel->rd_smgr,rel->rd_istemp);
1217+
rel->rd_smgr=NULL;
1218+
}
12141219

12151220
/*
12161221
* Close relcache entry, but *keep* AccessExclusiveLock on the
@@ -1706,7 +1711,7 @@ SetRelationNumChecks(Relation rel, int numchecks)
17061711
else
17071712
{
17081713
/* Skip the disk update, but force relcache inval anyway */
1709-
CacheInvalidateRelcache(RelationGetRelid(rel));
1714+
CacheInvalidateRelcache(rel);
17101715
}
17111716

17121717
heap_freetuple(reltup);
@@ -1943,7 +1948,9 @@ RelationTruncateIndexes(Oid heapId)
19431948
DropRelationBuffers(currentIndex);
19441949

19451950
/* Now truncate the actual data and set blocks to zero */
1946-
smgrtruncate(DEFAULT_SMGR,currentIndex,0);
1951+
if (currentIndex->rd_smgr==NULL)
1952+
currentIndex->rd_smgr=smgropen(currentIndex->rd_node);
1953+
smgrtruncate(currentIndex->rd_smgr,0);
19471954
currentIndex->rd_nblocks=0;
19481955
currentIndex->rd_targblock=InvalidBlockNumber;
19491956

@@ -1990,7 +1997,9 @@ heap_truncate(Oid rid)
19901997
DropRelationBuffers(rel);
19911998

19921999
/* Now truncate the actual data and set blocks to zero */
1993-
smgrtruncate(DEFAULT_SMGR,rel,0);
2000+
if (rel->rd_smgr==NULL)
2001+
rel->rd_smgr=smgropen(rel->rd_node);
2002+
smgrtruncate(rel->rd_smgr,0);
19942003
rel->rd_nblocks=0;
19952004
rel->rd_targblock=InvalidBlockNumber;
19962005

‎src/backend/catalog/index.c

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.226 2004/01/28 21:02:39 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.227 2004/02/10 01:55:24 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -808,7 +808,11 @@ index_drop(Oid indexId)
808808
if (i<0)
809809
elog(ERROR,"FlushRelationBuffers returned %d",i);
810810

811-
smgrunlink(DEFAULT_SMGR,userIndexRelation);
811+
if (userIndexRelation->rd_smgr==NULL)
812+
userIndexRelation->rd_smgr=smgropen(userIndexRelation->rd_node);
813+
smgrscheduleunlink(userIndexRelation->rd_smgr,
814+
userIndexRelation->rd_istemp);
815+
userIndexRelation->rd_smgr=NULL;
812816

813817
/*
814818
* We are presently too lazy to attempt to compute the new correct
@@ -818,7 +822,7 @@ index_drop(Oid indexId)
818822
* owning relation to ensure other backends update their relcache
819823
* lists of indexes.
820824
*/
821-
CacheInvalidateRelcache(heapId);
825+
CacheInvalidateRelcache(userHeapRelation);
822826

823827
/*
824828
* Close rels, but keep locks
@@ -1057,7 +1061,7 @@ setRelhasindex(Oid relid, bool hasindex, bool isprimary, Oid reltoastidxid)
10571061
else
10581062
{
10591063
/* no need to change tuple, but force relcache rebuild anyway */
1060-
CacheInvalidateRelcache(relid);
1064+
CacheInvalidateRelcacheByTuple(tuple);
10611065
}
10621066

10631067
if (!pg_class_scan)
@@ -1077,10 +1081,11 @@ void
10771081
setNewRelfilenode(Relationrelation)
10781082
{
10791083
Oidnewrelfilenode;
1084+
RelFileNodenewrnode;
1085+
SMgrRelationsrel;
10801086
Relationpg_class;
10811087
HeapTupletuple;
10821088
Form_pg_classrd_rel;
1083-
RelationDataworkrel;
10841089

10851090
/* Can't change relfilenode for nailed tables (indexes ok though) */
10861091
Assert(!relation->rd_isnailed||
@@ -1107,14 +1112,18 @@ setNewRelfilenode(Relation relation)
11071112

11081113
/* create another storage file. Is it a little ugly ? */
11091114
/* NOTE: any conflict in relfilenode value will be caught here */
1110-
memcpy((char*)&workrel,relation,sizeof(RelationData));
1111-
workrel.rd_fd=-1;
1112-
workrel.rd_node.relNode=newrelfilenode;
1113-
heap_storage_create(&workrel);
1114-
smgrclose(DEFAULT_SMGR,&workrel);
1115+
newrnode=relation->rd_node;
1116+
newrnode.relNode=newrelfilenode;
1117+
1118+
srel=smgropen(newrnode);
1119+
smgrcreate(srel,relation->rd_istemp, false);
1120+
smgrclose(srel);
11151121

11161122
/* schedule unlinking old relfilenode */
1117-
smgrunlink(DEFAULT_SMGR,relation);
1123+
if (relation->rd_smgr==NULL)
1124+
relation->rd_smgr=smgropen(relation->rd_node);
1125+
smgrscheduleunlink(relation->rd_smgr,relation->rd_istemp);
1126+
relation->rd_smgr=NULL;
11181127

11191128
/* update the pg_class row */
11201129
rd_rel->relfilenode=newrelfilenode;
@@ -1672,7 +1681,9 @@ reindex_index(Oid indexId)
16721681
DropRelationBuffers(iRel);
16731682

16741683
/* Now truncate the actual data and set blocks to zero */
1675-
smgrtruncate(DEFAULT_SMGR,iRel,0);
1684+
if (iRel->rd_smgr==NULL)
1685+
iRel->rd_smgr=smgropen(iRel->rd_node);
1686+
smgrtruncate(iRel->rd_smgr,0);
16761687
iRel->rd_nblocks=0;
16771688
iRel->rd_targblock=InvalidBlockNumber;
16781689
}

‎src/backend/commands/copy.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.217 2004/01/28 21:02:39 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.218 2004/02/10 01:55:24 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -40,6 +40,7 @@
4040
#include"parser/parse_coerce.h"
4141
#include"parser/parse_relation.h"
4242
#include"rewrite/rewriteHandler.h"
43+
#include"storage/fd.h"
4344
#include"tcop/pquery.h"
4445
#include"tcop/tcopprot.h"
4546
#include"utils/acl.h"

‎src/backend/commands/dbcommands.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.130 2004/01/07 18:56:25neilc Exp $
12+
* $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.131 2004/02/10 01:55:25tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -30,6 +30,7 @@
3030
#include"commands/comment.h"
3131
#include"commands/dbcommands.h"
3232
#include"miscadmin.h"
33+
#include"storage/fd.h"
3334
#include"storage/freespace.h"
3435
#include"storage/sinval.h"
3536
#include"utils/acl.h"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp