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

Commit 32bc08b

Browse files
committed
Rethink the way walreceiver is linked into the backend. Instead than shoving
walreceiver as whole into a dynamically loaded module, split the libpq-specific parts of it into dynamically loaded module and keep the rest in the main backend binary. Although Tom fixed the Windows compilation problems with the old walreceiver module already, this is a cleaner division of labour and makes the code more readable. There's also the prospect of adding new transport methods as pluggable modules in the future, which this patch makes easier, though for now the API between libpqwalreceiver and walreceiver process should be considered private. The libpq-specific module is now in src/backend/replication/libpqwalreceiver, and the part linked with postgres binary is in src/backend/replication/walreceiver.c.
1 parent eb210ce commit 32bc08b

File tree

9 files changed

+441
-326
lines changed

9 files changed

+441
-326
lines changed

src/Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# Copyright (c) 1994, Regents of the University of California
66
#
7-
# $PostgreSQL: pgsql/src/Makefile,v 1.49 2010/01/15 17:01:06 heikki Exp $
7+
# $PostgreSQL: pgsql/src/Makefile,v 1.50 2010/01/20 09:16:23 heikki Exp $
88
#
99
#-------------------------------------------------------------------------
1010

@@ -21,7 +21,7 @@ all install installdirs uninstall distprep:
2121
$(MAKE) -C backend/snowball $@
2222
$(MAKE) -C include $@
2323
$(MAKE) -C interfaces $@
24-
$(MAKE) -C backend/replication/walreceiver $@
24+
$(MAKE) -C backend/replication/libpqwalreceiver $@
2525
$(MAKE) -C bin $@
2626
$(MAKE) -C pl $@
2727
$(MAKE) -C makefiles $@
@@ -52,7 +52,7 @@ clean:
5252
$(MAKE) -C backend/snowball $@
5353
$(MAKE) -C include $@
5454
$(MAKE) -C interfaces $@
55-
$(MAKE) -C backend/replication/walreceiver $@
55+
$(MAKE) -C backend/replication/libpqwalreceiver $@
5656
$(MAKE) -C bin $@
5757
$(MAKE) -C pl $@
5858
$(MAKE) -C makefiles $@
@@ -67,7 +67,7 @@ distclean maintainer-clean:
6767
$(MAKE) -C backend/snowball $@
6868
$(MAKE) -C include $@
6969
$(MAKE) -C interfaces $@
70-
$(MAKE) -C backend/replication/walreceiver $@
70+
$(MAKE) -C backend/replication/libpqwalreceiver $@
7171
$(MAKE) -C bin $@
7272
$(MAKE) -C pl $@
7373
$(MAKE) -C makefiles $@
@@ -82,7 +82,7 @@ coverage:
8282
$(MAKE) -C backend/utils/mb/conversion_procs $@
8383
$(MAKE) -C backend/snowball $@
8484
$(MAKE) -C interfaces $@
85-
$(MAKE) -C backend/replication/walreceiver $@
85+
$(MAKE) -C backend/replication/libpqwalreceiver $@
8686
$(MAKE) -C bin $@
8787
$(MAKE) -C pl $@
8888

src/backend/bootstrap/bootstrap.c

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.256 2010/01/15 09:19:00 heikki Exp $
11+
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.257 2010/01/20 09:16:23 heikki Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -425,20 +425,7 @@ AuxiliaryProcessMain(int argc, char *argv[])
425425

426426
case WalReceiverProcess:
427427
/* don't set signals, walreceiver has its own agenda */
428-
{
429-
PGFunction WalReceiverMain;
430-
431-
/*
432-
* Walreceiver is not linked directly into the server
433-
* binary because we would then need to link the server
434-
* with libpq. It's compiled as a dynamically loaded module
435-
* to avoid that.
436-
*/
437-
WalReceiverMain = load_external_function("walreceiver",
438-
"WalReceiverMain",
439-
true, NULL);
440-
WalReceiverMain(NULL);
441-
}
428+
WalReceiverMain();
442429
proc_exit(1); /* should never return */
443430

