summaryrefslogtreecommitdiff
path: root/src/backend/catalog
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2000-04-09 04:43:20 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2000-04-09 04:43:20 +0000
commit1f6d8b90b83e02af8e73adcb167581bb10d6be22 (patch)
tree951f6bcc75fc6e42e23b1e695d259bc18a71b193 /src/backend/catalog
parent9c38a8d29684e9b9822ff7ca7f84c22ecab9cf1e (diff)
downloadpostgresql-1f6d8b90b83e02af8e73adcb167581bb10d6be22.tar.gz
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.
Diffstat (limited to 'src/backend/catalog')
-rw-r--r--src/backend/catalog/catalog.c74
1 files changed, 68 insertions, 6 deletions
diff --git a/src/backend/catalog/catalog.c b/src/backend/catalog/catalog.c
index 1072877713..5425387b3f 100644
--- a/src/backend/catalog/catalog.c
+++ b/src/backend/catalog/catalog.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/catalog/catalog.c,v 1.30 2000/01/26 05:56:10 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/catalog/catalog.c,v 1.31 2000/04/09 04:43:15 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -23,26 +23,88 @@
#include "utils/syscache.h"
/*
- * relpath - path to the relation
- * Perhaps this should be in-line code in relopen().
+ * relpath - construct path to a relation's file
+ *
+ * Note that this only works with relations that are visible to the current
+ * backend, ie, either in the current database or shared system relations.
+ *
+ * Result is a palloc'd string.
*/
char *
relpath(const char *relname)
{
char *path;
- size_t bufsize = 0;
if (IsSharedSystemRelationName(relname))
{
- bufsize = strlen(DataDir) + sizeof(NameData) + 2;
+ /* Shared system relations live in DataDir */
+ size_t bufsize = strlen(DataDir) + sizeof(NameData) + 2;
+
path = (char *) palloc(bufsize);
- snprintf(path, bufsize, "%s/%s", DataDir, relname);
+ snprintf(path, bufsize, "%s%c%s", DataDir, SEP_CHAR, relname);
return path;
}
+ /*
+ * If it is in the current database, assume it is in current working
+ * directory. NB: this does not work during bootstrap!
+ */
return pstrdup(relname);
}
/*
+ * relpath_blind - construct path to a relation's file
+ *
+ * Construct the path using only the info available to smgrblindwrt,
+ * namely the names and OIDs of the database and relation. (Shared system
+ * relations are identified with dbid = 0.) Note that we may have to
+ * access a relation belonging to a different database!
+ *
+ * Result is a palloc'd string.
+ */
+
+char *
+relpath_blind(const char *dbname, const char *relname,
+ Oid dbid, Oid relid)
+{
+ char *path;
+
+ if (dbid == (Oid) 0)
+ {
+ /* Shared system relations live in DataDir */
+ path = (char *) palloc(strlen(DataDir) + sizeof(NameData) + 2);
+ sprintf(path, "%s%c%s", DataDir, SEP_CHAR, relname);
+ }
+ else if (dbid == MyDatabaseId)
+ {
+ /* XXX why is this inconsistent with relpath() ? */
+ path = (char *) palloc(strlen(DatabasePath) + sizeof(NameData) + 2);
+ sprintf(path, "%s%c%s", DatabasePath, SEP_CHAR, relname);
+ }
+ else
+ {
+ /* this is work around only !!! */
+ char dbpathtmp[MAXPGPATH];
+ Oid id;
+ char *dbpath;
+
+ GetRawDatabaseInfo(dbname, &id, dbpathtmp);
+
+ if (id != dbid)
+ elog(FATAL, "relpath_blind: oid of db %s is not %u",
+ dbname, dbid);
+ dbpath = ExpandDatabasePath(dbpathtmp);
+ if (dbpath == NULL)
+ elog(FATAL, "relpath_blind: can't expand path for db %s",
+ dbname);
+ path = (char *) palloc(strlen(dbpath) + sizeof(NameData) + 2);
+ sprintf(path, "%s%c%s", dbpath, SEP_CHAR, relname);
+ pfree(dbpath);
+ }
+ return path;
+}
+
+
+/*
* IsSystemRelationName
* True iff name is the name of a system catalog relation.
*