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

Commit f4f12f1

Browse files
committed
Merge branch 'PGPROEE10_scheduler' into PGPROEE10
2 parents c24981b + 0816cec commit f4f12f1

22 files changed

+217
-19
lines changed

contrib/pgpro_scheduler/src/bit_array.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* bit_array.c
4+
*
5+
* Copyright (c) 2017-2018, Postgres Professional
6+
*
7+
*-------------------------------------------------------------------------
8+
*/
19
#include <stdlib.h>
210
#include "bit_array.h"
311
#include "postgres.h"

contrib/pgpro_scheduler/src/bit_array.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* bit_array.h
4+
*
5+
* Copyright (c) 2017-2018, Postgres Professional
6+
*
7+
*-------------------------------------------------------------------------
8+
*/
19
#ifndef PGPRO_SCHEDULER_BITARRAY_H
210
#define PGPRO_SCHEDULER_BITARRAY_H
311

contrib/pgpro_scheduler/src/char_array.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* char_array.c
4+
*
5+
* Copyright (c) 2017-2018, Postgres Professional
6+
*
7+
*-------------------------------------------------------------------------
8+
*/
19
#include <stdio.h>
210
#include <stdlib.h>
311
#include "postgres.h"

contrib/pgpro_scheduler/src/char_array.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* char_array.h
4+
*
5+
* Copyright (c) 2017-2018, Postgres Professional
6+
*
7+
*-------------------------------------------------------------------------
8+
*/
19
#ifndef CHAR_ARRAY_H
210
#define CHAR_ARRAY_H
311

contrib/pgpro_scheduler/src/cron_string.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* cron_string.c
4+
*
5+
* Copyright (c) 2017-2018, Postgres Professional
6+
*
7+
*-------------------------------------------------------------------------
8+
*/
19
#include <stdio.h>
210
#include <stdlib.h>
311
#include <string.h>

contrib/pgpro_scheduler/src/cron_string.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* cron_string.h
4+
*
5+
* Copyright (c) 2017-2018, Postgres Professional
6+
*
7+
*-------------------------------------------------------------------------
8+
*/
19
#ifndef CRON_STRING_PARSE_H
210
#define CRON_STRING_PARSE_H
311

contrib/pgpro_scheduler/src/memutils.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* memutils.c
4+
*
5+
* Copyright (c) 2017-2018, Postgres Professional
6+
*
7+
*-------------------------------------------------------------------------
8+
*/
19
#include "postgres.h"
210
#include "utils/memutils.h"
311
#include "memutils.h"

contrib/pgpro_scheduler/src/memutils.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* memutils.h
4+
*
5+
* Copyright (c) 2017-2018, Postgres Professional
6+
*
7+
*-------------------------------------------------------------------------
8+
*/
19
#ifndef PGPRO_SCHEDULER_MEMUTILS_H
210
#define PGPRO_SCHEDULER_MEMUTILS_H
311

contrib/pgpro_scheduler/src/pgpro_scheduler.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* pgpro_scheduler.c
4+
*
5+
* Copyright (c) 2017-2018, Postgres Professional
6+
*
7+
*-------------------------------------------------------------------------
8+
*/
19
#define ENABLE_LIST_COMPAT 1
210

311
#include "postgres.h"

contrib/pgpro_scheduler/src/pgpro_scheduler.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* pgpro_scheduler.h
4+
*
5+
* Copyright (c) 2017-2018, Postgres Professional
6+
*
7+
*-------------------------------------------------------------------------
8+
*/
19
#ifndef PGPRO_SCHEDULER_H
210
#define PGPRO_SCHEDULER_H
311

contrib/pgpro_scheduler/src/sched_manager_poll.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* sched_manager_poll.c
4+
*
5+
* Copyright (c) 2017-2018, Postgres Professional
6+
*
7+
*-------------------------------------------------------------------------
8+
*/
19
#include <stdlib.h>
210
#include "postgres.h"
311
#include "string.h"

contrib/pgpro_scheduler/src/sched_manager_poll.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* sched_manager_poll.h
4+
*
5+
* Copyright (c) 2017-2018, Postgres Professional
6+
*
7+
*-------------------------------------------------------------------------
8+
*/
19
#ifndef PGPRO_SCHEDULER_MANAGER_POLL_H
210
#define PGPRO_SCHEDULER_MANAGER_POLL_H
311

contrib/pgpro_scheduler/src/scheduler_executor.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* scheduler_executor.c
4+
*
5+
* Copyright (c) 2017-2018, Postgres Professional
6+
*
7+
*-------------------------------------------------------------------------
8+
*/
19
#include <stdlib.h>
210
#include <stdarg.h>
311
#include "postgres.h"

