Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e32962c

Browse files
committed
Set generation in PathNameOpenFile function
1 parent f5f45c9 commit e32962c

File tree

2 files changed

+37
-25
lines changed

2 files changed

+37
-25
lines changed

src/backend/storage/file/cfs.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ static void cfs_gc_bgworker_main(Datum arg)
11241124
/* We're now ready to receive signals */
11251125
BackgroundWorkerUnblockSignals();
11261126

1127-
elog(INFO, "Start CFS garbage collector %d", MyProcPid);
1127+
elog(INFO, "Start CFS garbage collector %d (enabled=%d)", MyProcPid, cfs_state->background_gc_enabled);
11281128

11291129
while (true)
11301130
{
@@ -1253,7 +1253,9 @@ Datum cfs_start_gc(PG_FUNCTION_ARGS)
12531253

12541254
Datum cfs_enable_gc(PG_FUNCTION_ARGS)
12551255
{
1256-
PG_RETURN_BOOL(cfs_control_gc(PG_GETARG_BOOL(0)));
1256+
bool was_enabled = cfs_state->background_gc_enabled;
1257+
cfs_state->background_gc_enabled = PG_GETARG_BOOL(0);
1258+
PG_RETURN_BOOL(was_enabled);
12571259
}
12581260

12591261
Datum cfs_version(PG_FUNCTION_ARGS)

src/backend/storage/file/fd.c

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,46 +1339,56 @@ PathNameOpenFile(FileName fileName, int fileFlags, int fileMode)
13391339
/* Close excess kernel FDs. */
13401340
ReleaseLruFiles();
13411341

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-
13541342
if (fileFlags & PG_COMPRESSION)
13551343
{
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);
13581346
pfree(mapFileName);
13591347
if (vfdP->md < 0)
13601348
{
13611349
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);
13651351
goto io_error;
13661352
}
1367-
13681353
vfdP->map = cfs_mmap(vfdP->md);
13691354
if (vfdP->map == MAP_FAILED)
13701355
{
13711356
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);
13731372
close(vfdP->md);
1374-
vfdP->fd = VFD_CLOSED;
13751373
vfdP->md = VFD_CLOSED;
1376-
elog(LOG, "MAP FAILED: %d", errno);
13771374
goto io_error;
13781375
}
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;
13801391
}
1381-
++nfile;
13821392
DO_DB(elog(LOG, "PathNameOpenFile: success %d",
13831393
vfdP->fd));
13841394

0 commit comments

Comments
 (0)