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

Commit 1f6d8b9

Browse files
committed
Buffer manager modifications to keep a local buffer-dirtied bit as well
as a shared dirtybit for each shared buffer. The shared dirtybit still controls writing the buffer, but the local bit controls whether we need to fsync the buffer's file. This arrangement fixes a bug that allowed some required fsyncs to be missed, and should improve performance as well. For more info see my post of same date on pghackers.
1 parent 9c38a8d commit 1f6d8b9

File tree

13 files changed

+951
-431
lines changed

13 files changed

+951
-431
lines changed

src/backend/access/transam/xact.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.62 2000/03/17 02:36:05 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.63 2000/04/09 04:43:16 tgl Exp $
1212
*
1313
* NOTES
1414
* Transaction aborts can now occur two ways:
@@ -642,7 +642,7 @@ RecordTransactionCommit()
642642
{
643643
FlushBufferPool();
644644
if (leak)
645-
ResetBufferPool();
645+
ResetBufferPool(true);
646646

647647
/*
648648
* have the transaction access methods record the status
@@ -658,7 +658,7 @@ RecordTransactionCommit()
658658
}
659659

660660
if (leak)
661-
ResetBufferPool();
661+
ResetBufferPool(true);
662662
}
663663

664664

@@ -759,7 +759,10 @@ RecordTransactionAbort()
759759
if (SharedBufferChanged && !TransactionIdDidCommit(xid))
760760
TransactionIdAbort(xid);
761761

762-
ResetBufferPool();
762+
/*
763+
* Tell bufmgr and smgr to release resources.
764+
*/
765+
ResetBufferPool(false); /* false -> is abort */
763766
}
764767

765768
/* --------------------------------

src/backend/catalog/catalog.c

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/catalog.c,v 1.30 2000/01/26 05:56:10 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/catalog.c,v 1.31 2000/04/09 04:43:15 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -23,25 +23,87 @@
2323
#include "utils/syscache.h"
2424

2525
/*
26-
* relpath - path to the relation
27-
* Perhaps this should be in-line code in relopen().
26+
* relpath - construct path to a relation's file
27+
*
28+
* Note that this only works with relations that are visible to the current
29+
* backend, ie, either in the current database or shared system relations.
30+
*
31+
* Result is a palloc'd string.
2832
*/
2933
char *
3034
relpath(const char *relname)
3135
{
3236
char *path;
33-
size_t bufsize = 0;
3437

3538
if (IsSharedSystemRelationName(relname))
3639
{
37-
bufsize = strlen(DataDir) + sizeof(NameData) + 2;
40+
/* Shared system relations live in DataDir */
41+
size_t bufsize = strlen(DataDir) + sizeof(NameData) + 2;
42+
3843
path = (char *) palloc(bufsize);
39-
snprintf(path, bufsize, "%s/%s", DataDir, relname);
44+
snprintf(path, bufsize, "%s%c%s", DataDir, SEP_CHAR, relname);
4045
return path;
4146
}
47+
/*
48+
* If it is in the current database, assume it is in current working
49+
* directory. NB: this does not work during bootstrap!
50+
*/
4251
return pstrdup(relname);
4352
}
4453

54+
/*
55+
* relpath_blind - construct path to a relation's file
56+
*
57+
* Construct the path using only the info available to smgrblindwrt,
58+
* namely the names and OIDs of the database and relation. (Shared system
59+
* relations are identified with dbid = 0.) Note that we may have to
60+
* access a relation belonging to a different database!
61+
*
62+
* Result is a palloc'd string.
63+
*/
64+
65+
char *
66+
relpath_blind(const char *dbname, const char *relname,
67+
Oid dbid, Oid relid)
68+
{
69+
char *path;
70+
71+
if (dbid == (Oid) 0)
72+
{
73+
/* Shared system relations live in DataDir */
74+
path = (char *) palloc(strlen(DataDir) + sizeof(NameData) + 2);
75+
sprintf(path, "%s%c%s", DataDir, SEP_CHAR, relname);
76+
}
77+
else if (dbid == MyDatabaseId)
78+
{
79+
/* XXX why is this inconsistent with relpath() ? */
80+
path = (char *) palloc(strlen(DatabasePath) + sizeof(NameData) + 2);
81+
sprintf(path, "%s%c%s", DatabasePath, SEP_CHAR, relname);
82+
}
83+
else
84+
{
85+
/* this is work around only !!! */
86+
char dbpathtmp[MAXPGPATH];
87+
Oid id;
88+
char *dbpath;
89+
90+
GetRawDatabaseInfo(dbname, &id, dbpathtmp);
91+
92+
if (id != dbid)
93+
elog(FATAL, "relpath_blind: oid of db %s is not %u",
94+
dbname, dbid);
95+
dbpath = ExpandDatabasePath(dbpathtmp);
96+
if (dbpath == NULL)
97+
elog(FATAL, "relpath_blind: can't expand path for db %s",
98+
dbname);
99+
path = (char *) palloc(strlen(dbpath) + sizeof(NameData) + 2);
100+
sprintf(path, "%s%c%s", dbpath, SEP_CHAR, relname);
101+
pfree(dbpath);
102+
}
103+
return path;
104+
}
105+
106+
45107
/*
46108
* IsSystemRelationName
47109
* True iff name is the name of a system catalog relation.

src/backend/storage/buffer/buf_init.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_init.c,v 1.32 2000/01/26 05:56:50 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_init.c,v 1.33 2000/04/09 04:43:18 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -65,9 +65,11 @@ long *NWaitIOBackendP;
6565
extern IpcSemaphoreId WaitIOSemId;
6666

6767
long *PrivateRefCount; /* also used in freelist.c */
68-
bits8 *BufferLocks; /* */
69-
long *CommitInfoNeedsSave;/* to write buffers where we have filled
70-
* in t_infomask */
68+
bits8 *BufferLocks; /* flag bits showing locks I have set */
69+
BufferTag *BufferTagLastDirtied; /* tag buffer had when last dirtied by me */
70+
BufferBlindId *BufferBlindLastDirtied; /* and its BlindId too */
71+
bool *BufferDirtiedByMe; /* T if buf has been dirtied in cur xact */
72+
7173

7274
/*
7375
* Data Structures:
@@ -247,7 +249,9 @@ InitBufferPool(IPCKey key)
247249
#endif
248250
PrivateRefCount = (long *) calloc(NBuffers, sizeof(long));
249251
BufferLocks = (bits8 *) calloc(NBuffers, sizeof(bits8));
250-
CommitInfoNeedsSave = (long *) calloc(NBuffers, sizeof(long));
252+
BufferTagLastDirtied = (BufferTag *) calloc(NBuffers, sizeof(BufferTag));
253+
BufferBlindLastDirtied = (BufferBlindId *) calloc(NBuffers, sizeof(BufferBlindId));
254+
BufferDirtiedByMe = (bool *) calloc(NBuffers, sizeof(bool));
251255
}
252256

253257
/* -----------------------------------------------------

0 commit comments

Comments
 (0)