contrib/pgpro_scheduler/src/scheduler_executor.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* scheduler_executor.h
4+
*
5+
* Copyright (c) 2017-2018, Postgres Professional
6+
*
7+
*-------------------------------------------------------------------------
8+
*/
19
#ifndef PGPRO_SCHEDULER_EXECUTOR_H
210
#define PGPRO_SCHEDULER_EXECUTOR_H
311

contrib/pgpro_scheduler/src/scheduler_job.c

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* scheduler_job.c
4+
*
5+
* Copyright (c) 2017-2018, Postgres Professional
6+
*
7+
*-------------------------------------------------------------------------
8+
*/
19
#include <stdio.h>
210
#include <string.h>
311
#include <stdarg.h>
@@ -180,14 +188,15 @@ job_t *get_at_job_for_process(MemoryContext mem, char *nodename, char **error)
180188
get_job_sql = makeStringInfo();
181189
getNodesToSelect(&nodes, nodename);
182190

183-
appendStringInfo(get_job_sql, "select * from at_jobs_submitted s where \
184-
((not exists ( select * from at_jobs_submitted s2 where \
185-
s2.id = any(s.depends_on)) AND not exists \
186-
( select * from at_jobs_process p where p.id = any(s.depends_on)) AND \
187-
s.depends_on is NOT NULL and s.at IS NULL AND not exists \
188-
( select * from at_jobs_done d where d.id = any(s.depends_on) and \
189-
d.status=false)) OR ( s.at IS NOT NULL AND at <= 'now' and \
190-
(last_start_available is NULL OR last_start_available > 'now'))) and \
191+
appendStringInfo(get_job_sql, "select * \
192+
from at_jobs_submitted s \
193+
where (s.depends_on is null \
194+
or not exists (select * from at_jobs_submitted s2 where s2.id = any(s.depends_on)) \
195+
AND not exists(select * from at_jobs_process p where p.id = any(s.depends_on)) \
196+
AND not exists(select * from at_jobs_done d where d.id = any(s.depends_on) and d.status=false) \
197+
) \
198+
and coalesce(s.at, now()) <= now() \
199+
and (s.last_start_available is null or s.last_start_available>now()) and \
191200
node %s and not canceled order by at, submit_time \
192201
limit 1 FOR UPDATE SKIP LOCKED ", nodes.cond);
193202

@@ -579,10 +588,34 @@ int set_at_job_done(job_t *job, char *error, int64 resubmit, char **set_error)
579588
spi_response_t *r2;
580589
spi_response_t *r3;
581590

582-
const char *get_sql = "select * from at_jobs_process where id = $1";
583-
const char *insert_sql = "insert into at_jobs_done values($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21)";
591+
592+
593+
594+
const char *get_sql = "\
595+
select \
596+
id, node, name, comments, at, do_sql, params, depends_on, \
597+
executor, owner, last_start_available, attempt, resubmit_limit, \
598+
postpone, max_run_time, canceled, submit_time, start_time \
599+
from at_jobs_process where id = $1";
600+
601+
const char *insert_sql = "\
602+
insert into at_jobs_done \
603+
(id, node, name, comments, at, do_sql, params, depends_on, \
604+
executor, owner, last_start_available, attempt, resubmit_limit, \
605+
postpone, max_run_time, canceled, submit_time, start_time, \
606+
status, reason, done_time) \
607+
values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, \
608+
$15, $16, $17, $18, $19, $20, $21)";
584609
const char *delete_sql = "delete from at_jobs_process where id = $1";
585-
const char *resubmit_sql = "insert into at_jobs_submitted values($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17)";
610+
611+
const char *resubmit_sql = "\
612+
insert into at_jobs_submitted \
613+
(id, node, name, comments, at, do_sql, params, depends_on, \
614+
executor, owner, last_start_available, attempt, resubmit_limit, \
615+
postpone, max_run_time, canceled, submit_time) \
616+
values \
617+
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, \
618+
$15, $16, $17)";
586619

587620
oldpath = set_schema(NULL, true);
588621

