agora inbox for [email protected]
help / color / mirror / Atom feedFrom: Andrey V. Lepikhov <[email protected]>
Subject: [PATCH 1/4] Relation-into-WAL-function
Date: Mon, 1 Apr 2019 08:33:46 +0500
---
src/backend/access/transam/generic_xlog.c | 48 +++++++++++++++++++++++
src/include/access/generic_xlog.h | 3 ++
2 files changed, 51 insertions(+)
diff --git a/src/backend/access/transam/generic_xlog.c b/src/backend/access/transam/generic_xlog.c
index 5b00b7275b..c22e361747 100644
--- a/src/backend/access/transam/generic_xlog.c
+++ b/src/backend/access/transam/generic_xlog.c
@@ -542,3 +542,51 @@ generic_mask(char *page, BlockNumber blkno)
mask_unused_space(page);
}
+
+/*
+ * Function to write generic xlog for every existing block of a relation.
+ * Caller is responsible for locking the relation exclusively.
+ */
+void
+generic_log_relation(Relation rel)
+{
+ BlockNumber blkno;
+ BlockNumber nblocks;
+ int npbuf = 0;
+ GenericXLogState *state = NULL;
+ Buffer bufpack[MAX_GENERIC_XLOG_PAGES];
+
+ CHECK_FOR_INTERRUPTS();
+ nblocks = RelationGetNumberOfBlocks(rel);
+
+ /*
+ * Iterate over all index pages and WAL-logging it. Pages are grouping into
+ * the packages before adding to a WAL-record. Zero-pages are
+ * not logged.
+ */
+ for (blkno = 0; blkno < nblocks; blkno++)
+ {
+ Buffer buf;
+
+ buf = ReadBuffer(rel, blkno);
+ if (!PageIsNew(BufferGetPage(buf)))
+ {
+ if (npbuf == 0)
+ state = GenericXLogStart(rel);
+
+ LockBuffer(buf, BUFFER_LOCK_EXCLUSIVE);
+ GenericXLogRegisterBuffer(state, buf, GENERIC_XLOG_FULL_IMAGE);
+ bufpack[npbuf++] = buf;
+ }
+ else
+ ReleaseBuffer(buf);
+
+ if ((npbuf == MAX_GENERIC_XLOG_PAGES) || (blkno == nblocks-1))
+ {
+ GenericXLogFinish(state);
+
+ for (; npbuf > 0; npbuf--)
+ UnlockReleaseBuffer(bufpack[npbuf-1]);
+ }
+ }
+}
diff --git a/src/include/access/generic_xlog.h b/src/include/access/generic_xlog.h
index cb5b5b713a..e3bbf014cc 100644
--- a/src/include/access/generic_xlog.h
+++ b/src/include/access/generic_xlog.h
@@ -42,4 +42,7 @@ extern const char *generic_identify(uint8 info);
extern void generic_desc(StringInfo buf, XLogReaderState *record);
extern void generic_mask(char *pagedata, BlockNumber blkno);
+/* other utils */
+extern void generic_log_relation(Relation rel);
+
#endif /* GENERIC_XLOG_H */
--
2.17.1
--------------5B85550EC82B346D9FBFC34E
Content-Type: text/x-patch;
name="v2_0002-GIN-Optimal-WAL-Usage.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="v2_0002-GIN-Optimal-WAL-Usage.patch"
view thread (18+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected]
Subject: Re: [PATCH 1/4] Relation-into-WAL-function
In-Reply-To: <no-message-id-1883167@localhost>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox