Skip to content

Commit ca2dc0f

Browse files
author
Vladimir Ershov
committed
read guc vars for db online
1 parent 2b5853b commit ca2dc0f

File tree

6 files changed

+74
-27
lines changed

6 files changed

+74
-27
lines changed

pgpro_scheduler--1.0.sql

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,42 @@ $BODY$
10371037
LANGUAGE plpgsql
10381038
SECURITY DEFINER;
10391039

1040+
-- CREATE FUNCTION schedule.enable() RETURNS boolean AS
1041+
-- $BODY$
1042+
-- DECLARE
1043+
-- value text;
1044+
-- BEGIN
1045+
-- EXECUTE 'show schedule.enabled' INTO value;
1046+
-- IF value = 'on' THEN
1047+
-- RAISE NOTICE 'Scheduler already enabled';
1048+
-- RETURN false;
1049+
-- ELSE
1050+
-- ALTER SYSTEM SET schedule.enabled = true;
1051+
-- SELECT pg_reload_conf();
1052+
-- END IF;
1053+
-- RETURN true;
1054+
-- END
1055+
-- $BODY$
1056+
-- LANGUAGE plpgsql;
1057+
--
1058+
-- CREATE FUNCTION schedule.disable() RETURNS boolean AS
1059+
-- $BODY$
1060+
-- DECLARE
1061+
-- value text;
1062+
-- BEGIN
1063+
-- EXECUTE 'show schedule.enabled' INTO value;
1064+
-- IF value = 'off' THEN
1065+
-- RAISE NOTICE 'Scheduler already disabled';
1066+
-- RETURN false;
1067+
-- ELSE
1068+
-- ALTER SYSTEM SET schedule.enabled = false;
1069+
-- SELECT pg_reload_conf();
1070+
-- END IF;
1071+
-- RETURN true;
1072+
-- END
1073+
-- $BODY$
1074+
-- LANGUAGE plpgsql;
1075+
10401076
CREATE FUNCTION schedule.cron2jsontext(CSTRING)
10411077
RETURNS text
10421078
AS 'MODULE_PATHNAME', 'cron_string_to_json_text'

src/pgpro_scheduler.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "access/xact.h"
2121
#include "utils/snapmgr.h"
2222
#include "utils/datetime.h"
23+
#include "catalog/pg_db_role_setting.h"
2324

2425
#include "char_array.h"
2526
#include "sched_manager_poll.h"
@@ -68,6 +69,18 @@ worker_spi_sigterm(SIGNAL_ARGS)
6869

6970
/** Some utils **/
7071

