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

Commit 2c7de17

Browse files
committed
New file naming. Database OID is used as "tablespace" id and
relation OID is used as file node on creation but may be changed later if required. Regression Tests Approved (c) -:)))
1 parent 07a55eb commit 2c7de17

File tree

19 files changed

+488
-154
lines changed

19 files changed

+488
-154
lines changed

src/backend/catalog/catalog.c

Lines changed: 56 additions & 1 deletion
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.33 2000/07/03 20:48:28 petere Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/catalog.c,v 1.34 2000/10/16 14:52:02 vadim Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -22,6 +22,7 @@
2222
#include "miscadmin.h"
2323
#include "utils/syscache.h"
2424

25+
#ifdef OLD_FILE_NAMING
2526
/*
2627
* relpath - construct path to a relation's file
2728
*
@@ -104,6 +105,60 @@ relpath_blind(const char *dbname, const char *relname,
104105
return path;
105106
}
106107

108+
#else /* ! OLD_FILE_NAMING */
109+
110+
/*
111+
* relpath - construct path to a relation's file
112+
*
113+
* Result is a palloc'd string.
114+
*/
115+
116+
char *
117+
relpath(RelFileNode rnode)
118+
{
119+
char *path;
120+
121+
if (rnode.tblNode == (Oid) 0) /* "global tablespace" */
122+
{
123+
/* Shared system relations live in {datadir}/global */
124+
path = (char *) palloc(strlen(DataDir) + 8 + sizeof(NameData) + 1);
125+
sprintf(path, "%s%cglobal%c%u", DataDir, SEP_CHAR, SEP_CHAR, rnode.relNode);
126+
}
127+
else
128+
{
129+
path = (char *) palloc(strlen(DataDir) + 6 + 2 * sizeof(NameData) + 3);
130+
sprintf(path, "%s%cbase%c%u%c%u", DataDir, SEP_CHAR, SEP_CHAR,
131+
rnode.tblNode, SEP_CHAR, rnode.relNode);
132+
}
133+
return path;
134+
}
135+
136+
/*
137+
* GetDatabasePath - construct path to a database dir
138+
*
139+
* Result is a palloc'd string.
140+
*/
141+
142+
char *
143+
GetDatabasePath(Oid tblNode)
144+
{
145+
char *path;
146+
147+
if (tblNode == (Oid) 0) /* "global tablespace" */
148+
{
149+
/* Shared system relations live in {datadir}/global */
150+
path = (char *) palloc(strlen(DataDir) + 8);
151+
sprintf(path, "%s%cglobal", DataDir, SEP_CHAR);
152+
}
153+
else
154+
{
155+
path = (char *) palloc(strlen(DataDir) + 6 + sizeof(NameData) + 1);
156+
sprintf(path, "%s%cbase%c%u", DataDir, SEP_CHAR, SEP_CHAR, tblNode);
157+
}
158+
return path;
159+
}
160+
161+
#endif /* OLD_FILE_NAMING */
107162

