8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.148 2009/06/26 20:29:04 tgl Exp $
11
+ * $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.149 2009/08/05 18:01:54 heikki Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -160,6 +160,8 @@ static void register_dirty_segment(SMgrRelation reln, ForkNumber forknum,
160
160
MdfdVec * seg );
161
161
static void register_unlink (RelFileNode rnode );
162
162
static MdfdVec * _fdvec_alloc (void );
163
+ static char * _mdfd_segpath (SMgrRelation reln , ForkNumber forknum ,
164
+ BlockNumber segno );
163
165
static MdfdVec * _mdfd_openseg (SMgrRelation reln , ForkNumber forkno ,
164
166
BlockNumber segno , int oflags );
165
167
static MdfdVec * _mdfd_getseg (SMgrRelation reln , ForkNumber forkno ,
@@ -273,7 +275,7 @@ mdcreate(SMgrRelation reln, ForkNumber forkNum, bool isRedo)
273
275
errno = save_errno ;
274
276
ereport (ERROR ,
275
277
(errcode_for_file_access (),
276
- errmsg ("could not create relation %s : %m" , path )));
278
+ errmsg ("could not create file \"%s\" : %m" , path )));
277
279
}
278
280
}
279
281
@@ -336,7 +338,16 @@ mdunlink(RelFileNode rnode, ForkNumber forkNum, bool isRedo)
336
338
* Delete or truncate the first segment.
337
339
*/
338
340
if (isRedo || forkNum != MAIN_FORKNUM )
341
+ {
339
342
ret = unlink (path );
343
+ if (ret < 0 )
344
+ {
345
+ if (!isRedo || errno != ENOENT )
346
+ ereport (WARNING ,
347
+ (errcode_for_file_access (),
348
+ errmsg ("could not remove file \"%s\": %m" , path )));
349
+ }
350
+ }
340
351
else
341
352
{
342
353
/* truncate(2) would be easier here, but Windows hasn't got it */
@@ -354,19 +365,16 @@ mdunlink(RelFileNode rnode, ForkNumber forkNum, bool isRedo)
354
365
}
355
366
else
356
367
ret = -1 ;
357
- }
358
- if (ret < 0 )
359
- {
360
- if (!isRedo || errno != ENOENT )
368
+ if (ret < 0 && errno != ENOENT )
361
369
ereport (WARNING ,
362
370
(errcode_for_file_access (),
363
- errmsg ("could not remove relation %s : %m" , path )));
371
+ errmsg ("could not truncate file \"%s\" : %m" , path )));
364
372
}
365
373
366
374
/*
367
375
* Delete any additional segments.
368
376
*/
369
- else
377
+ if ( ret >= 0 )
370
378
{
371
379
char * segpath = (char * ) palloc (strlen (path ) + 12 );
372
380
BlockNumber segno ;
@@ -384,8 +392,7 @@ mdunlink(RelFileNode rnode, ForkNumber forkNum, bool isRedo)
384
392
if (errno != ENOENT )
385
393
ereport (WARNING ,
386
394
(errcode_for_file_access (),
387
- errmsg ("could not remove segment %u of relation %s: %m" ,
388
- segno , path )));
395
+ errmsg ("could not remove file \"%s\": %m" , segpath )));
389
396
break ;
390
397
}
391
398
}
@@ -429,7 +436,7 @@ mdextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
429
436
if (blocknum == InvalidBlockNumber )
430
437
ereport (ERROR ,
431
438
(errcode (ERRCODE_PROGRAM_LIMIT_EXCEEDED ),
432
- errmsg ("cannot extend relation %s beyond %u blocks" ,
439
+ errmsg ("cannot extend file \"%s\" beyond %u blocks" ,
433
440
relpath (reln -> smgr_rnode , forknum ),
434
441
InvalidBlockNumber )));
435
442
@@ -451,23 +458,22 @@ mdextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
451
458
if (FileSeek (v -> mdfd_vfd , seekpos , SEEK_SET ) != seekpos )
452
459
ereport (ERROR ,
453
460
(errcode_for_file_access (),
454
- errmsg ("could not seek to block %u of relation %s: %m" ,
455
- blocknum ,
456
- relpath (reln -> smgr_rnode , forknum ))));
461
+ errmsg ("could not seek to block %u in file \"%s\": %m" ,
462
+ blocknum , FilePathName (v -> mdfd_vfd ))));
457
463
458
464
if ((nbytes = FileWrite (v -> mdfd_vfd , buffer , BLCKSZ )) != BLCKSZ )
459
465
{
460
466
if (nbytes < 0 )
461
467
ereport (ERROR ,
462
468
(errcode_for_file_access (),
463
- errmsg ("could not extend relation %s : %m" ,
464
- relpath ( reln -> smgr_rnode , forknum )),
469
+ errmsg ("could not extend file \"%s\" : %m" ,
470
+ FilePathName ( v -> mdfd_vfd )),
465
471
errhint ("Check free disk space." )));
466
472
/* short write: complain appropriately */
467
473
ereport (ERROR ,
468
474
(errcode (ERRCODE_DISK_FULL ),
469
- errmsg ("could not extend relation %s : wrote only %d of %d bytes at block %u" ,
470
- relpath ( reln -> smgr_rnode , forknum ),
475
+ errmsg ("could not extend file \"%s\" : wrote only %d of %d bytes at block %u" ,
476
+ FilePathName ( v -> mdfd_vfd ),
471
477
nbytes , BLCKSZ , blocknum ),
472
478
errhint ("Check free disk space." )));
473
479
}
@@ -523,7 +529,7 @@ mdopen(SMgrRelation reln, ForkNumber forknum, ExtensionBehavior behavior)
523
529
}
524
530
ereport (ERROR ,
525
531
(errcode_for_file_access (),
526
- errmsg ("could not open relation %s : %m" , path )));
532
+ errmsg ("could not open file \"%s\" : %m" , path )));
527
533
}
528
534
}
529
535
@@ -612,8 +618,8 @@ mdread(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
612
618
if (FileSeek (v -> mdfd_vfd , seekpos , SEEK_SET ) != seekpos )
613
619
ereport (ERROR ,
614
620
(errcode_for_file_access (),
615
- errmsg ("could not seek to block %u of relation %s : %m" ,
616
- blocknum , relpath ( reln -> smgr_rnode , forknum ))));
621
+ errmsg ("could not seek to block %u in file \"%s\" : %m" ,
622
+ blocknum , FilePathName ( v -> mdfd_vfd ))));
617
623
618
624
nbytes = FileRead (v -> mdfd_vfd , buffer , BLCKSZ );
619
625
@@ -629,8 +635,8 @@ mdread(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
629
635
if (nbytes < 0 )
630
636
ereport (ERROR ,
631
637
(errcode_for_file_access (),
632
- errmsg ("could not read block %u of relation %s : %m" ,
633
- blocknum , relpath ( reln -> smgr_rnode , forknum ))));
638
+ errmsg ("could not read block %u in file \"%s\" : %m" ,
639
+ blocknum , FilePathName ( v -> mdfd_vfd ))));
634
640
635
641
/*
636
642
* Short read: we are at or past EOF, or we read a partial block at
@@ -645,8 +651,8 @@ mdread(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
645
651
else
646
652
ereport (ERROR ,
647
653
(errcode (ERRCODE_DATA_CORRUPTED ),
648
- errmsg ("could not read block %u of relation %s : read only %d of %d bytes" ,
649
- blocknum , relpath ( reln -> smgr_rnode , forknum ),
654
+ errmsg ("could not read block %u in file \"%s\" : read only %d of %d bytes" ,
655
+ blocknum , FilePathName ( v -> mdfd_vfd ),
650
656
nbytes , BLCKSZ )));
651
657
}
652
658
}
@@ -685,8 +691,8 @@ mdwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
685
691
if (FileSeek (v -> mdfd_vfd , seekpos , SEEK_SET ) != seekpos )
686
692
ereport (ERROR ,
687
693
(errcode_for_file_access (),
688
- errmsg ("could not seek to block %u of relation %s : %m" ,
689
- blocknum , relpath ( reln -> smgr_rnode , forknum ))));
694
+ errmsg ("could not seek to block %u in file \"%s\" : %m" ,
695
+ blocknum , FilePathName ( v -> mdfd_vfd ))));
690
696
691
697
nbytes = FileWrite (v -> mdfd_vfd , buffer , BLCKSZ );
692
698
@@ -702,14 +708,14 @@ mdwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
702
708
if (nbytes < 0 )
703
709
ereport (ERROR ,
704
710
(errcode_for_file_access (),
705
- errmsg ("could not write block %u of relation %s : %m" ,
706
- blocknum , relpath ( reln -> smgr_rnode , forknum ))));
711
+ errmsg ("could not write block %u in file \"%s\" : %m" ,
712
+ blocknum , FilePathName ( v -> mdfd_vfd ))));
707
713
/* short write: complain appropriately */
708
714
ereport (ERROR ,
709
715
(errcode (ERRCODE_DISK_FULL ),
710
- errmsg ("could not write block %u of relation %s : wrote only %d of %d bytes" ,
716
+ errmsg ("could not write block %u in file \"%s\" : wrote only %d of %d bytes" ,
711
717
blocknum ,
712
- relpath ( reln -> smgr_rnode , forknum ),
718
+ FilePathName ( v -> mdfd_vfd ),
713
719
nbytes , BLCKSZ ),
714
720
errhint ("Check free disk space." )));
715
721
}
@@ -776,9 +782,8 @@ mdnblocks(SMgrRelation reln, ForkNumber forknum)
776
782
if (v -> mdfd_chain == NULL )
777
783
ereport (ERROR ,
778
784
(errcode_for_file_access (),
779
- errmsg ("could not open segment %u of relation %s: %m" ,
780
- segno ,
781
- relpath (reln -> smgr_rnode , forknum ))));
785
+ errmsg ("could not open file \"%s\": %m" ,
786
+ _mdfd_segpath (reln , forknum , segno ))));
782
787
}
783
788
784
789
v = v -> mdfd_chain ;
@@ -807,7 +812,7 @@ mdtruncate(SMgrRelation reln, ForkNumber forknum, BlockNumber nblocks,
807
812
if (InRecovery )
808
813
return ;
809
814
ereport (ERROR ,
810
- (errmsg ("could not truncate relation %s to %u blocks: it's only %u blocks now" ,
815
+ (errmsg ("could not truncate file \"%s\" to %u blocks: it's only %u blocks now" ,
811
816
relpath (reln -> smgr_rnode , forknum ),
812
817
nblocks , curnblk )));
813
818
}
@@ -831,9 +836,9 @@ mdtruncate(SMgrRelation reln, ForkNumber forknum, BlockNumber nblocks,
831
836
if (FileTruncate (v -> mdfd_vfd , 0 ) < 0 )
832
837
ereport (ERROR ,
833
838
(errcode_for_file_access (),
834
- errmsg ("could not truncate relation %s to %u blocks : %m" ,
835
- relpath ( reln -> smgr_rnode , forknum ),
836
- nblocks )));
839
+ errmsg ("could not truncate file \"%s\" : %m" ,
840
+ FilePathName ( v -> mdfd_vfd ))));
841
+
837
842
if (!isTemp )
838
843
register_dirty_segment (reln , forknum , v );
839
844
v = v -> mdfd_chain ;
@@ -856,8 +861,8 @@ mdtruncate(SMgrRelation reln, ForkNumber forknum, BlockNumber nblocks,
856
861
if (FileTruncate (v -> mdfd_vfd , (off_t ) lastsegblocks * BLCKSZ ) < 0 )
857
862
ereport (ERROR ,
858
863
(errcode_for_file_access (),
859
- errmsg ("could not truncate relation %s to %u blocks: %m" ,
860
- relpath ( reln -> smgr_rnode , forknum ),
864
+ errmsg ("could not truncate file \"%s\" to %u blocks: %m" ,
865
+ FilePathName ( v -> mdfd_vfd ),
861
866
nblocks )));
862
867
if (!isTemp )
863
868
register_dirty_segment (reln , forknum , v );
@@ -901,9 +906,8 @@ mdimmedsync(SMgrRelation reln, ForkNumber forknum)
901
906
if (FileSync (v -> mdfd_vfd ) < 0 )
902
907
ereport (ERROR ,
903
908
(errcode_for_file_access (),
904
- errmsg ("could not fsync segment %u of relation %s: %m" ,
905
- v -> mdfd_segno ,
906
- relpath (reln -> smgr_rnode , forknum ))));
909
+ errmsg ("could not fsync file \"%s\": %m" ,
910
+ FilePathName (v -> mdfd_vfd ))));
907
911
v = v -> mdfd_chain ;
908
912
}
909
913
}
@@ -1070,18 +1074,18 @@ mdsync(void)
1070
1074
* Don't see one at the moment, but easy to change the test
1071
1075
* here if so.
1072
1076
*/
1073
- path = relpath (entry -> tag .rnode , entry -> tag .forknum );
1077
+ path = _mdfd_segpath (reln , entry -> tag .forknum ,
1078
+ entry -> tag .segno );
1074
1079
if (!FILE_POSSIBLY_DELETED (errno ) ||
1075
1080
failures > 0 )
1076
1081
ereport (ERROR ,
1077
1082
(errcode_for_file_access (),
1078
- errmsg ("could not fsync segment %u of relation %s: %m" ,
1079
- entry -> tag .segno , path )));
1083
+ errmsg ("could not fsync file \"%s\": %m" , path )));
1080
1084
else
1081
1085
ereport (DEBUG1 ,
1082
1086
(errcode_for_file_access (),
1083
- errmsg ("could not fsync segment %u of relation %s but retrying: %m" ,
1084
- entry -> tag . segno , path )));
1087
+ errmsg ("could not fsync file \"%s\" but retrying: %m" ,
1088
+ path )));
1085
1089
pfree (path );
1086
1090
1087
1091
/*
@@ -1185,7 +1189,7 @@ mdpostckpt(void)
1185
1189
if (errno != ENOENT )
1186
1190
ereport (WARNING ,
1187
1191
(errcode_for_file_access (),
1188
- errmsg ("could not remove relation %s : %m" , path )));
1192
+ errmsg ("could not remove file \"%s\" : %m" , path )));
1189
1193
}
1190
1194
pfree (path );
1191
1195
@@ -1219,9 +1223,8 @@ register_dirty_segment(SMgrRelation reln, ForkNumber forknum, MdfdVec *seg)
1219
1223
if (FileSync (seg -> mdfd_vfd ) < 0 )
1220
1224
ereport (ERROR ,
1221
1225
(errcode_for_file_access (),
1222
- errmsg ("could not fsync segment %u of relation %s: %m" ,
1223
- seg -> mdfd_segno ,
1224
- relpath (reln -> smgr_rnode , forknum ))));
1226
+ errmsg ("could not fsync file \"%s\": %m" ,
1227
+ FilePathName (seg -> mdfd_vfd ))));
1225
1228
}
1226
1229
}
1227
1230
@@ -1456,17 +1459,14 @@ _fdvec_alloc(void)
1456
1459
}
1457
1460
1458
1461
/*
1459
- * Open the specified segment of the relation,
1460
- * and make a MdfdVec object for it. Returns NULL on failure .
1462
+ * Return the filename for the specified segment of the relation. The
1463
+ * returned string is palloc'd .
1461
1464
*/
1462
- static MdfdVec *
1463
- _mdfd_openseg (SMgrRelation reln , ForkNumber forknum , BlockNumber segno ,
1464
- int oflags )
1465
+ static char *
1466
+ _mdfd_segpath (SMgrRelation reln , ForkNumber forknum , BlockNumber segno )
1465
1467
{
1466
- MdfdVec * v ;
1467
- int fd ;
1468
- char * path ,
1469
- * fullpath ;
1468
+ char * path ,
1469
+ * fullpath ;
1470
1470
1471
1471
path = relpath (reln -> smgr_rnode , forknum );
1472
1472
@@ -1480,6 +1480,23 @@ _mdfd_openseg(SMgrRelation reln, ForkNumber forknum, BlockNumber segno,
1480
1480
else
1481
1481
fullpath = path ;
1482
1482
1483
+ return fullpath ;
1484
+ }
1485
+
1486
+ /*
1487
+ * Open the specified segment of the relation,
1488
+ * and make a MdfdVec object for it. Returns NULL on failure.
1489
+ */
1490
+ static MdfdVec *
1491
+ _mdfd_openseg (SMgrRelation reln , ForkNumber forknum , BlockNumber segno ,
1492
+ int oflags )
1493
+ {
1494
+ MdfdVec * v ;
1495
+ int fd ;
1496
+ char * fullpath ;
1497
+
1498
+ fullpath = _mdfd_segpath (reln , forknum , segno );
1499
+
1483
1500
/* open the file */
1484
1501
fd = PathNameOpenFile (fullpath , O_RDWR | PG_BINARY | oflags , 0600 );
1485
1502
@@ -1566,9 +1583,8 @@ _mdfd_getseg(SMgrRelation reln, ForkNumber forknum, BlockNumber blkno,
1566
1583
return NULL ;
1567
1584
ereport (ERROR ,
1568
1585
(errcode_for_file_access (),
1569
- errmsg ("could not open segment %u of relation %s (target block %u): %m" ,
1570
- nextsegno ,
1571
- relpath (reln -> smgr_rnode , forknum ),
1586
+ errmsg ("could not open file \"%s\" (target block %u): %m" ,
1587
+ _mdfd_segpath (reln , forknum , nextsegno ),
1572
1588
blkno )));
1573
1589
}
1574
1590
}
@@ -1589,8 +1605,8 @@ _mdnblocks(SMgrRelation reln, ForkNumber forknum, MdfdVec *seg)
1589
1605
if (len < 0 )
1590
1606
ereport (ERROR ,
1591
1607
(errcode_for_file_access (),
1592
- errmsg ("could not seek to end of segment %u of relation %s : %m" ,
1593
- seg -> mdfd_segno , relpath ( reln -> smgr_rnode , forknum ))));
1608
+ errmsg ("could not seek to end of file \"%s\" : %m" ,
1609
+ FilePathName ( seg -> mdfd_vfd ))));
1594
1610
/* note that this calculation will ignore any partial block at EOF */
1595
1611
return (BlockNumber ) (len / BLCKSZ );
1596
1612
}
0 commit comments