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

Commit 9b5cf96

Browse files
author
Vladimir Ershov
committed
tests && fixes
1 parent be33043 commit 9b5cf96

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+203
-171
lines changed

pgpro_scheduler--2.1--2.2.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ CREATE TABLE mtm_nodes(
44
status_set timestamp with time zone
55
);
66

7+
CREATE FUNCTION pgpro_scheduler_version()
8+
RETURNS text
9+
AS 'MODULE_PATHNAME', 'pgpro_scheduler_version'
10+
LANGUAGE C IMMUTABLE;
11+

pgpro_scheduler--2.2.sql

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,15 @@ CREATE VIEW all_job_status AS
302302
-- -- AT EXECUTOR FUNCTIONS --
303303
------------------------------
304304

305-
CREATE FUNCTION set_state(state bool)
306-
RETURNS bool
307-
AS 'MODULE_PATHNAME', 'set_state'
308-
LANGUAGE C IMMUTABLE;
305+
CREATE FUNCTION pgpro_scheduler_version()
306+
RETURNS text
307+
AS 'MODULE_PATHNAME', 'pgpro_scheduler_version'
308+
LANGUAGE C IMMUTABLE;
309+
310+
-- CREATE FUNCTION set_state(state bool)
311+
-- RETURNS bool
312+
-- AS 'MODULE_PATHNAME', 'set_state'
313+
-- LANGUAGE C IMMUTABLE;
309314

310315
CREATE FUNCTION get_self_id()
311316
RETURNS bigint
@@ -391,6 +396,7 @@ BEGIN
391396
EXCEPTION
392397
WHEN NO_DATA_FOUND THEN
393398
RAISE EXCEPTION 'there is no such user %', executor;
399+
PERFORM onlySuperUser();
394400
-- TODO CHECK PERMISSION --
395401
-- SET SESSION AUTHORIZATION executor;
396402
-- RESET SESSION AUTHORIZATION;
@@ -684,8 +690,9 @@ BEGIN
684690
EXCEPTION
685691
WHEN NO_DATA_FOUND THEN
686692
RAISE EXCEPTION 'there is no such user %', executor;
687-
SET SESSION AUTHORIZATION executor;
688-
RESET SESSION AUTHORIZATION;
693+
PERFORM onlySuperUser();
694+
-- SET SESSION AUTHORIZATION executor;
695+
-- RESET SESSION AUTHORIZATION;
689696
END;
690697
ELSE
691698
executor := session_user;

src/pgpro_scheduler.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,20 @@ void _PG_init(void)
827827
pg_scheduler_startup();
828828
}
829829

830+
PG_FUNCTION_INFO_V1(pgpro_scheduler_version);
831+
Datum
832+
pgpro_scheduler_version(PG_FUNCTION_ARGS)
833+
{
834+
text *text_p;
835+
int len;
836+
837+
len = strlen(PGPRO_SCHEDULER_VERSION);
838+
text_p = (text *) palloc(sizeof(char)*len + VARHDRSZ);
839+
memcpy((void *)VARDATA(text_p), PGPRO_SCHEDULER_VERSION, len);
840+
SET_VARSIZE(text_p, sizeof(char)*len + VARHDRSZ);
841+
PG_RETURN_TEXT_P(text_p);
842+
}
843+
830844
PG_FUNCTION_INFO_V1(nodename);
831845
Datum
832846
nodename(PG_FUNCTION_ARGS)

src/pgpro_scheduler.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#define PPGS_NODEBUG 1
1515

1616
#ifdef _WITH_MTM
17-
#define PGPRO_SCHEDULER_VERSION "2.2.mtm"
17+
#define PGPRO_SCHEDULER_VERSION "2.2-mtm"
1818
#else
1919
#define PGPRO_SCHEDULER_VERSION "2.2"
2020
#endif
@@ -43,8 +43,11 @@ bool is_guc_in_default_state(const char *name);
4343

4444
void pg_scheduler_startup(void);
4545
char_array_t *readBasesToCheck(void);
46+
47+
extern Datum pgpro_scheduler_version(PG_FUNCTION_ARGS);
4648
extern Datum nodename(PG_FUNCTION_ARGS);
4749
extern Datum cron_string_to_json_text(PG_FUNCTION_ARGS);
50+
4851
void _PG_init(void);
4952
extern PGDLLEXPORT void parent_scheduler_main(Datum) pg_attribute_noreturn();
5053
int checkSchedulerNamespace(void);

