Skip to content

Commit a50d80c

Browse files
committed
Only allocate and use the buffer for SLRU segment with the old
communicator.
1 parent eac5279 commit a50d80c

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

src/backend/access/transam/slru.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,12 @@ SimpleLruDownloadSegment(SlruCtl ctl, int pageno, char const* path)
762762
}
763763
segno = pageno / SLRU_PAGES_PER_SEGMENT;
764764

765-
buffer = palloc(BLCKSZ * SLRU_PAGES_PER_SEGMENT);
765+
if (neon_use_communicator_worker) {
766+
buffer = NULL;
767+
} else {
768+
buffer = palloc(BLCKSZ * SLRU_PAGES_PER_SEGMENT);
769+
}
770+
766771
n_blocks = smgr_read_slru_segment(&dummy_smgr_rel, path, segno, buffer);
767772
if (n_blocks > 0)
768773
{
@@ -774,22 +779,25 @@ SimpleLruDownloadSegment(SlruCtl ctl, int pageno, char const* path)
774779
pfree(buffer);
775780
return -1;
776781
}
777-
errno = 0;
778-
pgstat_report_wait_start(WAIT_EVENT_SLRU_WRITE);
779-
if (pg_pwrite(fd, buffer, n_blocks*BLCKSZ, 0) != n_blocks*BLCKSZ)
780-
{
781-
pgstat_report_wait_end();
782-
/* if write didn't set errno, assume problem is no disk space */
783-
if (errno == 0)
784-
errno = ENOSPC;
785-
slru_errcause = SLRU_WRITE_FAILED;
786-
slru_errno = errno;
787782

788-
CloseTransientFile(fd);
789-
pfree(buffer);
790-
return -1;
783+
if (!neon_use_communicator_worker) {
784+
errno = 0;
785+
pgstat_report_wait_start(WAIT_EVENT_SLRU_WRITE);
786+
if (pg_pwrite(fd, buffer, n_blocks*BLCKSZ, 0) != n_blocks*BLCKSZ)
787+
{
788+
pgstat_report_wait_end();
789+
/* if write didn't set errno, assume problem is no disk space */
790+
if (errno == 0)
791+
errno = ENOSPC;
792+
slru_errcause = SLRU_WRITE_FAILED;
793+
slru_errno = errno;
794+
795+
CloseTransientFile(fd);
796+
pfree(buffer);
797+
return -1;
798+
}
799+
pgstat_report_wait_end();
791800
}
792-
pgstat_report_wait_end();
793801
}
794802
pfree(buffer);
795803
return fd;

src/backend/utils/init/globals.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ pid_t PostmasterPid = 0;
116116
bool IsPostmasterEnvironment = false;
117117
bool IsUnderPostmaster = false;
118118
bool IsBinaryUpgrade = false;
119+
bool neon_use_communicator_worker = false;
119120

120121
bool ExitOnAnyError = false;
121122

src/include/miscadmin.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ extern PGDLLIMPORT pid_t PostmasterPid;
170170
extern PGDLLIMPORT bool IsPostmasterEnvironment;
171171
extern PGDLLIMPORT bool IsUnderPostmaster;
172172
extern PGDLLIMPORT bool IsBinaryUpgrade;
173+
/* Whether the communicator worker is used or not. Defined here so that
174+
* it is also accessible from the main postgres code easily without
175+
* having to look up the value using strings and chain of other
176+
* functions.
177+
*/
178+
extern PGDLLIMPORT bool neon_use_communicator_worker;
173179

174180
extern PGDLLIMPORT bool ExitOnAnyError;
175181

0 commit comments

Comments
 (0)