Skip to content

Commit 2030181

Browse files
author
Vladimir Ershov
committed
for multimuster env
1 parent 190a205 commit 2030181

File tree

4 files changed

+30
-25
lines changed

4 files changed

+30
-25
lines changed

src/memutils.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ MemoryContext switch_to_worker_context(void)
2929
return MemoryContextSwitchTo(SchedulerWorkerContext);
3030
}
3131

32+
void check_scheduler_context(void)
33+
{
34+
if(MemoryContextIsValid(SchedulerWorkerContext))
35+
{
36+
elog(LOG, "scheduler context: ok");
37+
}
38+
else
39+
{
40+
elog(LOG, "scheduler context: broken");
41+
}
42+
}
43+
3244
void *worker_alloc(Size size)
3345
{
3446
AssertState(SchedulerWorkerContext != NULL);

src/memutils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ void delete_worker_mem_ctx(MemoryContext toswitch);
1414

1515
char *_mcopy_string(MemoryContext ctx, char *str);
1616
char *my_copy_string(char *str);
17+
void check_scheduler_context(void);
1718

1819
#endif

src/pgpro_scheduler.c

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ const char *check_multimaster_database(void)
336336
/* at first need to parse shared_preload_libraries */
337337
libs = GetConfigOption("shared_preload_libraries", true, false);
338338
if(!libs) return NULL;
339-
split_libs = _split_string_to_char_array((char *)libs);
339+
split_libs = _split_string_to_char_array((char *)libs, true);
340340
if(split_libs->n == 0)
341341
{
342342
destroyCharArray(split_libs);
@@ -351,21 +351,19 @@ const char *check_multimaster_database(void)
351351
}
352352
}
353353
destroyCharArray(split_libs);
354-
if(0 && !mtm_present) return NULL;
354+
if(!mtm_present) return NULL;
355355

356356
/* now check id multimaster.node_id set */
357357
mtm_id_str = GetConfigOption("multimaster.node_id", true, false);
358358
if(!mtm_id_str) return NULL;
359359
mtm_id = atoi(mtm_id_str);
360360
if(mtm_id == 0) return NULL;
361-
elog(LOG, "got mtm_id %d", mtm_id);
362361

363362
/* find proper connection string from mtm_id */
364363
mtm_cstring = GetConfigOption("multimaster.conn_strings", true, false);
365364
if(!mtm_cstring) return NULL;
366-
elog(LOG, "got mtm_connstring");
367365

368-
conns = _split_string_to_char_array((char *)mtm_cstring);
366+
conns = _split_string_to_char_array((char *)mtm_cstring, false);
369367
if(conns->n < mtm_id)
370368
{
371369
destroyCharArray(conns);
@@ -377,10 +375,8 @@ const char *check_multimaster_database(void)
377375
destroyCharArray(conns);
378376
return NULL;
379377
}
380-
elog(LOG, "GOT BEGIN");
381378

382-
memset(buffer, 0, 256);
383-
for(i=7; dbbeg[i] != 0 || i < 249; i++)
379+
for(i=7; dbbeg[i] != 0 && i < 256; i++)
384380
{
385381
if(dbbeg[i] != ' ')
386382
{
@@ -391,13 +387,13 @@ const char *check_multimaster_database(void)
391387
break;
392388
}
393389
}
390+
buffer[j] = 0;
394391
destroyCharArray(conns);
395-
elog(LOG, "Almost ready %s", buffer);
396392
if(j > 0) return buffer;
397393
return NULL;
398394
}
399395

400-
char_array_t *_split_string_to_char_array(char *str)
396+
char_array_t *_split_string_to_char_array(char *str, bool do_clean)
401397
{
402398
int str_len, cv_len=0, i;
403399
char *clean_value;
@@ -410,17 +406,15 @@ char_array_t *_split_string_to_char_array(char *str)
410406
clean_value = worker_alloc(sizeof(char)*(str_len+1));
411407
for(i=0; i < str_len; i++)
412408
{
413-
if(str[i] != ' ')
409+
if(do_clean && str[i] == ' ') continue;
410+
if(str[i] == ',')
414411
{
415-
if(str[i] == ',')
416-
{
417-
nnames++;
418-
clean_value[cv_len++] = 0;
419-
}
420-
else
421-
{
422-
clean_value[cv_len++] = str[i];
423-
}
412+
nnames++;
413+
clean_value[cv_len++] = 0;
414+
}
415+
else
416+
{
417+
clean_value[cv_len++] = str[i];
424418
}
425419
}
426420
clean_value[cv_len] = 0;
@@ -462,7 +456,6 @@ char_array_t *readBasesToCheck(void)
462456
result = makeCharArray();
463457

464458
value = check_multimaster_database();
465-
elog(LOG, "From mm: %s", value);
466459

467460
if(!value)
468461
value = GetConfigOption("schedule.database", true, false);
@@ -472,8 +465,8 @@ char_array_t *readBasesToCheck(void)
472465
return result;
473466
}
474467

475-
names = _split_string_to_char_array((char *)value);
476-
if(names->n == 0)
468+
names = _split_string_to_char_array((char *)value, true);
469+
if(names == NULL || names->n == 0)
477470
{
478471
destroyCharArray(names);
479472
return result;
@@ -525,7 +518,6 @@ void parent_scheduler_main(Datum arg)
525518
CurrentResourceOwner = ResourceOwnerCreate(NULL, "pgpro_scheduler");
526519

527520
init_worker_mem_ctx("Parent scheduler context");
528-
elog(LOG, "Start PostgresPro scheduler.");
529521

530522
SetConfigOption("application_name", "pgp-s supervisor", PGC_USERSET, PGC_S_SESSION);
531523
pgstat_report_activity(STATE_RUNNING, "Initialize");

src/pgpro_scheduler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ bool is_scheduler_enabled(void);
4747
char *set_schema(const char *name, bool get_old);
4848
char *get_scheduler_schema_name(void);
4949
char *get_scheduler_nodename(MemoryContext mem);
50-
char_array_t *_split_string_to_char_array(char *str);
50+
char_array_t *_split_string_to_char_array(char *str, bool doclean);
5151
const char *check_multimaster_database(void);
5252

5353
#endif

0 commit comments

Comments
 (0)