Skip to content

Commit 81d4dd1

Browse files
lubennikovaavMatthias van de Meent
authored andcommitted
fix wal-redo buffer management
TODO: the logic around wal_redo + local buffers in other places too.
1 parent 78027f8 commit 81d4dd1

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)
@@ -1647,7 +1647,7 @@ WaitReadBuffers(ReadBuffersOperation *operation)
16471647
IOContext io_context;
16481648
IOObject io_object;
16491649

1650-
if (operation->persistence == RELPERSISTENCE_TEMP)
1650+
if (operation->persistence == RELPERSISTENCE_TEMP || am_wal_redo_postgres)
16511651
{
16521652
io_context = IOCONTEXT_NORMAL;
16531653
io_object = IOOBJECT_TEMP_RELATION;
@@ -1798,7 +1798,7 @@ AsyncReadBuffers(ReadBuffersOperation *operation, int *nblocks_progress)
17981798
if (flags & READ_BUFFERS_SYNCHRONOUSLY)
17991799
ioh_flags |= PGAIO_HF_SYNCHRONOUS;
18001800

1801-
if (persistence == RELPERSISTENCE_TEMP)
1801+
if (persistence == RELPERSISTENCE_TEMP || am_wal_redo_postgres)
18021802
{
18031803
io_context = IOCONTEXT_NORMAL;
18041804
io_object = IOOBJECT_TEMP_RELATION;
@@ -1899,7 +1899,7 @@ AsyncReadBuffers(ReadBuffersOperation *operation, int *nblocks_progress)
18991899
operation->smgr->smgr_rlocator.backend,
19001900
true);
19011901

1902-
if (persistence == RELPERSISTENCE_TEMP)
1902+
if (persistence == RELPERSISTENCE_TEMP || am_wal_redo_postgres)
19031903
pgBufferUsage.local_blks_hit += 1;
19041904
else
19051905
pgBufferUsage.shared_blks_hit += 1;
@@ -1946,7 +1946,7 @@ AsyncReadBuffers(ReadBuffersOperation *operation, int *nblocks_progress)
19461946
pgaio_io_set_handle_data_32(ioh, (uint32 *) io_buffers, io_buffers_len);
19471947

19481948
pgaio_io_register_callbacks(ioh,
1949-
persistence == RELPERSISTENCE_TEMP ?
1949+
(persistence == RELPERSISTENCE_TEMP || am_wal_redo_postgres) ?
19501950
PGAIO_HCB_LOCAL_BUFFER_READV :
19511951
PGAIO_HCB_SHARED_BUFFER_READV,
19521952
flags);
@@ -1969,7 +1969,7 @@ AsyncReadBuffers(ReadBuffersOperation *operation, int *nblocks_progress)
19691969
pgstat_count_io_op_time(io_object, io_context, IOOP_READ,
19701970
io_start, 1, io_buffers_len * BLCKSZ);
19711971

1972-
if (persistence == RELPERSISTENCE_TEMP)
1972+
if (persistence == RELPERSISTENCE_TEMP || am_wal_redo_postgres)
19731973
pgBufferUsage.local_blks_read += io_buffers_len;
19741974
else
19751975
pgBufferUsage.shared_blks_read += io_buffers_len;
@@ -2588,7 +2588,7 @@ ExtendBufferedRelCommon(BufferManagerRelation bmr,
25882588
bmr.smgr->smgr_rlocator.backend,
25892589
extend_by);
25902590

2591-
if (bmr.relpersistence == RELPERSISTENCE_TEMP)
2591+
if (bmr.relpersistence == RELPERSISTENCE_TEMP || am_wal_redo_postgres)
25922592
first_block = ExtendBufferedRelLocal(bmr, fork, flags,
25932593
extend_by, extend_upto,
25942594
buffers, &extend_by);
@@ -4582,7 +4582,7 @@ DropRelationBuffers(SMgrRelation smgr_reln, ForkNumber *forkNum,
45824582
rlocator = smgr_reln->smgr_rlocator;
45834583

45844584
/* If it's a local relation, it's localbuf.c's problem. */
4585-
if (RelFileLocatorBackendIsTemp(rlocator))
4585+
if (RelFileLocatorBackendIsTemp(rlocator) || am_wal_redo_postgres)
45864586
{
45874587
if (rlocator.backend == MyProcNumber)
45884588
{
@@ -4712,7 +4712,7 @@ DropRelationsAllBuffers(SMgrRelation *smgr_reln, int nlocators)
47124712
/* If it's a local relation, it's localbuf.c's problem. */
47134713
for (i = 0; i < nlocators; i++)
47144714
{
4715-
if (RelFileLocatorBackendIsTemp(smgr_reln[i]->smgr_rlocator))
4715+
if (RelFileLocatorBackendIsTemp(smgr_reln[i]->smgr_rlocator) || am_wal_redo_postgres)
47164716
{
47174717
if (smgr_reln[i]->smgr_rlocator.backend == MyProcNumber)
47184718
DropRelationAllLocalBuffers(smgr_reln[i]->smgr_rlocator.locator);
@@ -4979,7 +4979,7 @@ FlushRelationBuffers(Relation rel)
49794979
BufferDesc *bufHdr;
49804980
SMgrRelation srel = RelationGetSmgr(rel);
49814981

4982-
if (RelationUsesLocalBuffers(rel))
4982+
if (RelationUsesLocalBuffers(rel) || am_wal_redo_postgres)
49834983
{
49844984
for (i = 0; i < NLocBuffer; i++)
49854985
{

0 commit comments

Comments
 (0)