7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.29 1998/02/26 04:36:16 momjian Exp $
10
+ * $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.30 1998/03/20 04:22:54 momjian Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -45,7 +45,9 @@ typedef struct _MdfdVec
45
45
uint16 mdfd_flags ; /* clean, dirty, free */
46
46
int mdfd_lstbcnt ; /* most recent block count */
47
47
int mdfd_nextFree ; /* next free vector */
48
+ #ifndef LET_OS_MANAGE_FILESIZE
48
49
struct _MdfdVec * mdfd_chain ;/* for large relations */
50
+ #endif
49
51
} MdfdVec ;
50
52
51
53
static int Nfds = 100 ;
@@ -70,9 +72,16 @@ static MemoryContext MdCxt;
70
72
* (((2 ** 23) / BLCKSZ) * (2 ** 8))
71
73
*
72
74
* 07 Jan 98 darrenk
75
+ *
76
+ * Now possibly let the OS handle it...
77
+ *
78
+ * 19 Mar 98 darrenk
79
+ *
73
80
*/
74
81
82
+ #ifndef LET_OS_MANAGE_FILESIZE
75
83
#define RELSEG_SIZE ((8388608 / BLCKSZ) * 256)
84
+ #endif
76
85
77
86
/* routines declared here */
78
87
static MdfdVec * _mdfd_openseg (Relation reln , int segno , int oflags );
@@ -159,7 +168,9 @@ mdcreate(Relation reln)
159
168
160
169
Md_fdvec [vfd ].mdfd_vfd = fd ;
161
170
Md_fdvec [vfd ].mdfd_flags = (uint16 ) 0 ;
171
+ #ifndef LET_OS_MANAGE_FILESIZE
162
172
Md_fdvec [vfd ].mdfd_chain = (MdfdVec * ) NULL ;
173
+ #endif
163
174
Md_fdvec [vfd ].mdfd_lstbcnt = 0 ;
164
175
165
176
return (vfd );
@@ -203,6 +214,7 @@ mdunlink(Relation reln)
203
214
Md_fdvec [fd ].mdfd_flags = (uint16 ) 0 ;
204
215
205
216
oldcxt = MemoryContextSwitchTo (MdCxt );
217
+ #ifndef LET_OS_MANAGE_FILESIZE
206
218
for (v = & Md_fdvec [fd ]; v != (MdfdVec * ) NULL ;)
207
219
{
208
220
FileUnlink (v -> mdfd_vfd );
@@ -212,6 +224,13 @@ mdunlink(Relation reln)
212
224
pfree (ov );
213
225
}
214
226
Md_fdvec [fd ].mdfd_chain = (MdfdVec * ) NULL ;
227
+ #else
228
+ v = & Md_fdvec [fd ];
229
+ if (v != (MdfdVec * ) NULL )
230
+ {
231
+ FileUnlink (v -> mdfd_vfd );
232
+ }
233
+ #endif
215
234
MemoryContextSwitchTo (oldcxt );
216
235
217
236
_fdvec_free (fd );
@@ -245,6 +264,7 @@ mdextend(Relation reln, char *buffer)
245
264
v -> mdfd_flags |= MDFD_DIRTY ;
246
265
247
266
/* try to keep the last block count current, though it's just a hint */
267
+ #ifndef LET_OS_MANAGE_FILESIZE
248
268
if ((v -> mdfd_lstbcnt = (++ nblocks % RELSEG_SIZE )) == 0 )
249
269
v -> mdfd_lstbcnt = RELSEG_SIZE ;
250
270
@@ -253,6 +273,9 @@ mdextend(Relation reln, char *buffer)
253
273
|| v -> mdfd_lstbcnt > RELSEG_SIZE )
254
274
elog (FATAL , "segment too big!" );
255
275
#endif
276
+ #else
277
+ v -> mdfd_lstbcnt = ++ nblocks ;
278
+ #endif
256
279
257
280
return (SM_SUCCESS );
258
281
}
@@ -281,12 +304,14 @@ mdopen(Relation reln)
281
304
282
305
Md_fdvec [vfd ].mdfd_vfd = fd ;
283
306
Md_fdvec [vfd ].mdfd_flags = (uint16 ) 0 ;
284
- Md_fdvec [vfd ].mdfd_chain = (MdfdVec * ) NULL ;
285
307
Md_fdvec [vfd ].mdfd_lstbcnt = _mdnblocks (fd , BLCKSZ );
308
+ #ifndef LET_OS_MANAGE_FILESIZE
309
+ Md_fdvec [vfd ].mdfd_chain = (MdfdVec * ) NULL ;
286
310
287
311
#ifdef DIAGNOSTIC
288
312
if (Md_fdvec [vfd ].mdfd_lstbcnt > RELSEG_SIZE )
289
313
elog (FATAL , "segment too big on relopen!" );
314
+ #endif
290
315
#endif
291
316
292
317
return (vfd );
@@ -311,6 +336,7 @@ mdclose(Relation reln)
311
336
fd = RelationGetFile (reln );
312
337
313
338
oldcxt = MemoryContextSwitchTo (MdCxt );
339
+ #ifndef LET_OS_MANAGE_FILESIZE
314
340
for (v = & Md_fdvec [fd ]; v != (MdfdVec * ) NULL ;)
315
341
{
316
342
/* if not closed already */
@@ -335,8 +361,28 @@ mdclose(Relation reln)
335
361
pfree (ov );
336
362
}
337
363
338
- MemoryContextSwitchTo (oldcxt );
339
364
Md_fdvec [fd ].mdfd_chain = (MdfdVec * ) NULL ;
365
+ #else
366
+ v = & Md_fdvec [fd ];
367
+ if (v != (MdfdVec * ) NULL )
368
+ {
369
+ if (v -> mdfd_vfd >= 0 )
370
+ {
371
+
372
+ /*
373
+ * We sync the file descriptor so that we don't need to reopen
374
+ * it at transaction commit to force changes to disk.
375
+ */
376
+
377
+ FileSync (v -> mdfd_vfd );
378
+ FileClose (v -> mdfd_vfd );
379
+
380
+ /* mark this file descriptor as clean in our private table */
381
+ v -> mdfd_flags &= ~MDFD_DIRTY ;
382
+ }
383
+ }
384
+ #endif
385
+ MemoryContextSwitchTo (oldcxt );
340
386
341
387
_fdvec_free (fd );
342
388
@@ -358,12 +404,16 @@ mdread(Relation reln, BlockNumber blocknum, char *buffer)
358
404
359
405
v = _mdfd_getseg (reln , blocknum , 0 );
360
406
407
+ #ifndef LET_OS_MANAGE_FILESIZE
361
408
seekpos = (long ) (BLCKSZ * (blocknum % RELSEG_SIZE ));
362
409
363
410
#ifdef DIAGNOSTIC
364
411
if (seekpos >= BLCKSZ * RELSEG_SIZE )
365
412
elog (FATAL , "seekpos too big!" );
366
413
#endif
414
+ #else
415
+ seekpos = (long ) (BLCKSZ * (blocknum ));
416
+ #endif
367
417
368
418
if (FileSeek (v -> mdfd_vfd , seekpos , SEEK_SET ) != seekpos )
369
419
{
@@ -400,11 +450,15 @@ mdwrite(Relation reln, BlockNumber blocknum, char *buffer)
400
450
401
451
v = _mdfd_getseg (reln , blocknum , 0 );
402
452
453
+ #ifndef LET_OS_MANAGE_FILESIZE
403
454
seekpos = (long ) (BLCKSZ * (blocknum % RELSEG_SIZE ));
404
455
#ifdef DIAGNOSTIC
405
456
if (seekpos >= BLCKSZ * RELSEG_SIZE )
406
457
elog (FATAL , "seekpos too big!" );
407
458
#endif
459
+ #else
460
+ seekpos = (long ) (BLCKSZ * (blocknum ));
461
+ #endif
408
462
409
463
if (FileSeek (v -> mdfd_vfd , seekpos , SEEK_SET ) != seekpos )
410
464
{
@@ -435,11 +489,15 @@ mdflush(Relation reln, BlockNumber blocknum, char *buffer)
435
489
436
490
v = _mdfd_getseg (reln , blocknum , 0 );
437
491
492
+ #ifndef LET_OS_MANAGE_FILESIZE
438
493
seekpos = (long ) (BLCKSZ * (blocknum % RELSEG_SIZE ));
439
494
#ifdef DIAGNOSTIC
440
495
if (seekpos >= BLCKSZ * RELSEG_SIZE )
441
496
elog (FATAL , "seekpos too big!" );
442
497
#endif
498
+ #else
499
+ seekpos = (long ) (BLCKSZ * (blocknum ));
500
+ #endif
443
501
444
502
if (FileSeek (v -> mdfd_vfd , seekpos , SEEK_SET ) != seekpos )
445
503
{
@@ -483,6 +541,8 @@ mdblindwrt(char *dbstr,
483
541
long seekpos ;
484
542
int status ;
485
543
char * path ;
544
+
545
+ #ifndef LET_OS_MANAGE_FILESIZE
486
546
int nchars ;
487
547
488
548
/* be sure we have enough space for the '.segno', if any */
@@ -535,12 +595,53 @@ mdblindwrt(char *dbstr,
535
595
sprintf (path , "%s%c%s.%d" , tmpPath , SEP_CHAR , relstr , segno );
536
596
pfree (tmpPath );
537
597
}
598
+ #else
599
+ /* construct the path to the file and open it */
600
+ /* system table? then put in system area... */
601
+ if (dbid == (Oid ) 0 )
602
+ {
603
+ path = (char * ) palloc (strlen (DataDir ) + sizeof (NameData ) + 2 );
604
+ sprintf (path , "%s/%s" , DataDir , relstr );
605
+ }
606
+ /* user table? then put in user database area... */
607
+ else if (dbid == MyDatabaseId )
608
+ {
609
+ extern char * DatabasePath ;
610
+
611
+ path = (char * ) palloc (strlen (DatabasePath ) + 2 * sizeof (NameData ) + 2 );
612
+ sprintf (path , "%s%c%s" , DatabasePath , SEP_CHAR , relstr );
613
+ }
614
+ else
615
+ /* this is work arround only !!! */
616
+ {
617
+ char dbpath [MAXPGPATH + 1 ];
618
+ Oid owner ,
619
+ id ;
620
+ char * tmpPath ;
621
+
622
+ GetRawDatabaseInfo (dbstr , & owner , & id , dbpath );
623
+
624
+ if (id != dbid )
625
+ elog (FATAL , "mdblindwrt: oid of db %s is not %u" , dbstr , dbid );
626
+ tmpPath = ExpandDatabasePath (dbpath );
627
+ if (tmpPath == NULL )
628
+ elog (FATAL , "mdblindwrt: can't expand path for db %s" , dbstr );
629
+ path = (char * ) palloc (strlen (tmpPath ) + 2 * sizeof (NameData ) + 2 );
630
+ sprintf (path , "%s%c%s" , tmpPath , SEP_CHAR , relstr );
631
+ pfree (tmpPath );
632
+ }
633
+ #endif
538
634
539
635
if ((fd = open (path , O_RDWR , 0600 )) < 0 )
540
636
return (SM_FAIL );
541
637
542
638
/* seek to the right spot */
639
+ #ifndef LET_OS_MANAGE_FILESIZE
543
640
seekpos = (long ) (BLCKSZ * (blkno % RELSEG_SIZE ));
641
+ #else
642
+ seekpos = (long ) (BLCKSZ * (blkno ));
643
+ #endif
644
+
544
645
if (lseek (fd , seekpos , SEEK_SET ) != seekpos )
545
646
{
546
647
close (fd );
@@ -577,6 +678,7 @@ mdnblocks(Relation reln)
577
678
fd = RelationGetFile (reln );
578
679
v = & Md_fdvec [fd ];
579
680
681
+ #ifndef LET_OS_MANAGE_FILESIZE
580
682
#ifdef DIAGNOSTIC
581
683
if (_mdnblocks (v -> mdfd_vfd , BLCKSZ ) > RELSEG_SIZE )
582
684
elog (FATAL , "segment too big in getseg!" );
@@ -607,6 +709,9 @@ mdnblocks(Relation reln)
607
709
return ((segno * RELSEG_SIZE ) + nblocks );
608
710
}
609
711
}
712
+ #else
713
+ return (_mdnblocks (v -> mdfd_vfd , BLCKSZ ));
714
+ #endif
610
715
}
611
716
612
717
/*
@@ -619,6 +724,8 @@ mdtruncate(Relation reln, int nblocks)
619
724
{
620
725
int fd ;
621
726
MdfdVec * v ;
727
+
728
+ #ifndef LET_OS_MANAGE_FILESIZE
622
729
int curnblk ;
623
730
624
731
curnblk = mdnblocks (reln );
@@ -628,6 +735,7 @@ mdtruncate(Relation reln, int nblocks)
628
735
& (reln -> rd_rel -> relname .data [0 ]));
629
736
return (curnblk );
630
737
}
738
+ #endif
631
739
632
740
fd = RelationGetFile (reln );
633
741
v = & Md_fdvec [fd ];
@@ -657,7 +765,12 @@ mdcommit()
657
765
658
766
for (i = 0 ; i < CurFd ; i ++ )
659
767
{
768
+ #ifndef LET_OS_MANAGE_FILESIZE
660
769
for (v = & Md_fdvec [i ]; v != (MdfdVec * ) NULL ; v = v -> mdfd_chain )
770
+ #else
771
+ v = & Md_fdvec [i ];
772
+ if (v != (MdfdVec * ) NULL )
773
+ #endif
661
774
{
662
775
if (v -> mdfd_flags & MDFD_DIRTY )
663
776
{
@@ -686,7 +799,12 @@ mdabort()
686
799
687
800
for (i = 0 ; i < CurFd ; i ++ )
688
801
{
802
+ #ifndef LET_OS_MANAGE_FILESIZE
689
803
for (v = & Md_fdvec [i ]; v != (MdfdVec * ) NULL ; v = v -> mdfd_chain )
804
+ #else
805
+ v = & Md_fdvec [i ];
806
+ if (v != (MdfdVec * ) NULL )
807
+ #endif
690
808
{
691
809
v -> mdfd_flags &= ~MDFD_DIRTY ;
692
810
}
@@ -812,12 +930,14 @@ _mdfd_openseg(Relation reln, int segno, int oflags)
812
930
/* fill the entry */
813
931
v -> mdfd_vfd = fd ;
814
932
v -> mdfd_flags = (uint16 ) 0 ;
815
- v -> mdfd_chain = (MdfdVec * ) NULL ;
816
933
v -> mdfd_lstbcnt = _mdnblocks (fd , BLCKSZ );
934
+ #ifndef LET_OS_MANAGE_FILESIZE
935
+ v -> mdfd_chain = (MdfdVec * ) NULL ;
817
936
818
937
#ifdef DIAGNOSTIC
819
938
if (v -> mdfd_lstbcnt > RELSEG_SIZE )
820
939
elog (FATAL , "segment too big on open!" );
940
+ #endif
821
941
#endif
822
942
823
943
/* all done */
@@ -841,6 +961,7 @@ _mdfd_getseg(Relation reln, int blkno, int oflag)
841
961
reln -> rd_fd = fd ;
842
962
}
843
963
964
+ #ifndef LET_OS_MANAGE_FILESIZE
844
965
for (v = & Md_fdvec [fd ], segno = blkno / RELSEG_SIZE , i = 1 ;
845
966
segno > 0 ;
846
967
i ++ , segno -- )
@@ -856,6 +977,9 @@ _mdfd_getseg(Relation reln, int blkno, int oflag)
856
977
}
857
978
v = v -> mdfd_chain ;
858
979
}
980
+ #else
981
+ v = & Md_fdvec [fd ];
982
+ #endif
859
983
860
984
return (v );
861
985
}
0 commit comments