@@ -1339,46 +1339,56 @@ PathNameOpenFile(FileName fileName, int fileFlags, int fileMode)
1339
1339
/* Close excess kernel FDs. */
1340
1340
ReleaseLruFiles ();
1341
1341
1342
- vfdP -> fd = BasicOpenFile (fileName , fileFlags , fileMode );
1343
-
1344
- if (vfdP -> fd < 0 )
1345
- {
1346
- save_errno = errno ;
1347
- io_error :
1348
- FreeVfd (file );
1349
- free (fnamecopy );
1350
- errno = save_errno ;
1351
- return -1 ;
1352
- }
1353
-
1354
1342
if (fileFlags & PG_COMPRESSION )
1355
1343
{
1356
- char * mapFileName = psprintf ("%s.cfm" , fileName );
1357
- vfdP -> md = open (mapFileName , O_CREAT | O_RDWR | ( fileFlags & ~( PG_COMPRESSION | O_EXCL )), fileMode );
1344
+ char * mapFileName = psprintf ("%s.cfm" , vfdP -> fileName );
1345
+ vfdP -> md = BasicOpenFile (mapFileName , vfdP -> fileFlags & ~PG_COMPRESSION , vfdP -> fileMode );
1358
1346
pfree (mapFileName );
1359
1347
if (vfdP -> md < 0 )
1360
1348
{
1361
1349
save_errno = errno ;
1362
- close (vfdP -> fd );
1363
- vfdP -> fd = VFD_CLOSED ;
1364
- elog (LOG , "OPEN MAP FAILED: %d" , errno );
1350
+ elog (LOG , "RE_OPEN MAP FAILED: %d" , errno );
1365
1351
goto io_error ;
1366
1352
}
1367
-
1368
1353
vfdP -> map = cfs_mmap (vfdP -> md );
1369
1354
if (vfdP -> map == MAP_FAILED )
1370
1355
{
1371
1356
save_errno = errno ;
1372
- close (vfdP -> fd );
1357
+ elog (LOG , "RE_MAP FAILED: %d" , errno );
1358
+ close (vfdP -> md );
1359
+ goto io_error ;
1360
+ }
1361
+ /* We need to copy generation before openning data file */
1362
+ vfdP -> generation = vfdP -> map -> generation ;
1363
+ pg_read_barrier ();
1364
+
1365
+ vfdP -> fd = BasicOpenFile (vfdP -> fileName , vfdP -> fileFlags ,
1366
+ vfdP -> fileMode );
1367
+ if (vfdP -> fd < 0 )
1368
+ {
1369
+ save_errno = errno ;
1370
+ DO_DB (elog (LOG , "re-open failed: %m" ));
1371
+ cfs_munmap (vfdP -> map );
1373
1372
close (vfdP -> md );
1374
- vfdP -> fd = VFD_CLOSED ;
1375
1373
vfdP -> md = VFD_CLOSED ;
1376
- elog (LOG , "MAP FAILED: %d" , errno );
1377
1374
goto io_error ;
1378
1375
}
1379
- ++ nfile ;
1376
+ nfile += 2 ;
1377
+ }
1378
+ else
1379
+ {
1380
+ vfdP -> fd = BasicOpenFile (fileName , fileFlags , fileMode );
1381
+ if (vfdP -> fd < 0 )
1382
+ {
1383
+ save_errno = errno ;
1384
+ io_error :
1385
+ FreeVfd (file );
1386
+ free (fnamecopy );
1387
+ errno = save_errno ;
1388
+ return -1 ;
1389
+ }
1390
+ nfile += 1 ;
1380
1391
}
1381
- ++ nfile ;
1382
1392
DO_DB (elog (LOG , "PathNameOpenFile: success %d" ,
1383
1393
vfdP -> fd ));
1384
1394
0 commit comments