Skip to content

Commit b792941

Browse files
lubennikovaavMMeent
authored andcommitted
fix wal-redo buffer management
TODO: the logic around wal_redo + local buffers in other places too.
1 parent 61ae864 commit b792941

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/backend/storage/buffer/bufmgr.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ PrefetchBuffer(Relation reln, ForkNumber forkNum, BlockNumber blockNum)
658658
Assert(RelationIsValid(reln));
659659
Assert(BlockNumberIsValid(blockNum));
660660

661-
if (RelationUsesLocalBuffers(reln))
661+
if (RelationUsesLocalBuffers(reln) || am_wal_redo_postgres)
662662
{
663663
/* see comments in ReadBufferExtended */
664664
if (RELATION_IS_OTHER_TEMP(reln))
@@ -1057,7 +1057,7 @@ ZeroAndLockBuffer(Buffer buffer, ReadBufferMode mode, bool already_valid)
10571057
}
10581058
else if (isLocalBuf)
10591059
{
1060-
Assert(BufferIsLocal(buffer));
1060+
Assert(BufferIsLocal(buffer) || am_wal_redo_postgres);
10611061
/* Simple case for non-shared buffers. */
10621062
bufHdr = GetLocalBufferDescriptor(-buffer - 1);
10631063
need_to_zero = StartLocalBufferIO(bufHdr, true, false);
@@ -1138,7 +1138,7 @@ PinBufferForBlock(Relation rel,
11381138
persistence == RELPERSISTENCE_PERMANENT ||
11391139
persistence == RELPERSISTENCE_UNLOGGED));
11401140

