PostgreSQL Source Code  git master
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)
 
void SyncScanShmemInit (void)
 
Size SyncScanShmemSize (void)
 

Function Documentation

◆ ss_get_location()

BlockNumber ss_get_location ( Relation  rel,
BlockNumber  relnblocks 
)

Definition at line 254 of file syncscan.c.

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

References elog, 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 
)

Definition at line 289 of file syncscan.c.

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

References elog, 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().

◆ SyncScanShmemInit()

void SyncScanShmemInit ( void  )

Definition at line 135 of file syncscan.c.

136 {
137  int i;
138  bool found;
139 
141  ShmemInitStruct("Sync Scan Locations List",
143  &found);
144 
145  if (!IsUnderPostmaster)
146  {
147  /* Initialize shared memory area */
148  Assert(!found);
149 
152 
153  for (i = 0; i < SYNC_SCAN_NELEM; i++)
154  {
155  ss_lru_item_t *item = &scan_locations->items[i];
156 
157  /*
158  * Initialize all slots with invalid values. As scans are started,
159  * these invalid entries will fall off the LRU list and get
160  * replaced with real entries.
161  */
166 
167  item->prev = (i > 0) ?
168  (&scan_locations->items[i - 1]) : NULL;
169  item->next = (i < SYNC_SCAN_NELEM - 1) ?
170  (&scan_locations->items[i + 1]) : NULL;
171  }
172  }
173  else
174  Assert(found);
175 }
#define InvalidBlockNumber
Definition: block.h:33
#define Assert(condition)
Definition: c.h:861
bool IsUnderPostmaster
Definition: globals.c:119
int i
Definition: isn.c:73
#define InvalidOid
Definition: postgres_ext.h:36
#define InvalidRelFileNumber
Definition: relpath.h:26
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:387
RelFileNumber relNumber
ss_scan_location_t location
Definition: syncscan.c:101
struct ss_lru_item_t * next
Definition: syncscan.c:100
struct ss_lru_item_t * prev
Definition: syncscan.c:99
RelFileLocator relfilelocator
Definition: syncscan.c:93
BlockNumber location
Definition: syncscan.c:94
ss_lru_item_t * head
Definition: syncscan.c:106
ss_lru_item_t items[FLEXIBLE_ARRAY_MEMBER]
Definition: syncscan.c:108
ss_lru_item_t * tail
Definition: syncscan.c:107
static ss_scan_locations_t * scan_locations
Definition: syncscan.c:115
#define SYNC_SCAN_NELEM
Definition: syncscan.c:71
#define SizeOfScanLocations(N)
Definition: syncscan.c:111

References Assert, RelFileLocator::dbOid, ss_scan_locations_t::head, i, InvalidBlockNumber, InvalidOid, InvalidRelFileNumber, IsUnderPostmaster, ss_scan_locations_t::items, ss_scan_location_t::location, ss_lru_item_t::location, ss_lru_item_t::next, ss_lru_item_t::prev, ss_scan_location_t::relfilelocator, RelFileLocator::relNumber, scan_locations, ShmemInitStruct(), SizeOfScanLocations, RelFileLocator::spcOid, SYNC_SCAN_NELEM, and ss_scan_locations_t::tail.

Referenced by CreateOrAttachShmemStructs().

◆ SyncScanShmemSize()

Size SyncScanShmemSize ( void  )

Definition at line 126 of file syncscan.c.

127 {
129 }

References SizeOfScanLocations, and SYNC_SCAN_NELEM.

Referenced by CalculateShmemSize().