108163
/*
109164
* IsSystemRelationName

src/backend/catalog/heap.c

Lines changed: 70 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.148 2000/10/11 21:28:18 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.149 2000/10/16 14:52:02 vadim Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -177,12 +177,13 @@ heap_create(char *relname,
177177
{
178178
static unsigned int uniqueId = 0;
179179

180-
Oid relid;
181-
Relation rel;
182-
bool nailme = false;
183-
int natts = tupDesc->natts;
184-
int i;
185-
MemoryContext oldcxt;
180+
Oid relid;
181+
Relation rel;
182+
bool nailme = false;
183+
int natts = tupDesc->natts;
184+
int i;
185+
MemoryContext oldcxt;
186+
Oid tblNode = MyDatabaseId;
186187

187188
/* ----------------
188189
* sanity checks
@@ -203,25 +204,65 @@ heap_create(char *relname,
203204
* descriptor follows.
204205
* ----------------
205206
*/
206-
if (relname && strcmp(RelationRelationName, relname) == 0)
207-
{
208-
relid = RelOid_pg_class;
209-
nailme = true;
210-
}
211-
else if (relname && strcmp(AttributeRelationName, relname) == 0)
212-
{
213-
relid = RelOid_pg_attribute;
214-
nailme = true;
215-
}
216-
else if (relname && strcmp(ProcedureRelationName, relname) == 0)
217-
{
218-
relid = RelOid_pg_proc;
219-
nailme = true;
220-
}
221-
else if (relname && strcmp(TypeRelationName, relname) == 0)
207+
if (relname && IsSystemRelationName(relname))
222208
{
223-
relid = RelOid_pg_type;
224-
nailme = true;
209+
if (strcmp(TypeRelationName, relname) == 0)
210+
{
211+
nailme = true;
212+
relid = RelOid_pg_type;
213+
}
214+
else if (strcmp(AttributeRelationName, relname) == 0)
215+
{
216+
nailme = true;
217+
relid = RelOid_pg_attribute;
218+
}
219+
else if (strcmp(ProcedureRelationName, relname) == 0)
220+
{
221+
nailme = true;
222+
relid = RelOid_pg_proc;
223+
}
224+
else if (strcmp(RelationRelationName, relname) == 0)
225+
{
226+
nailme = true;
227+
relid = RelOid_pg_class;
228+
}
229+
else if (strcmp(ShadowRelationName, relname) == 0)
230+
{
231+
tblNode = InvalidOid;
232+
relid = RelOid_pg_shadow;
233+
}
234+
else if (strcmp(GroupRelationName, relname) == 0)
235+
{
236+
tblNode = InvalidOid;
237+
relid = RelOid_pg_group;
238+
}
239+
else if (strcmp(DatabaseRelationName, relname) == 0)
240+
{
241+
tblNode = InvalidOid;
242+
relid = RelOid_pg_database;
243+
}
244+
else if (strcmp(VariableRelationName, relname) == 0)
245+
{
246+
tblNode = InvalidOid;
247+
relid = RelOid_pg_variable;
248+
}
249+
else if (strcmp(LogRelationName, relname) == 0)
250+
{
251+
tblNode = InvalidOid;
252+
relid = RelOid_pg_log;
253+
}
254+
else if (strcmp(AttrDefaultRelationName, relname) == 0)
255+
relid = RelOid_pg_attrdef;
256+
else if (strcmp(RelCheckRelationName, relname) == 0)
257+
relid = RelOid_pg_relcheck;
258+
else if (strcmp(TriggerRelationName, relname) == 0)
259+
relid = RelOid_pg_trigger;
260+
else
261+
{
262+
relid = newoid();
263+
if (IsSharedSystemRelationName(relname))
264+
tblNode = InvalidOid;
265+
}
225266
}
226267
else
227268
relid = newoid();
@@ -290,6 +331,10 @@ heap_create(char *relname,
290331
rel->rd_rel->reltype = relid;
291332
}
292333

334+
rel->rd_node.tblNode = tblNode;
335+
rel->rd_node.relNode = relid;
336+
rel->rd_rel->relfilenode = relid;
337+
293338
/* ----------------
294339
* done building relcache entry.
295340
* ----------------

src/backend/commands/dbcommands.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.60 2000/09/06 14:15:16 petere Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.61 2000/10/16 14:52:03 vadim Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -25,6 +25,7 @@
2525

2626
#include "access/heapam.h"
2727
#include "catalog/catname.h"
28+
#include "catalog/catalog.h"
2829
#include "catalog/pg_database.h"
2930
#include "catalog/pg_shadow.h"
3031
#include "commands/comment.h"
@@ -76,6 +77,7 @@ createdb(const char *dbname, const char *dbpath, int encoding)
7677
if (IsTransactionBlock())
7778
elog(ERROR, "CREATE DATABASE: may not be called in a transaction block");
7879

80+
#ifdef OLD_FILE_NAMING
7981
/* Generate directory name for the new database */
8082
if (dbpath == NULL || strcmp(dbpath, dbname) == 0)
8183
strcpy(locbuf, dbname);
@@ -89,6 +91,7 @@ createdb(const char *dbname, const char *dbpath, int encoding)
8991
"The database path '%s' is invalid. "
9092
"This may be due to a character that is not allowed or because the chosen "
9193
"path isn't permitted for databases", dbpath);
94+
#endif
9295

