Skip to content

Commit 1ab15cf

Browse files
author
Vladimir Ershov
committed
show mwthods for GUC vars
1 parent 2030181 commit 1ab15cf

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

src/memutils.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ MemoryContext init_mem_ctx(const char *name)
1212
ALLOCSET_DEFAULT_MAXSIZE);
1313
}
1414

15+
bool is_worker_context_initialized(void)
16+
{
17+
return SchedulerWorkerContext == NULL ? false: true;
18+
}
19+
1520
MemoryContext init_worker_mem_ctx(const char *name)
1621
{
1722
AssertState(SchedulerWorkerContext == NULL);
@@ -47,6 +52,15 @@ void *worker_alloc(Size size)
4752
return MemoryContextAlloc(SchedulerWorkerContext, size);
4853
}
4954

55+
void drop_worker_context(void)
56+
{
57+
if(SchedulerWorkerContext)
58+
{
59+
MemoryContextDelete(SchedulerWorkerContext);
60+
SchedulerWorkerContext = NULL;
61+
}
62+
}
63+
5064
void delete_worker_mem_ctx(MemoryContext old)
5165
{
5266
if(!old) old = TopMemoryContext;

src/memutils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@ char *_mcopy_string(MemoryContext ctx, char *str);
1616
char *my_copy_string(char *str);
1717
void check_scheduler_context(void);
1818

19+
bool is_worker_context_initialized(void);
20+
void drop_worker_context(void);
21+
1922
#endif

src/pgpro_scheduler.c

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
PG_MODULE_MAGIC;
4848
#endif
4949

50+
static const char *show_scheduler_nodename(void);
51+
static const char *show_scheduler_database(void);
52+
5053
volatile sig_atomic_t got_sighup = false;
5154
volatile sig_atomic_t got_sigterm = false;
5255

@@ -297,6 +300,41 @@ char *set_schema(const char *name, bool get_old)
297300
return current;
298301
}
299302

303+
static const char *
304+
show_scheduler_nodename(void)
305+
{
306+
static char nbuf[256];
307+
char *nname;
308+
309+
nname = get_scheduler_nodename(CurrentMemoryContext);
310+
snprintf(nbuf, sizeof(nbuf), "%s", nname);
311+
pfree(nname);
312+
return nbuf;
313+
}
314+
315+
static const char *
316+
show_scheduler_database(void)
317+
{
318+
static char nbuf[256];
319+
const char *value;
320+
bool drop_context = false;
321+
322+
if(!is_worker_context_initialized())
323+
{
324+
init_worker_mem_ctx("temp for functions");
325+
drop_context = true;
326+
}
327+
328+
value = check_multimaster_database();
329+
330+
if(!value)
331+
value = GetConfigOption("schedule.database", true, false);
332+
snprintf(nbuf, sizeof(nbuf), "%s", value);
333+
334+
if(drop_context) drop_worker_context();
335+
return nbuf;
336+
}
337+
300338
char *get_scheduler_nodename(MemoryContext mem)
301339
{
302340
const char *opt;
@@ -670,7 +708,7 @@ void _PG_init(void)
670708
0,
671709
NULL,
672710
NULL,
673-
NULL
711+
show_scheduler_database
674712
);
675713
DefineCustomStringVariable(
676714
"schedule.nodename",
@@ -682,7 +720,7 @@ void _PG_init(void)
682720
0,
683721
NULL,
684722
NULL,
685-
NULL
723+
show_scheduler_nodename
686724
);
687725
DefineCustomStringVariable(
688726
"schedule.transaction_state",

0 commit comments

Comments
 (0)