Skip to content

Commit 3bbb8fa

Browse files
committed
Introduce version info for pglogical
Start at version 1.0.0. Make the extension script reflect that. Generate the control file based on the version parsed out of pglogical.h. This ensures the extension version always matches the version in the code. That was a source of confusion with BDR. It means we need dummy extension scripts for code-only bumps, but that's pretty harmless and usefully explicit. We can generate them with the Makefile if desired. Add information functions to get the protocol versions and pglogical version, and tests for them. Introduce 'dist' and 'git-dist' make targets with support for generating dist tarballs, checksums and detached signatures for release management.
1 parent 9a703cc commit 3bbb8fa

File tree

9 files changed

+131
-7
lines changed

9 files changed

+131
-7
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ pglogical_create_subscriber
55
*.o
66
*.so
77
*~
8+
pglogical.control
9+
pglogical-*.tar.bz2
10+
pglogical-*.tar.bz2.md5
11+
pglogical-*.tar.bz2.asc

Makefile

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ MODULE_big = pglogical
44
EXTENSION = pglogical
55
PGFILEDESC = "pglogical - logical replication"
66

7-
DATA = pglogical--1.0.sql
7+
DATA = pglogical--1.0.0.sql
88

99
OBJS = pglogical_apply.o pglogical_conflict.o pglogical_manager.o \
1010
pglogical_node.o pglogical_proto.o pglogical_relcache.o \
@@ -18,7 +18,13 @@ SCRIPTS_built = pglogical_create_subscriber
1818
PG_CPPFLAGS = -I$(libpq_srcdir)
1919
SHLIB_LINK = $(libpq)
2020

21-
REGRESS = preseed init_fail init preseed_check basic extended toasted replication_set add_table matview bidirectional primary_key foreign_key functions drop
21+
REGRESS = preseed infofuncs init_fail init preseed_check basic extended toasted replication_set add_table matview bidirectional primary_key foreign_key functions drop
22+
23+
EXTRA_CLEAN += pglogical.control
24+
25+
# The # in #define is taken as a comment, per https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=142043
26+
# so it must be escaped. The $ placeholders in awk must be doubled too.
27+
pglogical_version=$(shell awk '/\#define PGLOGICAL_VERSION[ \t]+\".*\"/ { print substr($$3,2,length($$3)-2) }' pglogical.h )
2228

2329
ifdef USE_PGXS
2430

@@ -91,4 +97,35 @@ EXTRA_REGRESS_OPTS += $(top_srcdir)/contrib/regress-postgresql.conf
9197

9298
endif
9399

100+
pglogical.control: pglogical.control.in pglogical.h
101+
sed 's/__PGLOGICAL_VERSION__/$(pglogical_version)/' pglogical.control.in > pglogical.control
102+
103+
all: pglogical.control
104+
105+
GITHASH=$(shell if [ -e .distgitrev ]; then cat .distgitrev; else git rev-parse --short HEAD; fi)
106+
107+
dist-common: clean
108+
@if test "$(wanttag)" -eq 1 -a "`git name-rev --tags --name-only $(GITHASH)`" = "undefined"; then echo "cannot 'make dist' on untagged tree; tag it or use make git-dist"; exit 1; fi
109+
@rm -f .distgitrev .distgittag
110+
@if ! git diff-index --quiet HEAD; then echo >&2 "WARNING: git working tree has uncommitted changes to tracked files which were INCLUDED"; fi
111+
@if [ -n "`git ls-files --exclude-standard --others`" ]; then echo >&2 "WARNING: git working tree has unstaged files which were IGNORED!"; fi
112+
@echo $(GITHASH) > .distgitrev
113+
@git name-rev --tags --name-only `cat .distgitrev` > .distgittag
114+
@git ls-tree -r -t --full-tree HEAD --name-only |\
115+
tar cjf "${distdir}.tar.bz2" --transform="s|^|${distdir}/|" -T - \
116+
.distgitrev .distgittag
117+
@echo >&2 "Prepared ${distdir}.tar.bz2 for rev=`cat .distgitrev`, tag=`cat .distgittag`"
118+
@rm -f .distgitrev .distgittag
119+
@md5sum "${distdir}.tar.bz2" > "${distdir}.tar.bz2.md5"
120+
@if test -n "$(GPGSIGNKEYS)"; then gpg -q -a -b $(shell for x in $(GPGSIGNKEYS); do echo -u $$x; done) "${distdir}.tar.bz2"; else echo "No GPGSIGNKEYS passed, not signing tarball. Pass space separated keyid list as make var to sign."; fi
121+
122+
dist: distdir=pglogical-$(pglogical_version)
123+
dist: wanttag=1
124+
dist: dist-common
125+
126+
git-dist: distdir=pglogical-$(pglogical_version)_git$(GITHASH)
127+
git-dist: wanttag=0
128+
git-dist: dist-common
129+
130+
94131
.PHONY: regresscheck

