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 */
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. Thishappens 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 relationslarger than the OS' file size limit (often 2GBytes).
37- *In order to do that, we break relations up into chunks of < 2GBytes
38- *andstore 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. Thisis 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 relationsup into chunks of < 2GBytes and store one chunk
34+ *in each of several files that represent the relation. See the
35+ *BLCKSZ andRELSEG_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;
6764static int Md_Free = -1 ;/* head of freelist of unused fdvec
6865 * entries */
6966static int CurFd = 0 ;/* first never-used fdvec index */
70- static MemoryContext MdCxt ;/* context for allmy allocations */
67+ static MemoryContext MdCxt ;/* context for allmd.c allocations */
7168
7269/* routines declared here */
7370static 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
249243seekpos = (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
255246seekpos = (long ) (BLCKSZ * (blocknum ));
256247#endif
257248
258249/*
259- * Note: because caller obtained blocknum by callingmdnblocks , 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
291279return SM_SUCCESS ;
@@ -335,11 +323,7 @@ mdopen(Relation reln)
335323Md_fdvec [vfd ].mdfd_flags = (uint16 )0 ;
336324#ifndef LET_OS_MANAGE_FILESIZE
337325Md_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
345329return 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 otherrelation !
335+ *AND FREE fd vector! It may be re-used for otherrelations !
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
420404seekpos = (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
427407seekpos = (long ) (BLCKSZ * (blocknum ));
428408#endif
@@ -466,10 +446,7 @@ mdwrite(Relation reln, BlockNumber blocknum, char *buffer)
466446
467447#ifndef LET_OS_MANAGE_FILESIZE
468448seekpos = (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
474451seekpos = (long ) (BLCKSZ * (blocknum ));
475452#endif
@@ -505,10 +482,7 @@ mdblindwrt(RelFileNode rnode,
505482
506483#ifndef LET_OS_MANAGE_FILESIZE
507484seekpos = (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
513487seekpos = (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 */
728700int
729701mdabort (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 */
753725static 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 */
808780static
@@ -853,19 +825,18 @@ _mdfd_openseg(Relation reln, BlockNumber segno, int oflags)
853825v -> mdfd_flags = (uint16 )0 ;
854826#ifndef LET_OS_MANAGE_FILESIZE
855827v -> 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 */
864832return 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+ */
869840static int
870841_mdfd_getrelnfd (Relation reln )
871842{
@@ -882,8 +853,11 @@ _mdfd_getrelnfd(Relation reln)
882853return 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+ */
887861static 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-
946919static int
947920_mdfd_blind_getseg (RelFileNode rnode ,BlockNumber blkno )
948921{