Skip to content

Commit 922c83f

Browse files
committed
OK...here is a patch that will cause the magnetic disk storage
manager to not try to split files in 2 gig chunks. It will just try to get another block. If applied, everything is just as before. But if LET_OS_MANAGE_FILESIZE is defined, the chaining disappears and the file just keeps on going, and going, and going, til the OS barfs. Darren King
1 parent 5920345 commit 922c83f

File tree

1 file changed

+128
-4
lines changed
  • src/backend/storage/smgr

1 file changed

+128
-4
lines changed

src/backend/storage/smgr/md.c

Lines changed: 128 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* 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 $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -45,7 +45,9 @@ typedef struct _MdfdVec
4545
uint16 mdfd_flags; /* clean, dirty, free */
4646
int mdfd_lstbcnt; /* most recent block count */
4747
int mdfd_nextFree; /* next free vector */
48+
#ifndef LET_OS_MANAGE_FILESIZE
4849
struct _MdfdVec *mdfd_chain;/* for large relations */
50+
#endif
4951
} MdfdVec;
5052

5153
static int Nfds = 100;
@@ -70,9 +72,16 @@ static MemoryContext MdCxt;
7072
* (((2 ** 23) / BLCKSZ) * (2 ** 8))
7173
*
7274
* 07 Jan 98 darrenk
75+
*
76+
* Now possibly let the OS handle it...
77+
*
78+
* 19 Mar 98 darrenk
79+
*
7380
*/
7481

82+
#ifndef LET_OS_MANAGE_FILESIZE
7583
#define RELSEG_SIZE ((8388608 / BLCKSZ) * 256)
84+
#endif
7685

7786
/* routines declared here */
7887
static MdfdVec *_mdfd_openseg(Relation reln, int segno, int oflags);
@@ -159,7 +168,9 @@ mdcreate(Relation reln)
159168

160169
Md_fdvec[vfd].mdfd_vfd = fd;
161170
Md_fdvec[vfd].mdfd_flags = (uint16) 0;
171+
#ifndef LET_OS_MANAGE_FILESIZE
162172
Md_fdvec[vfd].mdfd_chain = (MdfdVec *) NULL;
173+
#endif
163174
Md_fdvec[vfd].mdfd_lstbcnt = 0;
164175

165176
return (vfd);
@@ -203,6 +214,7 @@ mdunlink(Relation reln)
203214
Md_fdvec[fd].mdfd_flags = (uint16) 0;
204215

205216
oldcxt = MemoryContextSwitchTo(MdCxt);
217+
#ifndef LET_OS_MANAGE_FILESIZE
206218
for (v = &Md_fdvec[fd]; v != (MdfdVec *) NULL;)
207219
{
208220
FileUnlink(v->mdfd_vfd);
@@ -212,6 +224,13 @@ mdunlink(Relation reln)
212224
pfree(ov);
213225
}
214226
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
215234
MemoryContextSwitchTo(oldcxt);
216235

217236
_fdvec_free(fd);
@@ -245,6 +264,7 @@ mdextend(Relation reln, char *buffer)
245264
v->mdfd_flags |= MDFD_DIRTY;
246265

247266
/* try to keep the last block count current, though it's just a hint */
267+
#ifndef LET_OS_MANAGE_FILESIZE
248268
if ((v->mdfd_lstbcnt = (++nblocks % RELSEG_SIZE)) == 0)
249269
v->mdfd_lstbcnt = RELSEG_SIZE;
250270

@@ -253,6 +273,9 @@ mdextend(Relation reln, char *buffer)
253273
|| v->mdfd_lstbcnt > RELSEG_SIZE)
254274
elog(FATAL, "segment too big!");
255275
#endif
276+
#else
277+
v->mdfd_lstbcnt = ++nblocks;
278+
#endif
256279

257280
return (SM_SUCCESS);
258281
}
@@ -281,12 +304,14 @@ mdopen(Relation reln)
281304