72+
void reload_db_role_config(Oid databaseid)
73+
{
74+
Relation relsetting;
75+
Snapshot snapshot;
76+
77+
relsetting = heap_open(DbRoleSettingRelationId, AccessShareLock);
78+
snapshot = RegisterSnapshot(GetCatalogSnapshot(DbRoleSettingRelationId));
79+
ApplySetting(snapshot, databaseid, InvalidOid, relsetting, PGC_S_DATABASE);
80+
UnregisterSnapshot(snapshot);
81+
heap_close(relsetting, AccessShareLock);
82+
}
83+
7184
TimestampTz timestamp_add_seconds(TimestampTz to, int add)
7285
{
7386
if(to == 0) to = GetCurrentTimestamp();
@@ -227,7 +240,6 @@ char_array_t *readBasesToCheck(void)
227240
SPI_finish();
228241
PopActiveSnapshot();
229242
CommitTransactionCommand();
230-
elog(FATAL, "Cannot get databases list: error code %d", ret);
231243
}
232244
destroyCharArray(names);
233245
processed = SPI_processed;
@@ -299,7 +311,7 @@ void parent_scheduler_main(Datum arg)
299311
names = readBasesToCheck();
300312
}
301313
}
302-
else
314+
else if(poll->enabled)
303315
{
304316
names = readBasesToCheck();
305317
if(isBaseListChanged(names, poll)) refresh = true;
@@ -321,7 +333,7 @@ void parent_scheduler_main(Datum arg)
321333

322334
if(shared->setbychild)
323335
{
324-
elog(LOG, "got status change from: %s", poll->workers[i]->dbname);
336+
/* elog(LOG, "got status change from: %s", poll->workers[i]->dbname); */
325337
shared->setbychild = false;
326338
if(shared->status == SchdManagerConnected)
327339
{
@@ -340,7 +352,6 @@ void parent_scheduler_main(Datum arg)
340352
else
341353
{
342354
elog(WARNING, "manager: %s set strange status: %d", poll->workers[i]->dbname, shared->status);
343-
/* MAYBE kill the creep */
344355
}
345356
}
346357
}
@@ -361,7 +372,7 @@ pg_scheduler_startup(void)
361372
{
362373
BackgroundWorker worker;
363374

364-
elog(LOG, "start up");
375+
elog(LOG, "Start PostgresPro scheduler");
365376

366377
worker.bgw_flags = BGWORKER_SHMEM_ACCESS |
367378
BGWORKER_BACKEND_DATABASE_CONNECTION;
@@ -425,7 +436,7 @@ void _PG_init(void)
425436
2,
426437
1,
427438
100,
428-
PGC_SIGHUP,
439+
PGC_SUSET,
429440
0,
430441
NULL,
431442
NULL,
@@ -470,10 +481,10 @@ temp_now(PG_FUNCTION_ARGS)
470481
timestamp2tm(ts, &tz, &info, &fsec, &tzn, session_timezone );
471482
info.tm_wday = j2day(date2j(info.tm_year, info.tm_mon, info.tm_mday));
472483

473-
elog(NOTICE, "WDAY: %d, MON: %d, MDAY: %d, HOUR: %d, MIN: %d, YEAR: %d (%ld)",
484+
/* elog(NOTICE, "WDAY: %d, MON: %d, MDAY: %d, HOUR: %d, MIN: %d, YEAR: %d (%ld)",
474485
info.tm_wday, info.tm_mon, info.tm_mday, info.tm_hour, info.tm_min,
475486
info.tm_year, info.tm_gmtoff);
476-
elog(NOTICE, "TZP: %d, ZONE: %s", tz, tzn);
487+
elog(NOTICE, "TZP: %d, ZONE: %s", tz, tzn); */
477488

478489
cp.tm_mon = info.tm_mon;
479490
cp.tm_mday = info.tm_mday;
@@ -483,7 +494,7 @@ temp_now(PG_FUNCTION_ARGS)
483494
cp.tm_sec = info.tm_sec;
484495

485496
toff = DetermineTimeZoneOffset(&cp, session_timezone);
486-
elog(NOTICE, "Detect: offset = %ld", toff);
497+
/* elog(NOTICE, "Detect: offset = %ld", toff); */
487498

488499
cp.tm_gmtoff = -toff;
489500
tm2timestamp(&cp, 0, &tz, &ts);

src/pgpro_scheduler.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#define PGPRO_SCHEDULER_DBNAME_MAX 128
1111
#define PGPRO_SCHEDULER_NODENAME_MAX 128
1212
#define PGPRO_SCHEDULER_EXECUTOR_MESSAGE_MAX 1024
13-
#define PPGS_DEBUG 1
13+
#define PPGS_NODEBUG 1
1414

1515
#ifdef PPGS_DEBUG
1616
#ifdef HAVE__VA_ARGS
@@ -34,6 +34,7 @@ int checkSchedulerNamespace(void);
3434
void manager_worker_main(Datum arg);
3535
pid_t registerManagerWorker(schd_manager_t *man);
3636

37+
void reload_db_role_config(Oid databaseid);
3738
TimestampTz timestamp_add_seconds(TimestampTz to, int add);
3839
char *make_date_from_timestamp(TimestampTz ts);
3940
int get_integer_from_string(char *s, int start, int len);

src/sched_manager_poll.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ void changeChildBgwState(schd_manager_share_t *s, schd_manager_status_t status)
100100
if(parent)
101101
{
102102
SetLatch(&parent->procLatch);
103-
elog(LOG, "set LATCH to %d - status = %d" , MyBgworkerEntry->bgw_notify_pid, status);
103+
/* elog(LOG, "set LATCH to %d - status = %d" , MyBgworkerEntry->bgw_notify_pid, status); */
104104
}
105105
else
106106
{
107-
elog(LOG, "unable to set LATCH to %d", MyBgworkerEntry->bgw_notify_pid);
107+
/* elog(LOG, "unable to set LATCH to %d", MyBgworkerEntry->bgw_notify_pid); */
108108
}
109109
}
110110

@@ -114,7 +114,7 @@ int stopAllManagers(schd_managers_poll_t *poll)
114114
PGPROC *child;
115115
schd_manager_share_t *shared;
116116

117-
elog(LOG, "Stop all managers");
117+
elog(LOG, "Scheduler stops all managers");
118118

119119
for(i=0; i < poll->n; i++)
120120
{
@@ -124,16 +124,14 @@ int stopAllManagers(schd_managers_poll_t *poll)
124124
child = BackendPidGetProc(poll->workers[i]->pid);
125125
if(!child)
126126
{
127-
elog(LOG, "cannot get PGRPOC of %s scheduler", poll->workers[i]->dbname);
127+
/* elog(LOG, "cannot get PGRPOC of %s scheduler", poll->workers[i]->dbname); */
128128
}
129129
else
130130
{
131131
SetLatch(&child->procLatch);
132132
}
133133
}
134134

135-
/* MAYBE: WAIT? */
136-
137135
for(i=0; i < poll->n; i++)
138136
{
139137
destroyManagerRecord(poll->workers[i]);
@@ -382,7 +380,7 @@ int refreshManagers(char_array_t *names, schd_managers_poll_t *poll)
382380
if(found == 0) pushCharArray(delete, poll->workers[i]->dbname);
383381
}
384382
}
385-
elog(LOG, "WORK RESULT: same: %d, new: %d, delete: %d", same->n, new->n, delete->n);
383+
/* elog(LOG, "WORK RESULT: same: %d, new: %d, delete: %d", same->n, new->n, delete->n); */
386384
if(delete->n)
387385
{
388386
for(i = 0; i < delete->n; i++)

src/scheduler_manager.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,23 @@ int checkSchedulerNamespace(void)
6868
}
6969
else if(isnull)
7070
{
71-
elog(LOG, "%s: cannot check namespace: count return null",
71+
elog(LOG, "Scheduler manager: %s: cannot check namespace: count return null",
7272
MyBgworkerEntry->bgw_name);
7373
}
7474
else if(ntup > 1)
7575
{
76-
elog(LOG, "%s: cannot check namespace: found %d namespaces",
76+
elog(LOG, "Scheduler manager: %s: cannot check namespace: found %d namespaces",
7777
MyBgworkerEntry->bgw_name, ntup);
7878
}
7979
}
8080
else if(ret != SPI_OK_SELECT)
8181
{
82-
elog(LOG, "%s: cannot check namespace: error code %d",
82+
elog(LOG, "Scheduler manager: %s: cannot check namespace: error code %d",
8383
MyBgworkerEntry->bgw_name, ret);
8484
}
8585
else if(SPI_processed != 1)
8686
{
87-
elog(LOG, "%s: cannot check namespace: count return %ud tups",
87+
elog(LOG, "Scheduler manager: %s: cannot check namespace: count return %ud tups",
8888
MyBgworkerEntry->bgw_name,
8989
(unsigned)SPI_processed);
9090
}
@@ -100,7 +100,7 @@ int get_scheduler_maxworkers(void)
100100
const char *opt;
101101
int var;
102102

103-
opt = GetConfigOption("schedule.max_workers", true, false);
103+
opt = GetConfigOption("schedule.max_workers", false, false);
104104
/* opt = GetConfigOptionByName("schedule.max_workers", NULL); */
105105
if(opt == NULL)
106106
{
@@ -152,10 +152,11 @@ int refresh_scheduler_manager_context(scheduler_manager_ctx_t *ctx)
152152
scheduler_manager_slot_t **old;
153153

154154
N = get_scheduler_maxworkers();
155+
elog(LOG, "max-workers: %d", N);
155156
if(N != ctx->slots_len)
156157
{
157158
elog(LOG, "Change available workers number %d => %d", ctx->slots_len, N);
158-
}
159+
}
159160

160161
if(N > ctx->slots_len)
161162
{
@@ -314,7 +315,7 @@ scheduler_task_t *scheduler_get_active_tasks(scheduler_manager_ctx_t *ctx, int *
314315
}
315316
else if(ret != SPI_OK_SELECT)
316317
{
317-
elog(LOG, "%s: cannot get \"at\" tasks: error code %d",
318+
elog(LOG, "Scheduler manager: %s: cannot get \"at\" tasks: error code %d",
318319
MyBgworkerEntry->bgw_name, ret);
319320

320321
scheduler_manager_stop(ctx);
@@ -1047,7 +1048,8 @@ int scheduler_vanish_expired_jobs(scheduler_manager_ctx_t *ctx)
10471048
move_ret = move_job_to_log(&expired[i], 0);
10481049
if(move_ret < 0)
10491050
{
1050-
elog(LOG, "cannot move job %d@%s:00 to log", expired[i].cron_id, ts);
1051+
elog(LOG, "Scheduler manager: cannot move job %d@%s:00 to log",
1052+
expired[i].cron_id, ts);
10511053
ret--;
10521054
}
10531055
pfree(ts);
@@ -1233,7 +1235,7 @@ bool check_parent_stop_signal(scheduler_manager_ctx_t *ctx)
12331235
shared->setbyparent = false;
12341236
if(shared->status == SchdManagerStop)
12351237
{
1236-
elog(LOG, "Recieve stop signal from parent");
1238+
elog(LOG, "Scheduler manager: receive stop signal from supervisor");
12371239
return true;
12381240
}
12391241
}

src/scheduler_spi_utils.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ Datum select_onedatumvalue_sql(const char *sql, bool *is_null)
153153
int ret;
154154
Datum datum = 0;
155155

156-
elog(LOG, "do one val: %s", sql);
157156
ret = SPI_execute(sql, true, 0);
158157
if(ret == SPI_OK_SELECT)
159158
{

0 commit comments

Comments
 (0)