1141-
if (persistence == RELPERSISTENCE_TEMP)
1141+
if (persistence == RELPERSISTENCE_TEMP || am_wal_redo_postgres)
11421142
{
11431143
io_context = IOCONTEXT_NORMAL;
11441144
io_object = IOOBJECT_TEMP_RELATION;
@@ -1155,7 +1155,7 @@ PinBufferForBlock(Relation rel,
11551155
smgr->smgr_rlocator.locator.relNumber,
11561156
smgr->smgr_rlocator.backend);
11571157

1158-
if (persistence == RELPERSISTENCE_TEMP)
1158+
if (persistence == RELPERSISTENCE_TEMP || am_wal_redo_postgres)
11591159
{
11601160
bufHdr = LocalBufferAlloc(smgr, forkNum, blockNum, foundPtr);
11611161
if (*foundPtr)
@@ -1652,7 +1652,7 @@ WaitReadBuffers(ReadBuffersOperation *operation)
16521652
IOContext io_context;
16531653
IOObject io_object;
16541654

1655-
if (operation->persistence == RELPERSISTENCE_TEMP)
1655+
if (operation->persistence == RELPERSISTENCE_TEMP || am_wal_redo_postgres)
16561656
{
16571657
io_context = IOCONTEXT_NORMAL;
16581658
io_object = IOOBJECT_TEMP_RELATION;
@@ -1803,7 +1803,7 @@ AsyncReadBuffers(ReadBuffersOperation *operation, int *nblocks_progress)
18031803
if (flags & READ_BUFFERS_SYNCHRONOUSLY)
18041804
ioh_flags |= PGAIO_HF_SYNCHRONOUS;
18051805

1806-
if (persistence == RELPERSISTENCE_TEMP)
1806+
if (persistence == RELPERSISTENCE_TEMP || am_wal_redo_postgres)
18071807
{
18081808
io_context = IOCONTEXT_NORMAL;
18091809
io_object = IOOBJECT_TEMP_RELATION;
@@ -1904,7 +1904,7 @@ AsyncReadBuffers(ReadBuffersOperation *operation, int *nblocks_progress)
19041904
operation->smgr->smgr_rlocator.backend,
19051905
true);
19061906

1907-
if (persistence == RELPERSISTENCE_TEMP)
1907+
if (persistence == RELPERSISTENCE_TEMP || am_wal_redo_postgres)
19081908
pgBufferUsage.local_blks_hit += 1;
19091909
else
19101910
pgBufferUsage.shared_blks_hit += 1;
@@ -1951,7 +1951,7 @@ AsyncReadBuffers(ReadBuffersOperation *operation, int *nblocks_progress)
19511951
pgaio_io_set_handle_data_32(ioh, (uint32 *) io_buffers, io_buffers_len);
19521952

19531953
pgaio_io_register_callbacks(ioh,
1954-
persistence == RELPERSISTENCE_TEMP ?
1954+
(persistence == RELPERSISTENCE_TEMP || am_wal_redo_postgres) ?
19551955
PGAIO_HCB_LOCAL_BUFFER_READV :
19561956
PGAIO_HCB_SHARED_BUFFER_READV,
19571957
flags);
@@ -1974,7 +1974,7 @@ AsyncReadBuffers(ReadBuffersOperation *operation, int *nblocks_progress)
19741974
pgstat_count_io_op_time(io_object, io_context, IOOP_READ,
19751975
io_start, 1, io_buffers_len * BLCKSZ);
19761976

1977-
if (persistence == RELPERSISTENCE_TEMP)
1977+
if (persistence == RELPERSISTENCE_TEMP || am_wal_redo_postgres)
19781978
pgBufferUsage.local_blks_read += io_buffers_len;
19791979
else
19801980
pgBufferUsage.shared_blks_read += io_buffers_len;
@@ -2593,7 +2593,7 @@ ExtendBufferedRelCommon(BufferManagerRelation bmr,
25932593
bmr.smgr->smgr_rlocator.backend,
25942594
extend_by);
25952595

2596-
if (bmr.relpersistence == RELPERSISTENCE_TEMP)
2596+
if (bmr.relpersistence == RELPERSISTENCE_TEMP || am_wal_redo_postgres)
25972597
first_block = ExtendBufferedRelLocal(bmr, fork, flags,
25982598
extend_by, extend_upto,
25992599
buffers, &extend_by);
@@ -4587,7 +4587,7 @@ DropRelationBuffers(SMgrRelation smgr_reln, ForkNumber *forkNum,
45874587
rlocator = smgr_reln->smgr_rlocator;
45884588

45894589
/* If it's a local relation, it's localbuf.c's problem. */
4590-
if (RelFileLocatorBackendIsTemp(rlocator))
4590+
if (RelFileLocatorBackendIsTemp(rlocator) || am_wal_redo_postgres)
45914591
{
45924592
if (rlocator.backend == MyProcNumber)
45934593
{
@@ -4717,7 +4717,7 @@ DropRelationsAllBuffers(SMgrRelation *smgr_reln, int nlocators)
47174717
/* If it's a local relation, it's localbuf.c's problem. */
47184718
for (i = 0; i < nlocators; i++)
47194719
{
4720-
if (RelFileLocatorBackendIsTemp(smgr_reln[i]->smgr_rlocator))
4720+
if (RelFileLocatorBackendIsTemp(smgr_reln[i]->smgr_rlocator) || am_wal_redo_postgres)
47214721
{
47224722
if (smgr_reln[i]->smgr_rlocator.backend == MyProcNumber)
47234723
DropRelationAllLocalBuffers(smgr_reln[i]->smgr_rlocator.locator);
@@ -4984,7 +4984,7 @@ FlushRelationBuffers(Relation rel)
49844984
BufferDesc *bufHdr;
49854985
SMgrRelation srel = RelationGetSmgr(rel);
49864986

4987-
if (RelationUsesLocalBuffers(rel))
4987+
if (RelationUsesLocalBuffers(rel) || am_wal_redo_postgres)
49884988
{
49894989
for (i = 0; i < NLocBuffer; i++)
49904990
{

0 commit comments

Comments
 (0)