Skip to content

Commit dfc7e7b

Browse files
author
Neil Conway
committed
Code cleanup, mostly in the smgr:
- Update comment in IsReservedName() to the present day - Improve some variable & function names in commands/vacuum.c. I was planning to rewrite this to avoid lappend(), but since I still intend to do the list rewrite, there's no need for that. - Update some smgr comments which seemed to imply that we still forced all dirty pages to disk at commit-time. - Replace some #ifdef DIAGNOSTIC code with assertions. - Make the distinction between OS-level file descriptors and virtual file descriptors a little clearer in a few comments - Other minor comment improvements in the smgr code
1 parent 030f8e7 commit dfc7e7b

File tree

6 files changed

+73
-98
lines changed

6 files changed

+73
-98
lines changed

src/backend/catalog/catalog.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/catalog/catalog.c,v 1.50 2003/11/29 19:51:42 pgsql Exp $
12+
* $PostgreSQL: pgsql/src/backend/catalog/catalog.c,v 1.51 2004/01/06 18:07:31 neilc Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -165,8 +165,9 @@ IsToastNamespace(Oid namespaceId)
165165
* IsReservedName
166166
* True iff name starts with the pg_ prefix.
167167
*
168-
* For some classes of objects, the prefix pg_ is reserved
169-
* for system objects only.
168+
* For some classes of objects, the prefix pg_ is reserved for
169+
* system objects only. As of 7.3, this is now only true for
170+
* schema names.
170171
*/
171172
bool
172173
IsReservedName(const char *name)

src/backend/commands/analyze.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.65 2003/11/29 19:51:47 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.66 2004/01/06 18:07:31 neilc Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -204,8 +204,9 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt)
204204
}
205205