282305
Md_fdvec[vfd].mdfd_vfd = fd;
283306
Md_fdvec[vfd].mdfd_flags = (uint16) 0;
284-
Md_fdvec[vfd].mdfd_chain = (MdfdVec *) NULL;
285307
Md_fdvec[vfd].mdfd_lstbcnt = _mdnblocks(fd, BLCKSZ);
308+
#ifndef LET_OS_MANAGE_FILESIZE
309+
Md_fdvec[vfd].mdfd_chain = (MdfdVec *) NULL;
286310

287311
#ifdef DIAGNOSTIC
288312
if (Md_fdvec[vfd].mdfd_lstbcnt > RELSEG_SIZE)
289313
elog(FATAL, "segment too big on relopen!");
314+
#endif
290315
#endif
291316

292317
return (vfd);
@@ -311,6 +336,7 @@ mdclose(Relation reln)
311336
fd = RelationGetFile(reln);
312337

313338
oldcxt = MemoryContextSwitchTo(MdCxt);
339+
#ifndef LET_OS_MANAGE_FILESIZE
314340
for (v = &Md_fdvec[fd]; v != (MdfdVec *) NULL;)
315341
{
316342
/* if not closed already */
@@ -335,8 +361,28 @@ mdclose(Relation reln)
335361
pfree(ov);
336362
}
337363

338-
MemoryContextSwitchTo(oldcxt);
339364
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);
340386

341387
_fdvec_free(fd);
342388

@@ -358,12 +404,16 @@ mdread(Relation reln, BlockNumber blocknum, char *buffer)
358404

359405
v = _mdfd_getseg(reln, blocknum, 0);
360406

407+
#ifndef LET_OS_MANAGE_FILESIZE
361408
seekpos = (long) (BLCKSZ * (blocknum % RELSEG_SIZE));
362409

363410
#ifdef DIAGNOSTIC
364411
if (seekpos >= BLCKSZ * RELSEG_SIZE)
365412
elog(FATAL, "seekpos too big!");
366413
#endif
414+
#else
415+
seekpos = (long) (BLCKSZ * (blocknum));
416+
#endif
367417