@@ -627,7 +660,7 @@ int set_at_job_done(job_t *job, char *error, int64 resubmit, char **set_error)
627660
{
628661
if(canceled)
629662
{
630-
this_error = _mcopy_string(CurrentMemoryContext, "job was canceled while processing: cannot resubmit");
663+
this_error = _mcopy_string(CurrentMemoryContext, "job was cancelled while processing: cannot resubmit");
631664
sql = insert_sql;
632665
n = 21;
633666

@@ -640,6 +673,7 @@ int set_at_job_done(job_t *job, char *error, int64 resubmit, char **set_error)
640673
sql = resubmit_sql;
641674
values[4] = TimestampTzGetDatum(timestamp_add_seconds(0, resubmit));
642675
values[11] = Int64GetDatum(job->attempt + 1);
676+
nulls[4] = nulls[11] = ' ';
643677
n = 17;
644678
}
645679
else

contrib/pgpro_scheduler/src/scheduler_job.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* scheduler_job.h
4+
*
5+
* Copyright (c) 2017-2018, Postgres Professional
6+
*
7+
*-------------------------------------------------------------------------
8+
*/
19
#ifndef PGPRO_SCHEDULER_JOB_H
210
#define PGPRO_SCHEDULER_JOB_H
311

contrib/pgpro_scheduler/src/scheduler_manager.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
/*
2-
* contrib/pgpro_scheduler/src/scheduler_manager.c
1+
/*-------------------------------------------------------------------------
2+
*
3+
* scheduler_manager.c
4+
*
5+
* Copyright (c) 2017-2018, Postgres Professional
6+
*
7+
*-------------------------------------------------------------------------
38
*/
49
#include <stdlib.h>
510
#include "postgres.h"
@@ -954,14 +959,14 @@ void init_executor_shared_data(schd_executor_share_t *data, scheduler_manager_ct
954959
strcpy(data->database, ctx->database);
955960
else
956961
elog(ERROR, "String \"%s\"\n"
957-
"has %d symbols, while it should have less than %d symbols.",
962+
"has %lu symbols, while it should have less than %d symbols.",
958963
ctx->database, strlen(ctx->database), PGPRO_SCHEDULER_DBNAME_MAX);
959964

960965
if(strlen(job->node) < PGPRO_SCHEDULER_NODENAME_MAX)
961966
strcpy(data->nodename, job->node);
962967
else
963968
elog(ERROR, "String \"%s\"\n"
964-
"has %d symbols, while it should have less than %d symbols.",
969+
"has %lu symbols, while it should have less than %d symbols.",
965970
job->node, strlen(job->node), PGPRO_SCHEDULER_NODENAME_MAX);
966971

967972
data->new_job = true;
@@ -1791,19 +1796,18 @@ int start_at_worker(scheduler_manager_ctx_t *ctx, int pos)
17911796
item->res_owner = CurrentResourceOwner;
17921797
shm_data = dsm_segment_address(item->shared);
17931798

1794-
17951799
if(strlen(ctx->database) < PGPRO_SCHEDULER_DBNAME_MAX)
17961800
strcpy(shm_data->database, ctx->database);
17971801
else
17981802
elog(ERROR, "String \"%s\"\n"
1799-
"has %d symbols, while it should have less than %d symbols.",
1803+
"has %lu symbols, while it should have less than %d symbols.",
18001804
ctx->database, strlen(ctx->database), PGPRO_SCHEDULER_DBNAME_MAX);
18011805

18021806
if(strlen(ctx->nodename) < PGPRO_SCHEDULER_NODENAME_MAX)
18031807
strcpy(shm_data->nodename, ctx->nodename);
18041808
else
18051809
elog(ERROR, "String \"%s\"\n"
1806-
"has %d symbols, while it should have less than %d symbols.",
1810+
"has %lu symbols, while it should have less than %d symbols.",
18071811
ctx->nodename, strlen(ctx->nodename), PGPRO_SCHEDULER_NODENAME_MAX);
18081812

18091813
shm_data->stop_worker = false;

contrib/pgpro_scheduler/src/scheduler_manager.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* scheduler_manager.h
4+
*
5+
* Copyright (c) 2017-2018, Postgres Professional
6+
*
7+
*-------------------------------------------------------------------------
8+
*/
19
#ifndef PGPRO_SCHEDULER_MANAGER_H
210
#define PGPRO_SCHEDULER_MANAGER_H
311

contrib/pgpro_scheduler/src/scheduler_mtm.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* scheduler_mtm.c
4+
*
5+
* Copyright (c) 2017-2018, Postgres Professional
6+
*
7+
*-------------------------------------------------------------------------
8+
*/
19
#ifdef _WITH_MTM
210

311
/* This code is aimed to interact with Postgres Pro Multimaster extension

contrib/pgpro_scheduler/src/scheduler_mtm.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* scheduler_mtm.h
4+
*
5+
* Copyright (c) 2017-2018, Postgres Professional
6+
*
7+
*-------------------------------------------------------------------------
8+
*/
19
#ifdef _WITH_MTM
210
#ifndef SCHEDULER_MTM_H
311
#define SCHEDULER_MTM_H

contrib/pgpro_scheduler/src/scheduler_spi_utils.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* scheduler_spi_utils.c
4+
*
5+
* Copyright (c) 2017-2018, Postgres Professional
6+
*
7+
*-------------------------------------------------------------------------
8+
*/
19
#include "postgres.h"
210
#include "fmgr.h"
311
#include "executor/spi.h"

contrib/pgpro_scheduler/src/scheduler_spi_utils.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* scheduler_spi_utils.h
4+
*
5+
* Copyright (c) 2017-2018, Postgres Professional
6+
*
7+
*-------------------------------------------------------------------------
8+
*/
19
#ifndef PGPRO_SCHEDULER_SPI_H
210
#define PGPRO_SCHEDULER_SPI_H
311

0 commit comments

Comments
 (0)