From 2076db2aea766c4c828dccc34ae35f614129000d Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Thu, 6 Nov 2014 13:52:08 +0200 Subject: [PATCH] Move the backup-block logic from XLogInsert to a new file, xloginsert.c. xlog.c is huge, this makes it a little bit smaller, which is nice. Functions related to putting together the WAL record are in xloginsert.c, and the lower level stuff for managing WAL buffers and such are in xlog.c. Also move the definition of XLogRecord to a separate header file. This causes churn in the #includes of all the files that write WAL records, and redo routines, but it avoids pulling in xlog.h into most places. Reviewed by Michael Paquier, Alvaro Herrera, Andres Freund and Amit Kapila. --- contrib/pg_xlogdump/pg_xlogdump.c | 2 +- doc/src/sgml/wal.sgml | 14 +- src/backend/access/gin/ginbtree.c | 1 + src/backend/access/gin/gindatapage.c | 1 + src/backend/access/gin/ginentrypage.c | 1 + src/backend/access/gin/ginfast.c | 1 + src/backend/access/gin/gininsert.c | 1 + src/backend/access/gin/ginutil.c | 1 + src/backend/access/gin/ginvacuum.c | 1 + src/backend/access/gist/gistbuild.c | 1 + src/backend/access/gist/gistxlog.c | 1 + src/backend/access/heap/heapam.c | 2 + src/backend/access/heap/pruneheap.c | 1 + src/backend/access/heap/rewriteheap.c | 1 + src/backend/access/heap/visibilitymap.c | 1 + src/backend/access/nbtree/nbtinsert.c | 1 + src/backend/access/nbtree/nbtpage.c | 2 + src/backend/access/nbtree/nbtree.c | 1 + src/backend/access/nbtree/nbtsort.c | 2 + src/backend/access/nbtree/nbtxlog.c | 2 + src/backend/access/spgist/spgdoinsert.c | 1 + src/backend/access/spgist/spginsert.c | 2 + src/backend/access/spgist/spgvacuum.c | 1 + src/backend/access/spgist/spgxlog.c | 1 + src/backend/access/transam/Makefile | 2 +- src/backend/access/transam/clog.c | 3 + src/backend/access/transam/multixact.c | 2 + src/backend/access/transam/twophase.c | 1 + src/backend/access/transam/varsup.c | 1 + src/backend/access/transam/xact.c | 2 + src/backend/access/transam/xlog.c | 759 +++--------------------- src/backend/access/transam/xloginsert.c | 633 ++++++++++++++++++++ src/backend/access/transam/xlogreader.c | 2 +- src/backend/access/transam/xlogutils.c | 121 ++++ src/backend/catalog/heap.c | 1 + src/backend/catalog/namespace.c | 1 + src/backend/catalog/storage.c | 2 + src/backend/commands/cluster.c | 1 + src/backend/commands/copy.c | 1 + src/backend/commands/createas.c | 1 + src/backend/commands/dbcommands.c | 1 + src/backend/commands/matview.c | 1 + src/backend/commands/sequence.c | 2 + src/backend/commands/tablecmds.c | 1 + src/backend/commands/tablespace.c | 2 + src/backend/commands/vacuumlazy.c | 1 + src/backend/commands/variable.c | 1 + src/backend/storage/buffer/bufmgr.c | 1 + src/backend/storage/file/fd.c | 1 + src/backend/storage/ipc/procarray.c | 3 +- src/backend/storage/ipc/standby.c | 1 + src/backend/storage/lmgr/lock.c | 1 + src/backend/storage/lmgr/predicate.c | 1 + src/backend/tcop/utility.c | 1 + src/backend/utils/adt/txid.c | 1 + src/backend/utils/cache/relcache.c | 1 + src/backend/utils/cache/relmapper.c | 2 + src/backend/utils/init/postinit.c | 1 + src/backend/utils/sort/tuplestore.c | 2 + src/backend/utils/time/tqual.c | 1 + src/bin/pg_resetxlog/pg_resetxlog.c | 1 + src/include/access/clog.h | 3 +- src/include/access/gin.h | 3 +- src/include/access/gin_private.h | 1 + src/include/access/gist_private.h | 1 + src/include/access/hash.h | 3 +- src/include/access/heapam_xlog.h | 4 +- src/include/access/multixact.h | 3 +- src/include/access/nbtree.h | 5 +- src/include/access/spgist.h | 3 +- src/include/access/spgist_private.h | 1 + src/include/access/xact.h | 4 +- src/include/access/xlog.h | 112 +--- src/include/access/xlog_internal.h | 38 +- src/include/access/xloginsert.h | 66 +++ src/include/access/xlogrecord.h | 100 ++++ src/include/access/xlogutils.h | 8 +- src/include/catalog/storage_xlog.h | 3 +- src/include/commands/dbcommands.h | 3 +- src/include/commands/sequence.h | 3 +- src/include/commands/tablespace.h | 3 +- src/include/replication/decode.h | 1 + src/include/storage/standby.h | 3 +- src/include/utils/relmapper.h | 3 +- 84 files changed, 1122 insertions(+), 855 deletions(-) create mode 100644 src/backend/access/transam/xloginsert.c create mode 100644 src/include/access/xloginsert.h create mode 100644 src/include/access/xlogrecord.h diff --git a/contrib/pg_xlogdump/pg_xlogdump.c b/contrib/pg_xlogdump/pg_xlogdump.c index adc9087a1d..7f151f961c 100644 --- a/contrib/pg_xlogdump/pg_xlogdump.c +++ b/contrib/pg_xlogdump/pg_xlogdump.c @@ -15,8 +15,8 @@ #include #include -#include "access/xlog.h" #include "access/xlogreader.h" +#include "access/xlogrecord.h" #include "access/transam.h" #include "common/fe_memutils.h" #include "getopt_long.h" diff --git a/doc/src/sgml/wal.sgml b/doc/src/sgml/wal.sgml index 0420610a01..6172a087f2 100644 --- a/doc/src/sgml/wal.sgml +++ b/doc/src/sgml/wal.sgml @@ -578,12 +578,12 @@ There are two commonly used internal WAL functions: - XLogInsert and XLogFlush. - XLogInsert is used to place a new record into + XLogInsertRecord and XLogFlush. + XLogInsertRecord is used to place a new record into the WAL buffers in shared memory. If there is no - space for the new record, XLogInsert will have + space for the new record, XLogInsertRecord will have to write (move to kernel cache) a few filled WAL - buffers. This is undesirable because XLogInsert + buffers. This is undesirable because XLogInsertRecord is used on every database low level modification (for example, row insertion) at a time when an exclusive lock is held on affected data pages, so the operation needs to be as fast as possible. What @@ -594,7 +594,7 @@ made, for the most part, at transaction commit time to ensure that transaction records are flushed to permanent storage. On systems with high log output, XLogFlush requests might - not occur often enough to prevent XLogInsert + not occur often enough to prevent XLogInsertRecord from having to do writes. On such systems one should increase the number of WAL buffers by modifying the parameter. When @@ -683,7 +683,7 @@ Enabling the configuration parameter (provided that PostgreSQL has been compiled with support for it) will result in each - XLogInsert and XLogFlush + XLogInsertRecord and XLogFlush WAL call being logged to the server log. This option might be replaced by a more general mechanism in the future. @@ -708,7 +708,7 @@ building the server). Each segment is divided into pages, normally 8 kB each (this size can be changed via the