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 253 of file syncscan.c.

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

Referenced by initscan(), and table_block_parallelscan_startblock_init().

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

◆ ss_report_location()

void ss_report_location ( Relation  rel,
BlockNumber  location 
)

Definition at line 288 of file syncscan.c.

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

Referenced by heapam_scan_sample_next_block(), heapgettup(), heapgettup_pagemode(), and table_block_parallelscan_nextpage().

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

◆ SyncScanShmemInit()

void SyncScanShmemInit ( void  )

Definition at line 135 of file syncscan.c.

References Assert, RelFileNode::dbNode, ss_scan_locations_t::head, i, InvalidBlockNumber, InvalidOid, 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::relfilenode, RelFileNode::relNode, ShmemInitStruct(), SizeOfScanLocations, RelFileNode::spcNode, SYNC_SCAN_NELEM, and ss_scan_locations_t::tail.

Referenced by CreateSharedMemoryAndSemaphores().

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 SYNC_SCAN_NELEM
Definition: syncscan.c:71
RelFileNode relfilenode
Definition: syncscan.c:93
ss_scan_location_t location
Definition: syncscan.c:101
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:396
ss_lru_item_t items[FLEXIBLE_ARRAY_MEMBER]
Definition: syncscan.c:108
BlockNumber location
Definition: syncscan.c:94
bool IsUnderPostmaster
Definition: globals.c:112
ss_lru_item_t * head
Definition: syncscan.c:106
ss_lru_item_t * tail
Definition: syncscan.c:107
#define InvalidOid
Definition: postgres_ext.h:36
#define Assert(condition)
Definition: c.h:804
#define InvalidBlockNumber
Definition: block.h:33
struct ss_lru_item_t * next
Definition: syncscan.c:100
int i
static ss_scan_locations_t * scan_locations
Definition: syncscan.c:115
struct ss_lru_item_t * prev
Definition: syncscan.c:99
#define SizeOfScanLocations(N)
Definition: syncscan.c:111

◆ SyncScanShmemSize()

Size SyncScanShmemSize ( void  )

Definition at line 126 of file syncscan.c.

References SizeOfScanLocations, and SYNC_SCAN_NELEM.

Referenced by CreateSharedMemoryAndSemaphores().

127 {
129 }
#define SYNC_SCAN_NELEM
Definition: syncscan.c:71
#define SizeOfScanLocations(N)
Definition: syncscan.c:111