206206
/*
207-
* Check that it's a plain table; we used to do this in getrels() but
208-
* seems safer to check after we've locked the relation.
207+
* Check that it's a plain table; we used to do this in
208+
* get_rel_oids() but seems safer to check after we've locked the
209+
* relation.
209210
*/
210211
if (onerel->rd_rel->relkind != RELKIND_RELATION)
211212
{

src/backend/commands/vacuum.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*
1515
* IDENTIFICATION
16-
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.269 2003/11/29 19:51:47 pgsql Exp $
16+
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.270 2004/01/06 18:07:31 neilc Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -108,7 +108,7 @@ static TransactionId FreezeLimit;
108108

109109

110110
/* non-export function prototypes */
111-
static List *getrels(const RangeVar *vacrel, const char *stmttype);
111+
static List *get_rel_oids(const RangeVar *vacrel, const char *stmttype);
112112
static void vac_update_dbstats(Oid dbid,
113113
TransactionId vacuumXID,
114114
TransactionId frozenXID);
@@ -161,7 +161,7 @@ vacuum(VacuumStmt *vacstmt)
161161
TransactionId initialOldestXmin = InvalidTransactionId;
162162
TransactionId initialFreezeLimit = InvalidTransactionId;
163163
bool all_rels;
164-
List *vrl,
164+
List *relations,
165165
*cur;
166166

167167
if (vacstmt->verbose)
@@ -216,7 +216,7 @@ vacuum(VacuumStmt *vacstmt)
216216
all_rels = (vacstmt->relation == NULL);
217217

218218
/* Build list of relations to process (note this lives in vac_context) */
219-
vrl = getrels(vacstmt->relation, stmttype);
219+
relations = get_rel_oids(vacstmt->relation, stmttype);
220220

221221
/*
222222
* Formerly, there was code here to prevent more than one VACUUM from
@@ -282,7 +282,7 @@ vacuum(VacuumStmt *vacstmt)
282282
/*
283283
* Loop to process each selected relation.
284284
*/
285-
foreach(cur, vrl)
285+
foreach(cur, relations)
286286
{
287287
Oid relid = lfirsto(cur);
288288

@@ -383,21 +383,21 @@ vacuum(VacuumStmt *vacstmt)
383383
* per-relation transactions.
384384
*/
385385
static List *
386-
getrels(const RangeVar *vacrel, const char *stmttype)
386+
get_rel_oids(const RangeVar *vacrel, const char *stmttype)
387387
{
388-
List *vrl = NIL;
388+
List *oid_list = NIL;
389389
MemoryContext oldcontext;
390390

391391
if (vacrel)
392392
{
393-
/* Process specific relation */
393+
/* Process a specific relation */
394394
Oid relid;
395395

396396
relid = RangeVarGetRelid(vacrel, false);
397397

398398
/* Make a relation list entry for this guy */
399399
oldcontext = MemoryContextSwitchTo(vac_context);
400-
vrl = lappendo(vrl, relid);
400+
oid_list = lappendo(oid_list, relid);
401401
MemoryContextSwitchTo(oldcontext);
402402
}
403403
else
@@ -421,15 +421,15 @@ getrels(const RangeVar *vacrel, const char *stmttype)
421421
{
422422
/* Make a relation list entry for this guy */
423423
oldcontext = MemoryContextSwitchTo(vac_context);
424-
vrl = lappendo(vrl, HeapTupleGetOid(tuple));
424+
oid_list = lappendo(oid_list, HeapTupleGetOid(tuple));
425425
MemoryContextSwitchTo(oldcontext);
426426
}
427427

428428
heap_endscan(scan);
429429
heap_close(pgclass, AccessShareLock);
430430
}
431431

432-
return vrl;
432+
return oid_list;
433433
}
434434

435435
/*
@@ -818,8 +818,9 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind)
818818
}
819819

820820
/*
821-
* Check that it's a plain table; we used to do this in getrels() but
822-
* seems safer to check after we've locked the relation.
821+
* Check that it's a plain table; we used to do this in
822+
* get_rel_oids() but seems safer to check after we've locked the
823+
* relation.
823824
*/
824825
if (onerel->rd_rel->relkind != expected_relkind)
825826
{

src/backend/storage/smgr/md.c

Lines changed: 33 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.99 2003/11/29 19:51:57 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.100 2004/01/06 18:07:31 neilc Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -25,18 +25,15 @@
2525
#include "utils/inval.h"
2626
#include "utils/memutils.h"
2727

28-
29-
#undef DIAGNOSTIC
30-
3128
/*
32-
* The magnetic disk storage manager keeps track of open file descriptors
33-
* in its own descriptor pool. This happens for two reasons. First, at
34-
* transaction boundaries, we walk the list of descriptors and flush
35-
* anything that we've dirtied in the current transaction. Second, we want
36-
* to support relations larger than the OS' file size limit (often 2GBytes).
37-
* In order to do that, we break relations up into chunks of < 2GBytes
38-
* and store one chunk in each of several files that represent the relation.
39-
* See the BLCKSZ and RELSEG_SIZE configuration constants in include/pg_config.h.
29+
* The magnetic disk storage manager keeps track of open file
30+
* descriptors in its own descriptor pool. This is done to make it
31+
* easier to support relations that are larger than the operating
32+
* system's file size limit (often 2GBytes). In order to do that, we
33+
* we break relations up into chunks of < 2GBytes and store one chunk
34+
* in each of several files that represent the relation. See the
35+
* BLCKSZ and RELSEG_SIZE configuration constants in
36+
* include/pg_config.h.
4037
*
4138
* The file descriptor stored in the relation cache (see RelationGetFile())
4239
* is actually an index into the Md_fdvec array. -1 indicates not open.
@@ -67,7 +64,7 @@ static MdfdVec *Md_fdvec = (MdfdVec *) NULL;
6764
static int Md_Free = -1; /* head of freelist of unused fdvec
6865
* entries */
6966
static int CurFd = 0; /* first never-used fdvec index */
70-
static MemoryContext MdCxt; /* context for all my allocations */
67+
static MemoryContext MdCxt; /* context for all md.c allocations */
7168

7269
/* routines declared here */
7370
static void mdclose_fd(int fd);
@@ -84,11 +81,8 @@ static BlockNumber _mdnblocks(File file, Size blcksz);
8481
/*
8582
* mdinit() -- Initialize private state for magnetic disk storage manager.
8683
*
87-
* We keep a private table of all file descriptors. Whenever we do
88-
* a write to one, we mark it dirty in our table. Whenever we force
89-
* changes to disk, we mark the file descriptor clean. At transaction
90-
* commit, we force changes to disk for all dirty file descriptors.
91-
* This routine allocates and initializes the table.
84+
* We keep a private table of all file descriptors. This routine
85+
* allocates and initializes the table.
9286
*
9387
* Returns SM_SUCCESS or SM_FAIL with errno set as appropriate.
9488
*/
@@ -247,16 +241,13 @@ mdextend(Relation reln, BlockNumber blocknum, char *buffer)
247241

248242
#ifndef LET_OS_MANAGE_FILESIZE
249243
seekpos = (long) (BLCKSZ * (blocknum % ((BlockNumber) RELSEG_SIZE)));
250-
#ifdef DIAGNOSTIC
251-
if (seekpos >= BLCKSZ * RELSEG_SIZE)
252-
elog(FATAL, "seekpos too big");
253-
#endif
244+
Assert(seekpos < BLCKSZ * RELSEG_SIZE);
254245
#else
255246
seekpos = (long) (BLCKSZ * (blocknum));
256247
#endif
257248

258249
/*
259-
* Note: because caller obtained blocknum by calling mdnblocks, which
250+
* Note: because caller obtained blocknum by calling _mdnblocks, which
260251
* did a seek(SEEK_END), this seek is often redundant and will be
261252
* optimized away by fd.c. It's not redundant, however, if there is a
262253
* partial page at the end of the file. In that case we want to try
@@ -282,10 +273,7 @@ mdextend(Relation reln, BlockNumber blocknum, char *buffer)
282273
}
283274

284275
#ifndef LET_OS_MANAGE_FILESIZE
285-
#ifdef DIAGNOSTIC
286-
if (_mdnblocks(v->mdfd_vfd, BLCKSZ) > ((BlockNumber) RELSEG_SIZE))
287-
elog(FATAL, "segment too big");
288-
#endif
276+
Assert(_mdnblocks(v->mdfd_vfd, BLCKSZ) <= ((BlockNumber) RELSEG_SIZE));
289277
#endif
290278

291279
return SM_SUCCESS;
@@ -335,11 +323,7 @@ mdopen(Relation reln)
335323
Md_fdvec[vfd].mdfd_flags = (uint16) 0;
336324
#ifndef LET_OS_MANAGE_FILESIZE
337325
Md_fdvec[vfd].mdfd_chain = (MdfdVec *) NULL;
338-
339-
#ifdef DIAGNOSTIC
340-
if (_mdnblocks(fd, BLCKSZ) > ((BlockNumber) RELSEG_SIZE))
341-
elog(FATAL, "segment too big");
342-
#endif
326+
Assert(_mdnblocks(fd, BLCKSZ) <= ((BlockNumber) RELSEG_SIZE));
343327
#endif
344328

345329
return vfd;
@@ -348,7 +332,7 @@ mdopen(Relation reln)
348332
/*
349333
* mdclose() -- Close the specified relation, if it isn't closed already.
350334
*
351-
* AND FREE fd vector! It may be re-used for other relation!
335+
* AND FREE fd vector! It may be re-used for other relations!
352336
* reln should be flushed from cache after closing !..
353337
*
354338
* Returns SM_SUCCESS or SM_FAIL with errno set as appropriate.
@@ -418,11 +402,7 @@ mdread(Relation reln, BlockNumber blocknum, char *buffer)
418402

419403
#ifndef LET_OS_MANAGE_FILESIZE
420404
seekpos = (long) (BLCKSZ * (blocknum % ((BlockNumber) RELSEG_SIZE)));
421-
422-
#ifdef DIAGNOSTIC
423-
if (seekpos >= BLCKSZ * RELSEG_SIZE)
424-
elog(FATAL, "seekpos too big");
425-
#endif
405+
Assert(seekpos < BLCKSZ * RELSEG_SIZE);
426406
#else
427407
seekpos = (long) (BLCKSZ * (blocknum));
428408
#endif
@@ -466,10 +446,7 @@ mdwrite(Relation reln, BlockNumber blocknum, char *buffer)
466446

467447
#ifndef LET_OS_MANAGE_FILESIZE
468448
seekpos = (long) (BLCKSZ * (blocknum % ((BlockNumber) RELSEG_SIZE)));
469-
#ifdef DIAGNOSTIC
470-
if (seekpos >= BLCKSZ * RELSEG_SIZE)
471-
elog(FATAL, "seekpos too big");
472-
#endif
449+
Assert(seekpos < BLCKSZ * RELSEG_SIZE);
473450
#else
474451
seekpos = (long) (BLCKSZ * (blocknum));
475452
#endif
@@ -505,10 +482,7 @@ mdblindwrt(RelFileNode rnode,
505482

506483
#ifndef LET_OS_MANAGE_FILESIZE
507484
seekpos = (long) (BLCKSZ * (blkno % ((BlockNumber) RELSEG_SIZE)));
508-
#ifdef DIAGNOSTIC
509-
if (seekpos >= BLCKSZ * RELSEG_SIZE)
510-
elog(FATAL, "seekpos too big");
511-
#endif
485+
Assert(seekpos < BLCKSZ * RELSEG_SIZE);
512486
#else
513487
seekpos = (long) (BLCKSZ * (blkno));
514488
#endif
@@ -722,8 +696,6 @@ mdcommit(void)
722696

723697
/*
724698
* mdabort() -- Abort a transaction.
725-
*
726-
* Changes need not be forced to disk at transaction abort.
727699
*/
728700
int
729701
mdabort(void)
@@ -748,7 +720,7 @@ mdsync(void)
748720
}
749721

750722
/*
751-
* _fdvec_alloc () -- grab a free (or new) md file descriptor vector.
723+
* _fdvec_alloc() -- Grab a free (or new) md file descriptor vector.
752724
*/
753725
static int
754726
_fdvec_alloc(void)
@@ -802,7 +774,7 @@ _fdvec_alloc(void)
802774
}
803775