444431
default:

src/backend/replication/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
# Makefile for src/backend/replication
55
#
66
# IDENTIFICATION
7-
# $PostgreSQL: pgsql/src/backend/replication/Makefile,v 1.1 2010/01/15 09:19:03 heikki Exp $
7+
# $PostgreSQL: pgsql/src/backend/replication/Makefile,v 1.2 2010/01/20 09:16:24 heikki Exp $
88
#
99
#-------------------------------------------------------------------------
1010

1111
subdir = src/backend/replication
1212
top_builddir = ../../..
1313
include $(top_builddir)/src/Makefile.global
1414

15-
OBJS = walsender.o walreceiverfuncs.o
15+
OBJS = walsender.o walreceiverfuncs.o walreceiver.o
1616

1717
include $(top_srcdir)/src/backend/common.mk

src/backend/replication/README

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,36 @@
1-
$PostgreSQL: pgsql/src/backend/replication/README,v 1.1 2010/01/15 09:19:03 heikki Exp $
1+
$PostgreSQL: pgsql/src/backend/replication/README,v 1.2 2010/01/20 09:16:24 heikki Exp $
2+
3+
Walreceiver - libpqwalreceiver API
4+
----------------------------------
5+
6+
The transport-specific part of walreceiver, responsible for connecting to
7+
the primary server and receiving WAL files, is loaded dynamically to avoid
8+
having to link the main server binary with libpq. The dynamically loaded
9+
module is in libpqwalreceiver subdirectory.
10+
11+
The dynamically loaded module implements three functions:
12+
13+
14+
bool walrcv_connect(char *conninfo, XLogRecPtr startpoint)
15+
16+
Establish connection to the primary, and starts streaming from 'startpoint'.
17+
Returns true on success.
18+
19+
20+
bool walrcv_receive(int timeout, XLogRecPtr *recptr, char **buffer, int *len)
21+
22+
Retrieve any WAL record available through the connection, blocking for
23+
maximum of 'timeout' ms.
24+
25+
26+
void walrcv_disconnect(void);
27+
28+
Disconnect.
29+
30+
31+
This API should be considered internal at the moment, but we could open it
32+
up for 3rd party replacements of libpqwalreceiver in the future, allowing
33+
pluggable methods for receiveing WAL.
234

335
Walreceiver IPC
436
---------------

src/backend/replication/walreceiver/Makefile renamed to src/backend/replication/libpqwalreceiver/Makefile

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
#-------------------------------------------------------------------------
22
#
33
# Makefile--
4-
# Makefile for src/backend/replication/walreceiver
4+
# Makefile for src/backend/replication/libpqwalreceiver
55
#
66
# IDENTIFICATION
7-
# $PostgreSQL: pgsql/src/backend/replication/walreceiver/Makefile,v 1.4 2010/01/15 21:06:26 tgl Exp $
7+
# $PostgreSQL: pgsql/src/backend/replication/libpqwalreceiver/Makefile,v 1.1 2010/01/20 09:16:24 heikki Exp $
88
#
99
#-------------------------------------------------------------------------
1010

11-
subdir = src/backend/replication/walreceiver
11+
subdir = src/backend/postmaster/libpqwalreceiver
1212
top_builddir = ../../../..
1313
include $(top_builddir)/src/Makefile.global
1414

15-
override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS)
16-
17-
OBJS = walreceiver.o
15+
override CPPFLAGS := -I$(srcdir) -I$(libpq_srcdir) $(CPPFLAGS)
1816

17+
OBJS = libpqwalreceiver.o
1918
SHLIB_LINK = $(libpq)
20-
21-
NAME := walreceiver
19+
NAME = libpqwalreceiver
2220

2321
all: submake-libpq all-shared-lib
2422

0 commit comments

Comments
 (0)