expected/infofuncs.out

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
CREATE EXTENSION pglogical;
2+
SELECT pglogical.pglogical_max_proto_version();
3+
pglogical_max_proto_version
4+
-----------------------------
5+
1
6+
(1 row)
7+
8+
SELECT pglogical.pglogical_min_proto_version();
9+
pglogical_min_proto_version
10+
-----------------------------
11+
1
12+
(1 row)
13+
14+
SELECT pglogical.pglogical_version() = extversion
15+
FROM pg_extension
16+
WHERE extname = 'pglogical';
17+
?column?
18+
----------
19+
t
20+
(1 row)
21+
22+
DROP EXTENSION pglogical;

pglogical--1.0.sql renamed to pglogical--1.0.0.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,15 @@ STABLE STRICT LANGUAGE c AS 'MODULE_PATHNAME';
187187
CREATE FUNCTION pglogical.pglogical_gen_slot_name(name, name, name)
188188
RETURNS name
189189
IMMUTABLE STRICT LANGUAGE c AS 'MODULE_PATHNAME';
190+
191+
CREATE FUNCTION pglogical_version() RETURNS text
192+
LANGUAGE c AS 'MODULE_PATHNAME';
193+
194+
CREATE FUNCTION pglogical_version_num() RETURNS integer
195+
LANGUAGE c AS 'MODULE_PATHNAME';
196+
197+
CREATE FUNCTION pglogical_max_proto_version() RETURNS integer
198+
LANGUAGE c AS 'MODULE_PATHNAME';
199+
200+
CREATE FUNCTION pglogical_min_proto_version() RETURNS integer
201+
LANGUAGE c AS 'MODULE_PATHNAME';