9396
/*
9497
* Insert a new tuple into pg_database
@@ -111,6 +114,10 @@ createdb(const char *dbname, const char *dbpath, int encoding)
111114
*/
112115
heap_insert(pg_database_rel, tuple);
113116

117+
#ifndef OLD_FILE_NAMING
118+
loc = GetDatabasePath(tuple->t_data->t_oid);
119+
#endif
120+
114121
/*
115122
* Update indexes (there aren't any currently)
116123
*/
@@ -140,8 +147,19 @@ createdb(const char *dbname, const char *dbpath, int encoding)
140147
if (mkdir(loc, S_IRWXU) != 0)
141148
elog(ERROR, "CREATE DATABASE: unable to create database directory '%s': %s", loc, strerror(errno));
142149

150+
#ifdef OLD_FILE_NAMING
143151
snprintf(buf, sizeof(buf), "cp %s%cbase%ctemplate1%c* '%s'",
144152
DataDir, SEP_CHAR, SEP_CHAR, SEP_CHAR, loc);
153+
#else
154+
{
155+
char *tmpl = GetDatabasePath(TemplateDbOid);
156+
157+
snprintf(buf, sizeof(buf), "cp %s%c* '%s'",
158+
tmpl, SEP_CHAR, loc);
159+
pfree(tmpl);
160+
}
161+
#endif
162+
145163
ret = system(buf);
146164
/* Some versions of SunOS seem to return ECHILD after a system() call */
147165
#if defined(sun)
@@ -204,12 +222,16 @@ dropdb(const char *dbname)
204222
if (GetUserId() != db_owner && !use_super)
205223
elog(ERROR, "DROP DATABASE: Permission denied");
206224

225+
#ifdef OLD_FILE_NAMING
207226
path = ExpandDatabasePath(dbpath);
208227
if (path == NULL)
209228
elog(ERROR,
210229
"The database path '%s' is invalid. "
211230
"This may be due to a character that is not allowed or because the chosen "
212231
"path isn't permitted for databases", path);
232+
#else
233+
path = GetDatabasePath(db_id);
234+
#endif
213235

214236
/*
215237
* Obtain exclusive lock on pg_database. We need this to ensure that

src/backend/commands/rename.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.47 2000/09/06 14:15:16 petere Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.48 2000/10/16 14:52:03 vadim Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -311,6 +311,7 @@ renamerel(const char *oldrelname, const char *newrelname)
311311
if (relkind != RELKIND_INDEX)
312312
TypeRename(oldrelname, newrelname);
313313

314+
#ifdef OLD_FILE_NAMING
314315
/*
315316
* Perform physical rename of files. If this fails, we haven't yet
316317
* done anything irreversible. NOTE that this MUST be the last step;
@@ -340,4 +341,5 @@ renamerel(const char *oldrelname, const char *newrelname)
340341
toldpath, tnewpath);
341342
}
342343
}
344+
#endif
343345
}

src/backend/postmaster/postmaster.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.171 2000/10/11 17:58:01 momjian Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.172 2000/10/16 14:52:08 vadim Exp $
1515
*
1616
* NOTES
1717
*
@@ -60,6 +60,7 @@
6060
#include "getopt.h"
6161
#endif
6262

63+
#include "catalog/pg_database.h"
6364
#include "commands/async.h"
6465
#include "lib/dllist.h"
6566
#include "libpq/auth.h"
@@ -278,8 +279,14 @@ checkDataDir(const char *DataDir)
278279
exit(2);
279280
}
280281

282+
#ifdef OLD_FILE_NAMING
281283
snprintf(path, sizeof(path), "%s%cbase%ctemplate1%cpg_class",
282284
DataDir, SEP_CHAR, SEP_CHAR, SEP_CHAR);
285+
#else
286+
snprintf(path, sizeof(path), "%s%cbase%c%u%c%u",
287+
DataDir, SEP_CHAR, SEP_CHAR,
288+
TemplateDbOid, SEP_CHAR, RelOid_pg_class);
289+
#endif
283290

284291
fp = AllocateFile(path, PG_BINARY_R);
285292
if (fp == NULL)

0 commit comments

Comments
 (0)