Skip to content

Commit

Permalink
Do not wallog AUX files at replica (#515)
Browse files Browse the repository at this point in the history
Co-authored-by: Konstantin Knizhnik <knizhnik@neon.tech>
  • Loading branch information
knizhnik and Konstantin Knizhnik authored Nov 11, 2024
1 parent ea70383 commit de0a000
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/backend/access/heap/rewriteheap.c
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,11 @@ static void
wallog_mapping_file(char const* path, int fd)
{
char prefix[MAXPGPATH];

/* Do not wallog AUX file at replica */
if (!XLogInsertAllowed())
return;

snprintf(prefix, sizeof(prefix), "neon-file:%s", path);
if (fd < 0)
{
Expand Down
20 changes: 14 additions & 6 deletions src/backend/replication/logical/snapbuild.c
Original file line number Diff line number Diff line change
Expand Up @@ -1737,9 +1737,13 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn)
(errcode_for_file_access(),
errmsg("could not open file \"%s\": %m", tmppath)));

/* NEON specific: persist snapshot in storage using logical message */
snprintf(prefix, sizeof(prefix), "neon-file:%s", path);
XLogFlush(LogLogicalMessage(prefix, (char*)ondisk, needed_length, false));
/* Do not wallog AUX file at replica */
if (XLogInsertAllowed())
{
/* NEON specific: persist snapshot in storage using logical message */
snprintf(prefix, sizeof(prefix), "neon-file:%s", path);
XLogFlush(LogLogicalMessage(prefix, (char*)ondisk, needed_length, false));
}

errno = 0;
pgstat_report_wait_start(WAIT_EVENT_SNAPBUILD_WRITE);
Expand Down Expand Up @@ -2106,9 +2110,13 @@ CheckPointSnapBuild(void)
{
elog(DEBUG1, "removing snapbuild snapshot %s", path);

/* NEON specific: delete file from storage using logical message */
snprintf(prefix, sizeof(prefix), "neon-file:%s", path);
XLogFlush(LogLogicalMessage(prefix, NULL, 0, false));
/* Do not wallog AUX file at replica */
if (XLogInsertAllowed())
{
/* NEON specific: delete file from storage using logical message */
snprintf(prefix, sizeof(prefix), "neon-file:%s", path);
XLogFlush(LogLogicalMessage(prefix, NULL, 0, false));
}

/*
* It's not particularly harmful, though strange, if we can't
Expand Down
4 changes: 2 additions & 2 deletions src/backend/replication/slot.c
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ ReplicationSlotDropPtr(ReplicationSlot *slot)
sprintf(path, "pg_replslot/%s", NameStr(slot->data.name));
sprintf(tmppath, "pg_replslot/%s.tmp", NameStr(slot->data.name));

if (SlotIsLogical(slot))
if (SlotIsLogical(slot) && XLogInsertAllowed())
{
/* NEON specific: delete slot from storage using logical message */
char prefix[MAXPGPATH];
Expand Down Expand Up @@ -1579,7 +1579,7 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
SnapBuildOnDiskChecksummedSize);
FIN_CRC32C(cp.checksum);

if (SlotIsLogical(slot) && cp.slotdata.restart_lsn != InvalidXLogRecPtr)
if (SlotIsLogical(slot) && XLogInsertAllowed() && cp.slotdata.restart_lsn != InvalidXLogRecPtr)
{
/* NEON specific: persist slot in storage using logical message */
char prefix[MAXPGPATH];
Expand Down

0 comments on commit de0a000

Please sign in to comment.