pglogical.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,9 @@ pglogical_start_replication(PGconn *streamConn, const char *slot_name,
197197
/* Basic protocol info. */
198198
appendStringInfo(&command, "expected_encoding '%s'",
199199
GetDatabaseEncodingName());
200-
appendStringInfo(&command, ", min_proto_version '1'");
201-
appendStringInfo(&command, ", max_proto_version '1'");
200+
appendStringInfo(&command, ", min_proto_version '%d'", PGLOGICAL_MIN_PROTO_VERSION_NUM);
201+
appendStringInfo(&command, ", max_proto_version '%d'", PGLOGICAL_MAX_PROTO_VERSION_NUM);
202202
appendStringInfo(&command, ", startup_params_format '1'");
203-
appendStringInfo(&command, ", pg_version '%u'", PG_VERSION_NUM);
204203

205204
/* Binary protocol compatibility. */
206205
appendStringInfo(&command, ", \"binary.want_internal_basetypes\" '1'");
@@ -243,7 +242,6 @@ pglogical_start_replication(PGconn *streamConn, const char *slot_name,
243242
appendStringInfoString(&command,
244243
", \"hooks.setup_function\" 'pglogical.pglogical_hooks_setup'");
245244

246-
247245
if (forward_origins)
248246
appendStringInfo(&command, ", \"pglogical.forward_origins\" %s",
249247
quote_literal_cstr(forward_origins));
@@ -265,6 +263,11 @@ pglogical_start_replication(PGconn *streamConn, const char *slot_name,
265263
/* Tell the upstream that we want unbounded metadata cache size */
266264
appendStringInfoString(&command, ", \"relmeta_cache_size\" '-1'");
267265

266+
/* general info about the downstream */
267+
appendStringInfo(&command, ", pg_version '%u'", PG_VERSION_NUM);
268+
appendStringInfo(&command, ", pglogical_version '%s'", PGLOGICAL_VERSION);
269+
appendStringInfo(&command, ", pglogical_version_num '%d'", PGLOGICAL_VERSION_NUM);
270+
268271
appendStringInfoChar(&command, ')');
269272

270273
res = PQexec(streamConn, command.data);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# pglogical extension
22
comment = 'PostgreSQL Logical Replication'
3-
default_version = '1.0'
3+
default_version = '__PGLOGICAL_VERSION__'
44
module_pathname = '$libdir/pglogical'
55
relocatable = false
66
schema = pglogical

pglogical.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626
#include "pglogical_compat.h"
2727
#endif
2828

29+
#define PGLOGICAL_VERSION "1.0.0"
30+
#define PGLOGICAL_VERSION_NUM 10000
31+
32+
#define PGLOGICAL_MIN_PROTO_VERSION_NUM 1
33+
#define PGLOGICAL_MAX_PROTO_VERSION_NUM 1
34+
2935
#define EXTENSION_NAME "pglogical"
3036

3137
#define PGLOGICAL_MASTER_TOC_MAGIC 123

pglogical_functions.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ PG_FUNCTION_INFO_V1(pglogical_dependency_check_trigger);
102102
PG_FUNCTION_INFO_V1(pglogical_gen_slot_name);
103103
PG_FUNCTION_INFO_V1(pglogical_node_info);
104104

105+
/* Information */
106+
PG_FUNCTION_INFO_V1(pglogical_version);
107+
PG_FUNCTION_INFO_V1(pglogical_version_num);
108+
PG_FUNCTION_INFO_V1(pglogical_min_proto_version);
109+
PG_FUNCTION_INFO_V1(pglogical_max_proto_version);
110+
105111
static void gen_slot_name(Name slot_name, char *dbname,
106112
const char *provider_name,
107113
const char *subscriber_name);
@@ -1505,3 +1511,26 @@ gen_slot_name(Name slot_name, char *dbname, const char *provider_node,
15051511
NameStr(*slot_name)[NAMEDATALEN-1] = '\0';
15061512
}
15071513

1514+
Datum
1515+
pglogical_version(PG_FUNCTION_ARGS)
1516+
{
1517+
PG_RETURN_TEXT_P(cstring_to_text(PGLOGICAL_VERSION));
1518+
}
1519+
1520+
Datum
1521+
pglogical_version_num(PG_FUNCTION_ARGS)
1522+
{
1523+
PG_RETURN_INT32(PGLOGICAL_VERSION_NUM);
1524+
}
1525+
1526+
Datum
1527+
pglogical_max_proto_version(PG_FUNCTION_ARGS)
1528+
{
1529+
PG_RETURN_INT32(PGLOGICAL_MAX_PROTO_VERSION_NUM);
1530+
}
1531+
1532+
Datum
1533+
pglogical_min_proto_version(PG_FUNCTION_ARGS)
1534+
{
1535+
PG_RETURN_INT32(PGLOGICAL_MIN_PROTO_VERSION_NUM);
1536+
}

sql/infofuncs.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CREATE EXTENSION pglogical;
2+
3+
SELECT pglogical.pglogical_max_proto_version();
4+
5+
SELECT pglogical.pglogical_min_proto_version();
6+
7+
SELECT pglogical.pglogical_version() = extversion
8+
FROM pg_extension
9+
WHERE extname = 'pglogical';
10+
11+
DROP EXTENSION pglogical;

0 commit comments

Comments
 (0)