37
37
38
38
/*
39
39
* There are 2 kinds of worker: 1) scheduler, which creates new tasks, 2) the
40
- * actual "squeeze worker" which calls the squeeze_table() function. With
41
- * scheduling independent from the actual table processing we check the table
42
- * status exactly (with the granularity of one minute) at the scheduled
43
- * time. This way we avoid the tricky question how long should particular
44
- * schedule stay valid and thus we can use equality operator to check if the
45
- * scheduled time is there.
46
- *
47
- * There are 2 alternatives to the equality test: 1) schedule is valid for
48
- * some time interval which is hard to define, 2) the schedule is valid
49
- * forever - this is bad because it allows table processing even hours after
50
- * the schedule if the table happens to get bloated some time after the
51
- * schedule.
52
- *
53
- * If the squeeze_table() function makes the following tasks delayed, it's
54
- * another problem that we can address by increasing the number of "squeeze
55
- * workers". (In that case we'd have to adjust the replication slot naming
56
- * scheme so that there are no conflicts.)
40
+ * actual "squeeze worker" which calls the squeeze_table() function. It's
41
+ * simpler to have a separate worker that checks the schedules every
42
+ * minute. If there was a single worker that checks the schedules among the
43
+ * calls of squeeze_table(), it'd be harder to handle the cases where the call
44
+ * of squeeze_table() took too much time to complete (i.e. the worker could
45
+ * miss some schedule(s)).
57
46
*/
58
47
static bool am_i_scheduler = false;
59
48
@@ -64,14 +53,17 @@ static bool am_i_scheduler = false;
64
53
static bool am_i_standalone = false;
65
54
66
55
/*
67
- * The shmem_request_hook_type hook was introduced in PG 15. Since the number
68
- * of slots depends on the max_worker_processes GUC, the maximum number of
69
- * squeeze workers must be a compile time constant for PG < 15.
56
+ * As long as the number of slots depends on the max_worker_processes GUC (it
57
+ * just makes sense not to allocate more slots for our workers than this
58
+ * value), we should not use this GUC before the other libraries have been
59
+ * loaded: those libraries might, at least in theory, adjust
60
+ * max_worker_processes.
70
61
*
71
- * XXX Regarding PG < 15: maybe we don't need to worry about dependency on an
72
- * in-core GUC - the value should be known at load time and no other loadable
73
- * module should be able to change it before we start the shared memory
74
- * allocation.
62
+ * In PG >= 15, this function is called from squeeze_worker_shmem_request(),
63
+ * after all the related GUCs have been set. In earlier versions (which do not
64
+ * have the hook), the function is called while our library is being loaded,
65
+ * and some other libraries might follow. Therefore we prefer a compile time
66
+ * constant to a (possibly) not-yet-finalized GUC.
75
67
*/
76
68
static int
77
69
max_squeeze_workers (void )
@@ -209,6 +201,10 @@ squeeze_save_prev_shmem_request_hook(void)
209
201
}
210
202
#endif
211
203
204
+ /*
205
+ * The shmem_request_hook hook was introduced in PG 15. In earlier versions we
206
+ * call it directly from _PG_init().
207
+ */
212
208
void
213
209
squeeze_worker_shmem_request (void )
214
210
{
@@ -914,7 +910,8 @@ squeeze_worker_main(Datum main_arg)
914
910
915
911
/*
916
912
* Initialize MyWorkerTask as soon as possible so that
917
- * worker_shmem_shutdown() can release it in case of ERROR.
913
+ * worker_shmem_shutdown() can clean it up in the shared memory in case of
914
+ * ERROR.
918
915
*/
919
916
if (task_idx >= 0 )
920
917
{
@@ -942,10 +939,9 @@ squeeze_worker_main(Datum main_arg)
942
939
/*
943
940
* The first worker after restart is responsible for cleaning up
944
941
* replication slots and/or origins that other workers could not remove
945
- * due to server crash. Do that while holding the exclusive lock, as
946
- * concurrency makes no sense here. That also ensures that the other
947
- * workers wait for the cleanup to finish instead of complaining about the
948
- * existing slots / origins.
942
+ * due to server crash. Do that while holding the exclusive lock - that
943
+ * also ensures that the other workers wait for the cleanup to finish
944
+ * instead of complaining about the existing slots / origins.
949
945
*/
950
946
if (!am_i_scheduler && !workerData -> cleanup_done )
951
947
{
@@ -1352,7 +1348,8 @@ scheduler_worker_loop(void)
1352
1348
* the current transaction.
1353
1349
*/
1354
1350
old_cxt = MemoryContextSwitchTo (sched_cxt );
1355
- registered = start_worker_internal (false, task_idx , & worker -> handle );
1351
+ registered = start_worker_internal (false, task_idx ,
1352
+ & worker -> handle );
1356
1353
MemoryContextSwitchTo (old_cxt );
1357
1354
1358
1355
if (!registered )
@@ -2322,7 +2319,7 @@ release_task(WorkerTask *task)
2322
2319
*/
2323
2320
2324
2321
MyWorkerTask = NULL ;
2325
- /* Let others to see the WTS_UNUSED state. */
2322
+ /* Let others see the WTS_UNUSED state. */
2326
2323
SpinLockRelease (& task -> mutex );
2327
2324
}
2328
2325
0 commit comments