Introduce replication progress tracking infrastructure.
authorAndres Freund <andres@anarazel.de>
Wed, 29 Apr 2015 17:30:53 +0000 (19:30 +0200)
committerAndres Freund <andres@anarazel.de>
Wed, 29 Apr 2015 17:30:53 +0000 (19:30 +0200)
commit5aa2350426c4fdb3d04568b65aadac397012bbcb
tree954c3123dc58905bbda6407565383c65850204e7
parentc6e96a2f986e4dad72c14b14d4cc17d02b2a6aad
Introduce replication progress tracking infrastructure.

When implementing a replication solution ontop of logical decoding, two
related problems exist:
* How to safely keep track of replication progress
* How to change replication behavior, based on the origin of a row;
  e.g. to avoid loops in bi-directional replication setups

The solution to these problems, as implemented here, consist out of
three parts:

1) 'replication origins', which identify nodes in a replication setup.
2) 'replication progress tracking', which remembers, for each
   replication origin, how far replay has progressed in a efficient and
   crash safe manner.
3) The ability to filter out changes performed on the behest of a
   replication origin during logical decoding; this allows complex
   replication topologies. E.g. by filtering all replayed changes out.

Most of this could also be implemented in "userspace", e.g. by inserting
additional rows contain origin information, but that ends up being much
less efficient and more complicated.  We don't want to require various
replication solutions to reimplement logic for this independently. The
infrastructure is intended to be generic enough to be reusable.

This infrastructure also replaces the 'nodeid' infrastructure of commit
timestamps. It is intended to provide all the former capabilities,
except that there's only 2^16 different origins; but now they integrate
with logical decoding. Additionally more functionality is accessible via
SQL.  Since the commit timestamp infrastructure has also been introduced
in 9.5 (commit 73c986add) changing the API is not a problem.

For now the number of origins for which the replication progress can be
tracked simultaneously is determined by the max_replication_slots
GUC. That GUC is not a perfect match to configure this, but there
doesn't seem to be sufficient reason to introduce a separate new one.

Bumps both catversion and wal page magic.

Author: Andres Freund, with contributions from Petr Jelinek and Craig Ringer
Reviewed-By: Heikki Linnakangas, Petr Jelinek, Robert Haas, Steve Singer
Discussion: 20150216002155.GI15326@awork2.anarazel.de,
    20140923182422.GA15776@alap3.anarazel.de,
    20131114172632.GE7522@alap2.anarazel.de
52 files changed:
contrib/test_decoding/Makefile
contrib/test_decoding/expected/replorigin.out [new file with mode: 0644]
contrib/test_decoding/sql/replorigin.sql [new file with mode: 0644]
contrib/test_decoding/test_decoding.c
doc/src/sgml/catalogs.sgml
doc/src/sgml/filelist.sgml
doc/src/sgml/func.sgml
doc/src/sgml/logicaldecoding.sgml
doc/src/sgml/postgres.sgml
doc/src/sgml/replication-origins.sgml [new file with mode: 0644]
src/backend/access/heap/heapam.c
src/backend/access/rmgrdesc/Makefile
src/backend/access/rmgrdesc/replorigindesc.c [new file with mode: 0644]
src/backend/access/rmgrdesc/xactdesc.c
src/backend/access/transam/commit_ts.c
src/backend/access/transam/rmgr.c
src/backend/access/transam/xact.c
src/backend/access/transam/xlog.c
src/backend/access/transam/xloginsert.c
src/backend/access/transam/xlogreader.c
src/backend/catalog/Makefile
src/backend/catalog/catalog.c
src/backend/catalog/system_views.sql
src/backend/replication/logical/Makefile
src/backend/replication/logical/decode.c
src/backend/replication/logical/logical.c
src/backend/replication/logical/origin.c [new file with mode: 0644]
src/backend/replication/logical/reorderbuffer.c
src/backend/storage/ipc/ipci.c
src/backend/utils/cache/syscache.c
src/bin/pg_resetxlog/pg_resetxlog.c
src/include/access/commit_ts.h
src/include/access/rmgrlist.h
src/include/access/xact.h
src/include/access/xlog.h
src/include/access/xlog_internal.h
src/include/access/xlogdefs.h
src/include/access/xloginsert.h
src/include/access/xlogreader.h
src/include/access/xlogrecord.h
src/include/catalog/catversion.h
src/include/catalog/indexing.h
src/include/catalog/pg_proc.h
src/include/catalog/pg_replication_origin.h [new file with mode: 0644]
src/include/replication/logical.h
src/include/replication/origin.h [new file with mode: 0644]
src/include/replication/output_plugin.h
src/include/replication/reorderbuffer.h
src/include/storage/lwlock.h
src/include/utils/syscache.h
src/test/regress/expected/rules.out
src/test/regress/expected/sanity_check.out