804776
/*
805-
* _fdvec_free () -- free md file descriptor vector.
777+
* _fdvec_free() -- free md file descriptor vector.
806778
*
807779
*/
808780
static
@@ -853,19 +825,18 @@ _mdfd_openseg(Relation reln, BlockNumber segno, int oflags)
853825
v->mdfd_flags = (uint16) 0;
854826
#ifndef LET_OS_MANAGE_FILESIZE
855827
v->mdfd_chain = (MdfdVec *) NULL;
856-
857-
#ifdef DIAGNOSTIC
858-
if (_mdnblocks(fd, BLCKSZ) > ((BlockNumber) RELSEG_SIZE))
859-
elog(FATAL, "segment too big");
860-
#endif
828+
Assert(_mdnblocks(fd, BLCKSZ) <= ((BlockNumber) RELSEG_SIZE));
861829
#endif
862830

863831
/* all done */
864832
return v;
865833
}
866834

867-
/* Get the fd for the relation, opening it if it's not already open */
868-
835+
/*
836+
* _mdfd_getrelnfd() -- Get the (virtual) fd for the relation,
837+
* opening it if it's not already open
838+
*
839+
*/
869840
static int
870841
_mdfd_getrelnfd(Relation reln)
871842
{
@@ -882,8 +853,11 @@ _mdfd_getrelnfd(Relation reln)
882853
return fd;
883854
}
884855

885-
/* Find the segment of the relation holding the specified block */
886-
856+
/*
857+
* _mdfd_getseg() -- Find the segment of the relation holding the
858+
* specified block
859+
*
860+
*/
887861
static MdfdVec *
888862
_mdfd_getseg(Relation reln, BlockNumber blkno)
889863
{
@@ -942,7 +916,6 @@ _mdfd_getseg(Relation reln, BlockNumber blkno)
942916
*
943917
* The return value is the kernel descriptor, or -1 on failure.
944918
*/
945-
946919
static int
947920
_mdfd_blind_getseg(RelFileNode rnode, BlockNumber blkno)
948921
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy