Skip to content

Commit d23f5b8

Browse files
committed
Move referee to a separate extension
1 parent d3c47cf commit d23f5b8

File tree

7 files changed

+56
-34
lines changed

7 files changed

+56
-34
lines changed

contrib/mmts/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ COPY ./ /pg/mmts/
66
RUN export USE_PGXS=1 && \
77
cd /pg/mmts && make clean && make install
88

9+
RUN export USE_PGXS=1 && \
10+
cd /pg/src/contrib/referee && make clean && make install
11+
912
# pg_regress client assumes such dir exists on server
1013
RUN cp /pg/src/src/test/regress/*.so /pg/install/lib/postgresql/
1114
USER postgres

contrib/mmts/multimaster--1.0.sql

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -151,30 +151,3 @@ $$
151151
LANGUAGE plpgsql;
152152

153153
-- select mtm.alter_sequences();
154-
155-
-- referee stuff
156-
CREATE TABLE IF NOT EXISTS mtm.referee_decision(key text primary key not null, node_id int);
157-
158-
CREATE OR REPLACE FUNCTION mtm.referee_get_winner(applicant_id int) RETURNS int AS
159-
$$
160-
DECLARE
161-
winner_id int;
162-
BEGIN
163-
insert into mtm.referee_decision values ('winner', applicant_id);
164-
select node_id into winner_id from mtm.referee_decision where key = 'winner';
165-
return winner_id;
166-
EXCEPTION WHEN others THEN
167-
select node_id into winner_id from mtm.referee_decision where key = 'winner';
168-
return winner_id;
169-
END
170-
$$
171-
LANGUAGE plpgsql;
172-
173-
CREATE OR REPLACE FUNCTION mtm.referee_clean() RETURNS bool AS
174-
$$
175-
BEGIN
176-
delete from mtm.referee_decision where key = 'winner';
177-
return 'true';
178-
END
179-
$$
180-
LANGUAGE plpgsql;

contrib/mmts/state.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ MtmRefreshClusterStatus()
417417
}
418418

419419
/*
420-
* Clear winner if we again have all nodes are online.
420+
* Clear winner if we again have all nodes online.
421421
*/
422422
if (MtmRefereeConnStr && *MtmRefereeConnStr && Mtm->refereeWinnerId &&
423423
countZeroBits(SELF_CONNECTIVITY_MASK, Mtm->nAllNodes) == Mtm->nAllNodes)
@@ -511,13 +511,13 @@ MtmRefereeGetWinner(void)
511511
return -1;
512512
}
513513

514-
sprintf(sql, "select mtm.referee_get_winner(%d)", MtmNodeId);
514+
sprintf(sql, "select referee.get_winner(%d)", MtmNodeId);
515515
res = PQexec(conn, sql);
516516
if (PQresultStatus(res) != PGRES_TUPLES_OK ||
517517
PQntuples(res) != 1 ||
518518
PQnfields(res) != 1)
519519
{
520-
MTM_ELOG(WARNING, "Refusing unexpected result (r=%d, n=%d, w=%d, k=%s) from referee.",
520+
MTM_ELOG(WARNING, "Refusing unexpected result (r=%d, n=%d, w=%d, k=%s) from referee.get_winner()",
521521
PQresultStatus(res), PQntuples(res), PQnfields(res), PQgetvalue(res, 0, 0));
522522
PQclear(res);
523523
PQfinish(conn);
@@ -558,12 +558,12 @@ MtmRefereeClearWinner(void)
558558
return false;
559559
}
560560

561-
res = PQexec(conn, "select mtm.referee_clean()");
561+
res = PQexec(conn, "select referee.clean()");
562562
if (PQresultStatus(res) != PGRES_TUPLES_OK ||
563563
PQntuples(res) != 1 ||
564564
PQnfields(res) != 1)
565565
{
566-
MTM_ELOG(WARNING, "Refusing unexpected result (r=%d, n=%d, w=%d, k=%s) from referee_clean().",
566+
MTM_ELOG(WARNING, "Refusing unexpected result (r=%d, n=%d, w=%d, k=%s) from referee.clean().",
567567
PQresultStatus(res), PQntuples(res), PQnfields(res), PQgetvalue(res, 0, 0));
568568
PQclear(res);
569569
PQfinish(conn);
@@ -574,7 +574,7 @@ MtmRefereeClearWinner(void)
574574

575575
if (strncmp(response, "t", 1) != 0)
576576
{
577-
MTM_ELOG(WARNING, "Wrong response from referee_clean(): '%s'", response);
577+
MTM_ELOG(WARNING, "Wrong response from referee.clean(): '%s'", response);
578578
PQclear(res);
579579
PQfinish(conn);
580580
return false;

contrib/mmts/tests2/test_referee.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def setUpClass(cls):
3535
cls.client.bgrun()
3636

3737
# create extension on referee
38-
cls.nodeExecute("dbname=regression user=postgres host=127.0.0.1 port=15435", ['create extension multimaster'])
38+
cls.nodeExecute("dbname=regression user=postgres host=127.0.0.1 port=15435", ['create extension referee'])
3939

4040
@classmethod
4141
def tearDownClass(cls):

contrib/referee/Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
EXTENSION = referee
2+
DATA = referee--1.0.sql
3+
4+
ifdef USE_PGXS
5+
PG_CONFIG = pg_config
6+
PGXS := $(shell $(PG_CONFIG) --pgxs)
7+
include $(PGXS)
8+
else
9+
subdir = contrib/referee
10+
top_builddir = ../..
11+
include $(top_builddir)/src/Makefile.global
12+
include $(top_srcdir)/contrib/contrib-global.mk
13+
endif

contrib/referee/referee--1.0.sql

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
2+
\echo Use "CREATE EXTENSION referee" to load this file. \quit
3+
4+
CREATE TABLE IF NOT EXISTS referee.decision(key text primary key not null, node_id int);
5+
6+
CREATE OR REPLACE FUNCTION referee.get_winner(applicant_id int) RETURNS int AS
7+
$$
8+
DECLARE
9+
winner_id int;
10+
BEGIN
11+
insert into referee.decision values ('winner', applicant_id);
12+
select node_id into winner_id from referee.decision where key = 'winner';
13+
return winner_id;
14+
EXCEPTION WHEN others THEN
15+
select node_id into winner_id from referee.decision where key = 'winner';
16+
return winner_id;
17+
END
18+
$$
19+
LANGUAGE plpgsql;
20+
21+
CREATE OR REPLACE FUNCTION referee.clean() RETURNS bool AS
22+
$$
23+
BEGIN
24+
delete from referee.decision where key = 'winner';
25+
return 'true';
26+
END
27+
$$
28+
LANGUAGE plpgsql;

contrib/referee/referee.control

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
comment = 'Multimaster referee'
2+
default_version = '1.0'
3+
module_pathname = '$libdir/referee'
4+
schema = referee
5+
relocatable = false

0 commit comments

Comments
 (0)