src/scheduler_manager.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,7 +1809,7 @@ void manager_worker_main(Datum arg)
18091809
{
18101810
char database[NAMEDATALEN];
18111811
char buffer[1024];
1812-
int rc = 0, i;
1812+
int rc = 0;
18131813
schd_manager_share_t *shared;
18141814
dsm_segment *seg;
18151815
scheduler_manager_ctx_t *ctx;
@@ -1819,7 +1819,9 @@ void manager_worker_main(Datum arg)
18191819
MemoryContext longTerm;
18201820
Oid reloid;
18211821
int stop_by_parent = 0;
1822-
int time_to_check = 3;
1822+
#ifdef _WITH_MTM
1823+
int time_to_check = 3, i;
1824+
#endif
18231825

18241826

18251827
CurrentResourceOwner = ResourceOwnerCreate(NULL, "pgpro_scheduler");

src/scheduler_mtm.c

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@
4040
Oid scheduler_mtm_node_status_OID = InvalidOid;
4141
Oid scheduler_mtm_node_status_pkey_OID = InvalidOid;
4242
int is_mtm_present = -1;
43+
int smtm_max_nodes = -1; /* copy of MtmMaxNodes */
44+
int smtm_node_id = -1; /* copy of MtmNodeId */
4345

4446
MtmState *mtmState = NULL;
4547
extern volatile sig_atomic_t got_sigterm;
4648

47-
Oid scheduler_mtm_node_status_func_oid = InvalidOid;
4849
sched_mtm_node_list_t *MTM_nodes = NULL;
4950

5051
/* Returns Oid of "mtm_nodes" table
@@ -183,7 +184,7 @@ void set_mtm_node_status(bool status)
183184
}
184185

185186
indexScan = index_beginscan(nodes_heap, nodes_idx, SnapshotSelf, 1, 0);
186-
ScanKeyInit(&key, 1, BTEqualStrategyNumber, F_INT4EQ, Int32GetDatum(MtmNodeId));
187+
ScanKeyInit(&key, 1, BTEqualStrategyNumber, F_INT4EQ, Int32GetDatum(getMtmNodeId()));
187188
index_rescan(indexScan, &key, 1, NULL, 0);
188189
if(index_getnext_tid(indexScan, ForwardScanDirection))
189190
{
@@ -207,7 +208,7 @@ void set_mtm_node_status(bool status)
207208
}
208209
else
209210
{
210-
values[0] = Int32GetDatum(MtmNodeId);
211+
values[0] = Int32GetDatum(getMtmNodeId());
211212
values[1] = CStringGetTextDatum(node_name);
212213
values[2] = TimestampTzGetDatum(GetCurrentTimestamp());
213214

@@ -287,25 +288,46 @@ const char *check_multimaster_database(void)
287288
return NULL;
288289
}
289290

291+
/* Get Multimaster nodeId */
292+
293+
int getMtmNodeId(void)
294+
{
295+
const char *val;
296+
297+
if(smtm_node_id != -1) return smtm_node_id;
298+
299+
val = GetConfigOption("multimaster.node_id", true, false);
300+
if(!val)
301+
{
302+
elog(ERROR, "Cannot get multimaster.node_id value");
303+
}
304+
if(!parse_int(val, &smtm_node_id, 0 , NULL))
305+
{
306+
elog(ERROR, "Cannot parse multimaster.node_id value");
307+
}
308+
309+
return smtm_node_id;
310+
}
311+
290312
/* Get Multimaster max nodes */
291313

292314
int getMtmMaxNodes(void)
293315
{
294-
return MtmMaxNodes;
295-
/* int max_nodes = -1;
296316
const char *val;
297317

318+
if(smtm_max_nodes != -1) return smtm_max_nodes;
319+
298320
val = GetConfigOption("multimaster.max_nodes", true, false);
299321
if(!val)
300322
{
301323
elog(ERROR, "Cannot get multimaster.max_nodes value");
302324
}
303-
if(!parse_int(val, &max_nodes, 0 , NULL))
325+
if(!parse_int(val, &smtm_max_nodes, 0 , NULL))
304326
{
305327
elog(ERROR, "Cannot parse multimaster.max_nodes value");
306328
}
307329

308-
return max_nodes; */
330+
return smtm_max_nodes;
309331
}
310332

311333
void initializeMtmState(void)
@@ -449,7 +471,7 @@ void check_mtm_nodes_status(void)
449471
MTM_nodes->set = true;
450472
MTM_nodes->nodes[node_id-1].has_scheduler = true;
451473
MTM_nodes->set = true;
452-
if(min_avail == MtmNodeId && !MTM_nodes->nodes[node_id-1].avail)
474+
if(min_avail == getMtmNodeId() && !MTM_nodes->nodes[node_id-1].avail)
453475
{
454476
MTM_nodes->nodes[node_id-1].need_help = true;
455477
MTM_nodes->need_help++;
@@ -500,38 +522,6 @@ void print_log_mtm_nodes(void)
500522
LWLockRelease((LWLockId)&MTM_nodes->locks[0]);
501523
}
502524

503-
Oid get_mtm_node_func_oid(void)
504-
{
505-
Oid ns_oid, func_oid;
506-
CatCList *catlist;
507-
int i;
508-
509-
if(OidIsValid(scheduler_mtm_node_status_func_oid))
510-
return scheduler_mtm_node_status_func_oid;
511-
512-
ns_oid = LookupExplicitNamespace(MULTIMASTER_SCHEMA_NAME, true);
513-
if (!OidIsValid(ns_oid))
514-
elog(ERROR, "SCHEDULER: cannot get multimaster namespace");
515-
catlist = SearchSysCacheList1(PROCNAMEARGSNSP, CStringGetDatum("get_nodes_state"));
516-
for(i = 0; i < catlist->n_members; i++)
517-
{
518-
HeapTuple proctup = &catlist->members[i]->tuple;
519-
Form_pg_proc procform = (Form_pg_proc) GETSTRUCT(proctup);
520-
if(procform->pronargs == 0 && procform->pronamespace == ns_oid)
521-
{
522-
func_oid = HeapTupleGetOid(proctup);
523-
break;
524-
}
525-
}
526-
ReleaseSysCacheList(catlist);
527-
528-
if(!OidIsValid(func_oid))
529-
elog(ERROR, "SCHEDULER: cannot get multimaster function get_nodes_state");
530-
scheduler_mtm_node_status_func_oid = func_oid;
531-
532-
return func_oid;
533-
}
534-
535525
bool mtm_check_help_byNodeId(int node_id)
536526
{
537527
bool st = true;

src/scheduler_mtm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ const char *check_multimaster_database(void);
3232
void initializeMtmState(void);
3333
void mtm_scheduler_StartTransactionCommand(void);
3434
void check_mtm_nodes_status(void);
35+
int getMtmNodeId(void);
3536
int getMtmMaxNodes(void);
3637
sched_mtm_node_list_t *init_scheduler_mtm_nodes(void);
37-
Oid get_mtm_node_func_oid(void);
3838
void print_log_mtm_nodes(void);
3939
bool mtm_check_if_node_need_help(char *nodename);
4040
bool is_mtm_node_available(int node_id);

src/scheduler_mtm.o

-4.03 KB
Binary file not shown.

test/perl/runtest.pl

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,20 @@
1010
my $password;
1111
my $host;
1212
my $port;
13+
my $multimaster;
14+
1315
GetOptions (
1416
"--host=s" => \$host,
1517
"--port=s" => \$port,
1618
"--dbname=s" => \$dbname,
1719
"--username=s" => \$username,
18-
"--password=s" => \$password);
20+
"--password=s" => \$password,
21+
"--multimaster" => \$multimaster);
1922

2023
$dbname ||= '_pgpro_scheduler_test';
2124
$username ||= 'postgres';
2225

23-
my $adm_dsn = 'dbi:Pg:dbname=postgres';
26+
my $adm_dsn = $multimaster ? "dbi:Pg:dbname=$dbname": 'dbi:Pg:dbname=postgres';
2427
my $dsn = "dbi:Pg:dbname=$dbname";
2528

2629

@@ -37,7 +40,7 @@
3740

3841
print "Prepare test enviroment\n";
3942
my $dbh = DBI->connect($adm_dsn, $username, $password, {PrintError => 1});
40-
if($dbh->err != 0){
43+
if(!$dbh || $dbh->err != 0){
4144
print $DBI::errstr . "\n";
4245
exit(-1);
4346
}
@@ -68,15 +71,23 @@
6871
my @sqls = (
6972
"ALTER SYSTEM SET schedule.enabled=off",
7073
"SELECT pg_reload_conf()",
71-
"DROP DATABASE IF EXISTS $dbname",
72-
"CREATE DATABASE $dbname",
7374
);
75+
if(!$multimaster)
76+
{
77+
push @sqls, "DROP DATABASE IF EXISTS $dbname";
78+
push @sqls, "CREATE DATABASE $dbname";
79+
}
80+
else
81+
{
82+
push @sqls, "DROP TABLE IF EXISTS test_results";
83+
push @sqls, "DROP TABLE IF EXISTS task_info";
84+
}
7485

7586
map { __do_sql($dbh, $_) } @sqls;
7687
$dbh->disconnect();
7788

7889
$dbh = DBI->connect($dsn, $username, $password, {PrintError => 1});
79-
if($dbh->err != 0){
90+
if(!$dbh || $dbh->err != 0){
8091
print $DBI::errstr . "\n";
8192
exit(-1);
8293
}
@@ -99,7 +110,7 @@
99110

100111
print "Run tests\n";
101112

102-
my @db_param = ["--dbname=$dbname"];
113+
my @db_param = ( "--dbname=$dbname" );
103114
push @db_param, "--host=$host" if $host;
104115
push @db_param, "--port=$port" if $port;
105116
push @db_param, "--username=$username" if $username;

test/perl/t/activateJob.t

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ my $query = "DELETE FROM test_results;";
1313
$dbh->do($query);
1414
ok($dbh->err == 0) or (print $DBI::errstr and $dbh->disconnect() and BAIL_OUT);
1515

16-
$query = "SELECT schedule.create_job(NULL, '');";
16+
$query = "SELECT * from schedule.create_job(NULL, '');";
1717
my $sth = $dbh->prepare($query);
1818
$sth->execute();
1919
ok($dbh->err == 0) or (print $DBI::errstr and $dbh->disconnect() and BAIL_OUT);
2020
my $job_id = $sth->fetchrow_array() and $sth->finish();
2121
$sth->finish();
2222

23-
$query = "SELECT schedule.deactivate_job(?)";
23+
$query = "SELECT * from schedule.deactivate_job(?)";
2424
$sth = $dbh->prepare($query);
2525
$sth->bind_param(1, $job_id);
2626
ok($sth->execute()) or (print $DBI::errstr and $dbh->disconnect() and BAIL_OUT);
@@ -37,13 +37,13 @@ my %data = (
3737
use_same_transaction => "true"
3838
);
3939

40-
$query = "SELECT schedule.set_job_attributes(?, '". t::json(\%data) ."')";
40+
$query = "SELECT * from schedule.set_job_attributes(?, '". t::json(\%data) ."')";
4141
$sth = $dbh->prepare($query);
4242
$sth->bind_param(1, $job_id);
4343
ok($sth->execute()) or (print $DBI::errstr and $dbh->disconnect() and BAIL_OUT);
4444
$sth->finish();
4545

46-
$query = "SELECT schedule.activate_job(?)";
46+
$query = "SELECT * from schedule.activate_job(?)";
4747
$sth = $dbh->prepare($query);
4848
$sth->bind_param(1, $job_id);
4949
ok($sth->execute()) or (print $DBI::errstr and $dbh->disconnect() and BAIL_OUT);
@@ -57,7 +57,7 @@ ok($sth->execute()) or (print $DBI::errstr and $dbh->disconnect() and BAIL_OUT);
5757
my $result = $sth->fetchrow_array() and $sth->finish();
5858
ok ($result > 1) or print "Count == 0\n";
5959

60-
$query = "SELECT schedule.deactivate_job(?)";
60+
$query = "SELECT * from schedule.deactivate_job(?)";
6161
$sth = $dbh->prepare($query);
6262
$sth->bind_param(1, $job_id);
6363
ok($sth->execute()) or print $DBI::errstr ;
@@ -67,7 +67,7 @@ $query = "DELETE FROM test_results;";
6767
$dbh->do($query);
6868
ok($dbh->err == 0) or print $DBI::errstr;
6969

70-
$query = "SELECT schedule.drop_job(?)";
70+
$query = "SELECT * from schedule.drop_job(?)";
7171
$sth = $dbh->prepare($query);
7272
$sth->bind_param(1, $job_id);
7373
ok($sth->execute()) or print $DBI::errstr;

0 commit comments

Comments
 (0)