Skip to content

Commit 9c32e4c

Browse files
author
Amit Kapila
committed
Clear the local map when not used.
After commit b0eaa4c, we use a local map of pages to find the required space for small relations. We do clear this map when we have found a block with enough free space, when we extend the relation, or on transaction abort so that it can be used next time. However, we miss to clear it when we didn't find any pages to try from the map which leads to an assertion failure when we later tried to use it after relation extension. In the passing, I have improved some comments in this area. Reported-by: Tom Lane based on buildfarm results Author: Amit Kapila Reviewed-by: John Naylor Tested-by: Kuntal Ghosh Discussion: https://postgr.es/m/32368.1551114120@sss.pgh.pa.us
1 parent 0f3cdf8 commit 9c32e4c

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/backend/access/heap/hio.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -675,10 +675,7 @@ RelationGetBufferForTuple(Relation relation, Size len,
675675
*/
676676
RelationSetTargetBlock(relation, BufferGetBlockNumber(buffer));
677677

678-
/*
679-
* In case we used an in-memory map of available blocks, reset it for next
680-
* use.
681-
*/
678+
/* This should already be cleared by now, but make sure it is. */
682679
FSMClearLocalMap();
683680

684681
return buffer;

src/backend/storage/freespace/freespace.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,16 @@ typedef struct
9797
/* Address of the root page. */
9898
static const FSMAddress FSM_ROOT_ADDRESS = {FSM_ROOT_LEVEL, 0};
9999

100-
/* Local map of block numbers for small heaps with no FSM. */
100+
/*
101+
* For small relations, we don't create FSM to save space, instead we use
102+
* local in-memory map of pages to try. To locate free space, we simply try
103+
* pages directly without knowing ahead of time how much free space they have.
104+
*
105+
* Note that this map is used to the find the block with required free space
106+
* for any given relation. We clear this map when we have found a block with
107+
* enough free space, when we extend the relation, or on transaction abort.
108+
* See src/backend/storage/freespace/README for further details.
109+
*/
101110
typedef struct
102111
{
103112
BlockNumber nblocks;
@@ -1175,5 +1184,13 @@ fsm_local_search(void)
11751184
return target_block;
11761185
} while (target_block > 0);
11771186

1187+
/*
1188+
* If we didn't find any available block to try in the local map, then
1189+
* clear it. This prevents us from using the map again without setting it
1190+
* first, which would otherwise lead to the same conclusion again and
1191+
* again.
1192+
*/
1193+
FSMClearLocalMap();
1194+
11781195
return InvalidBlockNumber;
11791196
}

0 commit comments

Comments
 (0)