PostgreSQL Source Code git master
Loading...
Searching...
No Matches
syncscan.h File Reference
#include "storage/block.h"
#include "utils/relcache.h"
Include dependency graph for syncscan.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void ss_report_location (Relation rel, BlockNumber location)
 
BlockNumber ss_get_location (Relation rel, BlockNumber relnblocks)
 

Function Documentation

◆ ss_get_location()

BlockNumber ss_get_location ( Relation  rel,
BlockNumber  relnblocks 
)
extern

Definition at line 252 of file syncscan.c.

253{
255
257 startloc = ss_search(rel->rd_locator, 0, false);
259
260 /*
261 * If the location is not a valid block number for this scan, start at 0.
262 *
263 * This can happen if for instance a VACUUM truncated the table since the
264 * location was saved.
265 */
266 if (startloc >= relnblocks)
267 startloc = 0;
268
269#ifdef TRACE_SYNCSCAN
270 if (trace_syncscan)
271 elog(LOG,
272 "SYNC_SCAN: start \"%s\" (size %u) at %u",
274#endif
275
276 return startloc;
277}
uint32 BlockNumber
Definition block.h:31
#define LOG
Definition elog.h:32
#define elog(elevel,...)
Definition elog.h:228
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition lwlock.c:1150
void LWLockRelease(LWLock *lock)
Definition lwlock.c:1767
@ LW_EXCLUSIVE
Definition lwlock.h:104
static int fb(int x)
#define RelationGetRelationName(relation)
Definition rel.h:550
RelFileLocator rd_locator
Definition rel.h:57
static BlockNumber ss_search(RelFileLocator relfilelocator, BlockNumber location, bool set)
Definition syncscan.c:189

References elog, fb(), LOG, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), RelationData::rd_locator, RelationGetRelationName, and ss_search().

Referenced by initscan(), and table_block_parallelscan_startblock_init().

◆ ss_report_location()

void ss_report_location ( Relation  rel,
BlockNumber  location 
)
extern

Definition at line 287 of file syncscan.c.

288{
289#ifdef TRACE_SYNCSCAN
290 if (trace_syncscan)
291 {
292 if ((location % 1024) == 0)
293 elog(LOG,
294 "SYNC_SCAN: scanning \"%s\" at %u",
295 RelationGetRelationName(rel), location);
296 }
297#endif
298
299 /*
300 * To reduce lock contention, only report scan progress every N pages. For
301 * the same reason, don't block if the lock isn't immediately available.
302 * Missing a few updates isn't critical, it just means that a new scan
303 * that wants to join the pack will start a little bit behind the head of
304 * the scan. Hopefully the pages are still in OS cache and the scan
305 * catches up quickly.
306 */
307 if ((location % SYNC_SCAN_REPORT_INTERVAL) == 0)
308 {
310 {
311 (void) ss_search(rel->rd_locator, location, true);
313 }
314#ifdef TRACE_SYNCSCAN
315 else if (trace_syncscan)
316 elog(LOG,
317 "SYNC_SCAN: missed update for \"%s\" at %u",
318 RelationGetRelationName(rel), location);
319#endif
320 }
321}
bool LWLockConditionalAcquire(LWLock *lock, LWLockMode mode)
Definition lwlock.c:1321
#define SYNC_SCAN_REPORT_INTERVAL
Definition syncscan.c:84

References elog, fb(), LOG, LW_EXCLUSIVE, LWLockConditionalAcquire(), LWLockRelease(), RelationData::rd_locator, RelationGetRelationName, ss_search(), and SYNC_SCAN_REPORT_INTERVAL.

Referenced by heapam_scan_sample_next_block(), heapgettup_advance_block(), and table_block_parallelscan_nextpage().