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

Commit 9af8b2e

Browse files
committed
Alter background_gc_enable in cfs_start_gc
1 parent e32962c commit 9af8b2e

File tree

1 file changed

+18
-1
lines changed
  • src/backend/storage/file

1 file changed

+18
-1
lines changed

src/backend/storage/file/cfs.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1253,8 +1253,25 @@ Datum cfs_start_gc(PG_FUNCTION_ARGS)
12531253

12541254
Datum cfs_enable_gc(PG_FUNCTION_ARGS)
12551255
{
1256+
bool enabled = PG_GETARG_BOOL(0);
12561257
bool was_enabled = cfs_state->background_gc_enabled;
1257-
cfs_state->background_gc_enabled = PG_GETARG_BOOL(0);
1258+
cfs_state->background_gc_enabled = enabled;
1259+
1260+
if (was_enabled && !enabled)
1261+
{
1262+
/* Wait until there are no active GC workers */
1263+
while (pg_atomic_read_u32(&cfs_state->n_active_gc) != 0)
1264+
{
1265+
int rc = WaitLatch(MyLatch,
1266+
WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
1267+
CFS_DISABLE_TIMEOUT /* ms */);
1268+
if (rc & WL_POSTMASTER_DEATH)
1269+
exit(1);
1270+
1271+
ResetLatch(MyLatch);
1272+
CHECK_FOR_INTERRUPTS();
1273+
}
1274+
}
12581275
PG_RETURN_BOOL(was_enabled);
12591276
}
12601277

0 commit comments

Comments
 (0)