8
8
*
9
9
*
10
10
* 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 $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
25
25
#include "utils/inval.h"
26
26
#include "utils/memutils.h"
27
27
28
-
29
- #undef DIAGNOSTIC
30
-
31
28
/*
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.
40
37
*
41
38
*The file descriptor stored in the relation cache (see RelationGetFile())
42
39
*is actually an index into the Md_fdvec array. -1 indicates not open.
@@ -67,7 +64,7 @@ static MdfdVec *Md_fdvec = (MdfdVec *) NULL;
67
64
static int Md_Free = -1 ;/* head of freelist of unused fdvec
68
65
* entries */
69
66
static 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 */
71
68
72
69
/* routines declared here */
73
70
static void mdclose_fd (int fd );
@@ -84,11 +81,8 @@ static BlockNumber _mdnblocks(File file, Size blcksz);
84
81
/*
85
82
*mdinit() -- Initialize private state for magnetic disk storage manager.
86
83
*
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.
92
86
*
93
87
*Returns SM_SUCCESS or SM_FAIL with errno set as appropriate.
94
88
*/
@@ -247,16 +241,13 @@ mdextend(Relation reln, BlockNumber blocknum, char *buffer)
247
241
248
242
#ifndef LET_OS_MANAGE_FILESIZE
249
243
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 );
254
245
#else
255
246
seekpos = (long ) (BLCKSZ * (blocknum ));
256
247
#endif
257
248
258
249
/*
259
- * Note: because caller obtained blocknum by callingmdnblocks , which
250
+ * Note: because caller obtained blocknum by calling_mdnblocks , which
260
251
* did a seek(SEEK_END), this seek is often redundant and will be
261
252
* optimized away by fd.c.It's not redundant, however, if there is a
262
253
* 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)
282
273
}
283
274
284
275
#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 ));
289
277
#endif
290
278
291
279
return SM_SUCCESS ;
@@ -335,11 +323,7 @@ mdopen(Relation reln)
335
323
Md_fdvec [vfd ].mdfd_flags = (uint16 )0 ;
336
324
#ifndef LET_OS_MANAGE_FILESIZE
337
325
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 ));
343
327
#endif
344
328
345
329
return vfd ;
@@ -348,7 +332,7 @@ mdopen(Relation reln)
348
332
/*
349
333
*mdclose() -- Close the specified relation, if it isn't closed already.
350
334
*
351
- *AND FREE fd vector! It may be re-used for otherrelation !
335
+ *AND FREE fd vector! It may be re-used for otherrelations !
352
336
*reln should be flushed from cache after closing !..
353
337
*
354
338
*Returns SM_SUCCESS or SM_FAIL with errno set as appropriate.
@@ -418,11 +402,7 @@ mdread(Relation reln, BlockNumber blocknum, char *buffer)
418
402
419
403
#ifndef LET_OS_MANAGE_FILESIZE
420
404
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 );
426
406
#else
427
407
seekpos = (long ) (BLCKSZ * (blocknum ));
428
408
#endif
@@ -466,10 +446,7 @@ mdwrite(Relation reln, BlockNumber blocknum, char *buffer)
466
446
467
447
#ifndef LET_OS_MANAGE_FILESIZE
468
448
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 );
473
450
#else
474
451
seekpos = (long ) (BLCKSZ * (blocknum ));
475
452
#endif
@@ -505,10 +482,7 @@ mdblindwrt(RelFileNode rnode,
505
482
506
483
#ifndef LET_OS_MANAGE_FILESIZE
507
484
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 );
512
486
#else
513
487
seekpos = (long ) (BLCKSZ * (blkno ));
514
488
#endif
@@ -722,8 +696,6 @@ mdcommit(void)
722
696
723
697
/*
724
698
*mdabort() -- Abort a transaction.
725
- *
726
- *Changes need not be forced to disk at transaction abort.
727
699
*/
728
700
int
729
701
mdabort (void )
@@ -748,7 +720,7 @@ mdsync(void)
748
720
}
749
721
750
722
/*
751
- *_fdvec_alloc () --grab a free (or new) md file descriptor vector.
723
+ *_fdvec_alloc() --Grab a free (or new) md file descriptor vector.
752
724
*/
753
725
static int
754
726
_fdvec_alloc (void )
@@ -802,7 +774,7 @@ _fdvec_alloc(void)
802
774
}
803
775
804
776
/*
805
- *_fdvec_free () -- free md file descriptor vector.
777
+ *_fdvec_free() -- free md file descriptor vector.
806
778
*
807
779
*/
808
780
static
@@ -853,19 +825,18 @@ _mdfd_openseg(Relation reln, BlockNumber segno, int oflags)
853
825
v -> mdfd_flags = (uint16 )0 ;
854
826
#ifndef LET_OS_MANAGE_FILESIZE
855
827
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 ));
861
829
#endif
862
830
863
831
/* all done */
864
832
return v ;
865
833
}
866
834
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
+ */
869
840
static int
870
841
_mdfd_getrelnfd (Relation reln )
871
842
{
@@ -882,8 +853,11 @@ _mdfd_getrelnfd(Relation reln)
882
853
return fd ;
883
854
}
884
855
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
+ */
887
861
static MdfdVec *
888
862
_mdfd_getseg (Relation reln ,BlockNumber blkno )
889
863
{
@@ -942,7 +916,6 @@ _mdfd_getseg(Relation reln, BlockNumber blkno)
942
916
*
943
917
* The return value is the kernel descriptor, or -1 on failure.
944
918
*/
945
-
946
919
static int
947
920
_mdfd_blind_getseg (RelFileNode rnode ,BlockNumber blkno )
948
921
{