368418
if (FileSeek(v->mdfd_vfd, seekpos, SEEK_SET) != seekpos)
369419
{
@@ -400,11 +450,15 @@ mdwrite(Relation reln, BlockNumber blocknum, char *buffer)
400450

401451
v = _mdfd_getseg(reln, blocknum, 0);
402452

453+
#ifndef LET_OS_MANAGE_FILESIZE
403454
seekpos = (long) (BLCKSZ * (blocknum % RELSEG_SIZE));
404455
#ifdef DIAGNOSTIC
405456
if (seekpos >= BLCKSZ * RELSEG_SIZE)
406457
elog(FATAL, "seekpos too big!");
407458
#endif
459+
#else
460+
seekpos = (long) (BLCKSZ * (blocknum));
461+
#endif
408462

409463
if (FileSeek(v->mdfd_vfd, seekpos, SEEK_SET) != seekpos)
410464
{
@@ -435,11 +489,15 @@ mdflush(Relation reln, BlockNumber blocknum, char *buffer)
435489

436490
v = _mdfd_getseg(reln, blocknum, 0);
437491

492+
#ifndef LET_OS_MANAGE_FILESIZE
438493
seekpos = (long) (BLCKSZ * (blocknum % RELSEG_SIZE));
439494
#ifdef DIAGNOSTIC
440495
if (seekpos >= BLCKSZ * RELSEG_SIZE)
441496
elog(FATAL, "seekpos too big!");
442497
#endif
498+
#else
499+
seekpos = (long) (BLCKSZ * (blocknum));
500+
#endif
443501

444502
if (FileSeek(v->mdfd_vfd, seekpos, SEEK_SET) != seekpos)
445503
{
@@ -483,6 +541,8 @@ mdblindwrt(char *dbstr,
483541
long seekpos;
484542
int status;
485543
char *path;
544+
545+
#ifndef LET_OS_MANAGE_FILESIZE
486546
int nchars;
487547

488548
/* be sure we have enough space for the '.segno', if any */
@@ -535,12 +595,53 @@ mdblindwrt(char *dbstr,
535595
sprintf(path, "%s%c%s.%d", tmpPath, SEP_CHAR, relstr, segno);
536596
pfree(tmpPath);
537597
}
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
538634

539635
if ((fd = open(path, O_RDWR, 0600)) < 0)
540636
return (SM_FAIL);
541637

542638
/* seek to the right spot */
639+
#ifndef LET_OS_MANAGE_FILESIZE
543640
seekpos = (long) (BLCKSZ * (blkno % RELSEG_SIZE));
641+
#else
642+
seekpos = (long) (BLCKSZ * (blkno));
643+
#endif
644+
544645
if (lseek(fd, seekpos, SEEK_SET) != seekpos)
545646
{
546647
close(fd);
@@ -577,6 +678,7 @@ mdnblocks(Relation reln)
577678
fd = RelationGetFile(reln);
578679
v = &Md_fdvec[fd];
579680

681+
#ifndef LET_OS_MANAGE_FILESIZE
580682
#ifdef DIAGNOSTIC
581683
if (_mdnblocks(v->mdfd_vfd, BLCKSZ) > RELSEG_SIZE)
582684
elog(FATAL, "segment too big in getseg!");
@@ -607,6 +709,9 @@ mdnblocks(Relation reln)
607709
return ((segno * RELSEG_SIZE) + nblocks);
608710
}
609711
}
712+
#else
713+
return (_mdnblocks(v->mdfd_vfd, BLCKSZ));
714+
#endif
610715
}
611716

612717
/*
@@ -619,6 +724,8 @@ mdtruncate(Relation reln, int nblocks)
619724
{
620725
int fd;
621726
MdfdVec *v;
727+
728+
#ifndef LET_OS_MANAGE_FILESIZE
622729
int curnblk;
623730

624731
curnblk = mdnblocks(reln);
@@ -628,6 +735,7 @@ mdtruncate(Relation reln, int nblocks)
628735
&(reln->rd_rel->relname.data[0]));
629736
return (curnblk);
630737
}
738+
#endif
631739

632740
fd = RelationGetFile(reln);
633741
v = &Md_fdvec[fd];
@@ -657,7 +765,12 @@ mdcommit()
657765

658766
for (i = 0; i < CurFd; i++)
659767
{
768+
#ifndef LET_OS_MANAGE_FILESIZE
660769
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
661774
{
662775
if (v->mdfd_flags & MDFD_DIRTY)
663776
{
@@ -686,7 +799,12 @@ mdabort()
686799

687800
for (i = 0; i < CurFd; i++)
688801
{
802+
#ifndef LET_OS_MANAGE_FILESIZE
689803
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
690808
{
691809
v->mdfd_flags &= ~MDFD_DIRTY;
692810
}
@@ -812,12 +930,14 @@ _mdfd_openseg(Relation reln, int segno, int oflags)
812930
/* fill the entry */
813931
v->mdfd_vfd = fd;
814932
v->mdfd_flags = (uint16) 0;
815-
v->mdfd_chain = (MdfdVec *) NULL;
816933
v->mdfd_lstbcnt = _mdnblocks(fd, BLCKSZ);
934+
#ifndef LET_OS_MANAGE_FILESIZE
935+
v->mdfd_chain = (MdfdVec *) NULL;
817936

818937
#ifdef DIAGNOSTIC
819938
if (v->mdfd_lstbcnt > RELSEG_SIZE)
820939
elog(FATAL, "segment too big on open!");
940+
#endif
821941
#endif
822942

823943
/* all done */
@@ -841,6 +961,7 @@ _mdfd_getseg(Relation reln, int blkno, int oflag)
841961
reln->rd_fd = fd;
842962
}
843963

964+
#ifndef LET_OS_MANAGE_FILESIZE
844965
for (v = &Md_fdvec[fd], segno = blkno / RELSEG_SIZE, i = 1;
845966
segno > 0;
846967
i++, segno--)
@@ -856,6 +977,9 @@ _mdfd_getseg(Relation reln, int blkno, int oflag)
856977
}
857978
v = v->mdfd_chain;
858979
}
980+
#else
981+
v = &Md_fdvec[fd];
982+
#endif
859983

860984
return (v);
861985
}

0 commit comments

Comments
 (0)