PostgreSQL Source Code  git master
smgr.h File Reference
#include "lib/ilist.h"
#include "storage/block.h"
#include "storage/relfilelocator.h"
Include dependency graph for smgr.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SMgrRelationData
 

Macros

#define SmgrIsTemp(smgr)    RelFileLocatorBackendIsTemp((smgr)->smgr_rlocator)
 

Typedefs

typedef struct SMgrRelationData SMgrRelationData
 
typedef SMgrRelationDataSMgrRelation
 

Functions

void smgrinit (void)
 
SMgrRelation smgropen (RelFileLocator rlocator, BackendId backend)
 
bool smgrexists (SMgrRelation reln, ForkNumber forknum)
 
void smgrsetowner (SMgrRelation *owner, SMgrRelation reln)
 
void smgrclearowner (SMgrRelation *owner, SMgrRelation reln)
 
void smgrclose (SMgrRelation reln)
 
void smgrcloseall (void)
 
void smgrcloserellocator (RelFileLocatorBackend rlocator)
 
void smgrrelease (SMgrRelation reln)
 
void smgrreleaseall (void)
 
void smgrcreate (SMgrRelation reln, ForkNumber forknum, bool isRedo)
 
void smgrdosyncall (SMgrRelation *rels, int nrels)
 
void smgrdounlinkall (SMgrRelation *rels, int nrels, bool isRedo)
 
void smgrextend (SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const void *buffer, bool skipFsync)
 
void smgrzeroextend (SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, int nblocks, bool skipFsync)
 
bool smgrprefetch (SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum)
 
void smgrread (SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, void *buffer)
 
void smgrwrite (SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const void *buffer, bool skipFsync)
 
void smgrwriteback (SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, BlockNumber nblocks)
 
BlockNumber smgrnblocks (SMgrRelation reln, ForkNumber forknum)
 
BlockNumber smgrnblocks_cached (SMgrRelation reln, ForkNumber forknum)
 
void smgrtruncate (SMgrRelation reln, ForkNumber *forknum, int nforks, BlockNumber *nblocks)
 
void smgrimmedsync (SMgrRelation reln, ForkNumber forknum)
 
void AtEOXact_SMgr (void)
 
bool ProcessBarrierSmgrRelease (void)
 

Macro Definition Documentation

◆ SmgrIsTemp

#define SmgrIsTemp (   smgr)     RelFileLocatorBackendIsTemp((smgr)->smgr_rlocator)

Definition at line 77 of file smgr.h.

Typedef Documentation

◆ SMgrRelation

Definition at line 75 of file smgr.h.

◆ SMgrRelationData

Function Documentation

◆ AtEOXact_SMgr()

void AtEOXact_SMgr ( void  )

Definition at line 738 of file smgr.c.

739 {
740  dlist_mutable_iter iter;
741 
742  /*
743  * Zap all unowned SMgrRelations. We rely on smgrclose() to remove each
744  * one from the list.
745  */
747  {
749  iter.cur);
750 
751  Assert(rel->smgr_owner == NULL);
752 
753  smgrclose(rel);
754  }
755 }
#define dlist_foreach_modify(iter, lhead)
Definition: ilist.h:640
#define dlist_container(type, membername, ptr)
Definition: ilist.h:593
Assert(fmt[strlen(fmt) - 1] !='\n')
void smgrclose(SMgrRelation reln)
Definition: smgr.c:260
static dlist_head unowned_relns
Definition: smgr.c:100
struct SMgrRelationData ** smgr_owner
Definition: smgr.h:45
dlist_node * cur
Definition: ilist.h:200

References Assert(), dlist_mutable_iter::cur, dlist_container, dlist_foreach_modify, SMgrRelationData::smgr_owner, smgrclose(), and unowned_relns.

Referenced by AbortTransaction(), AutoVacLauncherMain(), BackgroundWriterMain(), CheckpointerMain(), CommitTransaction(), PrepareTransaction(), and WalWriterMain().

◆ ProcessBarrierSmgrRelease()

bool ProcessBarrierSmgrRelease ( void  )

Definition at line 762 of file smgr.c.

763 {
764  smgrreleaseall();
765  return true;
766 }
void smgrreleaseall(void)
Definition: smgr.c:307

References smgrreleaseall().

Referenced by ProcessProcSignalBarrier().

◆ smgrclearowner()

void smgrclearowner ( SMgrRelation owner,
SMgrRelation  reln 
)

Definition at line 231 of file smgr.c.

232 {
233  /* Do nothing if the SMgrRelation object is not owned by the owner */
234  if (reln->smgr_owner != owner)
235  return;
236 
237  /* unset the owner's reference */
238  *owner = NULL;
239 
240  /* unset our reference to the owner */
241  reln->smgr_owner = NULL;
242 
243  /* add to list of unowned relations */
245 }
static void dlist_push_tail(dlist_head *head, dlist_node *node)
Definition: ilist.h:364
dlist_node node
Definition: smgr.h:72

References dlist_push_tail(), SMgrRelationData::node, SMgrRelationData::smgr_owner, and unowned_relns.

Referenced by FreeFakeRelcacheEntry().

◆ smgrclose()

void smgrclose ( SMgrRelation  reln)

Definition at line 260 of file smgr.c.

261 {
262  SMgrRelation *owner;
263  ForkNumber forknum;
264 
265  for (forknum = 0; forknum <= MAX_FORKNUM; forknum++)
266  smgrsw[reln->smgr_which].smgr_close(reln, forknum);
267 
268  owner = reln->smgr_owner;
269 
270  if (!owner)
271  dlist_delete(&reln->node);
272 
274  &(reln->smgr_rlocator),
275  HASH_REMOVE, NULL) == NULL)
276  elog(ERROR, "SMgrRelation hashtable corrupted");
277 
278  /*
279  * Unhook the owner pointer, if any. We do this last since in the remote
280  * possibility of failure above, the SMgrRelation object will still exist.
281  */
282  if (owner)
283  *owner = NULL;
284 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:953
#define ERROR
Definition: elog.h:39
@ HASH_REMOVE
Definition: hsearch.h:115
static void dlist_delete(dlist_node *node)
Definition: ilist.h:405
ForkNumber
Definition: relpath.h:48
#define MAX_FORKNUM
Definition: relpath.h:62
static HTAB * SMgrRelationHash
Definition: smgr.c:98
static const f_smgr smgrsw[]
Definition: smgr.c:70
RelFileLocatorBackend smgr_rlocator
Definition: smgr.h:42
int smgr_which
Definition: smgr.h:62
void(* smgr_close)(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:46

References dlist_delete(), elog(), ERROR, HASH_REMOVE, hash_search(), MAX_FORKNUM, SMgrRelationData::node, f_smgr::smgr_close, SMgrRelationData::smgr_owner, SMgrRelationData::smgr_rlocator, SMgrRelationData::smgr_which, SMgrRelationHash, and smgrsw.

Referenced by AtEOXact_SMgr(), DropRelationFiles(), fill_seq_with_data(), heapam_relation_copy_data(), heapam_relation_set_new_filelocator(), index_copy_data(), RelationCloseSmgr(), RelationSetNewRelfilenumber(), ScanSourceDatabasePgClass(), smgrcloseall(), smgrcloserellocator(), and smgrDoPendingDeletes().

◆ smgrcloseall()

void smgrcloseall ( void  )

Definition at line 326 of file smgr.c.

327 {
328  HASH_SEQ_STATUS status;
329  SMgrRelation reln;
330 
331  /* Nothing to do if hashtable not set up */
332  if (SMgrRelationHash == NULL)
333  return;
334 
336 
337  while ((reln = (SMgrRelation) hash_seq_search(&status)) != NULL)
338  smgrclose(reln);
339 }
void * hash_seq_search(HASH_SEQ_STATUS *status)
Definition: dynahash.c:1431
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
Definition: dynahash.c:1421

References hash_seq_init(), hash_seq_search(), smgrclose(), and SMgrRelationHash.

Referenced by BackgroundWriterMain(), CheckpointerMain(), RelationCacheInvalidate(), RequestCheckpoint(), WalWriterMain(), and XLogDropDatabase().

◆ smgrcloserellocator()

void smgrcloserellocator ( RelFileLocatorBackend  rlocator)

Definition at line 350 of file smgr.c.

351 {
352  SMgrRelation reln;
353 
354  /* Nothing to do if hashtable not set up */
355  if (SMgrRelationHash == NULL)
356  return;
357 
359  &rlocator,
360  HASH_FIND, NULL);
361  if (reln != NULL)
362  smgrclose(reln);
363 }
@ HASH_FIND
Definition: hsearch.h:113
SMgrRelationData * SMgrRelation
Definition: smgr.h:75

References HASH_FIND, hash_search(), smgrclose(), and SMgrRelationHash.

Referenced by CreateAndCopyRelationData(), and LocalExecuteInvalidationMessage().

◆ smgrcreate()

void smgrcreate ( SMgrRelation  reln,
ForkNumber  forknum,
bool  isRedo 
)

Definition at line 373 of file smgr.c.

374 {
375  smgrsw[reln->smgr_which].smgr_create(reln, forknum, isRedo);
376 }
void(* smgr_create)(SMgrRelation reln, ForkNumber forknum, bool isRedo)
Definition: smgr.c:47

References f_smgr::smgr_create, SMgrRelationData::smgr_which, and smgrsw.

Referenced by CreateAndCopyRelationData(), ExtendBufferedRelTo(), fill_seq_with_data(), heapam_relation_copy_data(), heapam_relation_set_new_filelocator(), index_build(), index_copy_data(), RelationCreateStorage(), smgr_redo(), and XLogReadBufferExtended().

◆ smgrdosyncall()

void smgrdosyncall ( SMgrRelation rels,
int  nrels 
)

Definition at line 388 of file smgr.c.

389 {
390  int i = 0;
391  ForkNumber forknum;
392 
393  if (nrels == 0)
394  return;
395 
396  FlushRelationsAllBuffers(rels, nrels);
397 
398  /*
399  * Sync the physical file(s).
400  */
401  for (i = 0; i < nrels; i++)
402  {
403  int which = rels[i]->smgr_which;
404 
405  for (forknum = 0; forknum <= MAX_FORKNUM; forknum++)
406  {
407  if (smgrsw[which].smgr_exists(rels[i], forknum))
408  smgrsw[which].smgr_immedsync(rels[i], forknum);
409  }
410  }
411 }
void FlushRelationsAllBuffers(SMgrRelation *smgrs, int nrels)
Definition: bufmgr.c:4156
int i
Definition: isn.c:73
void(* smgr_immedsync)(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:67

References FlushRelationsAllBuffers(), i, MAX_FORKNUM, f_smgr::smgr_immedsync, SMgrRelationData::smgr_which, and smgrsw.

Referenced by smgrDoPendingSyncs().

◆ smgrdounlinkall()

void smgrdounlinkall ( SMgrRelation rels,
int  nrels,
bool  isRedo 
)

Definition at line 424 of file smgr.c.

425 {
426  int i = 0;
427  RelFileLocatorBackend *rlocators;
428  ForkNumber forknum;
429 
430  if (nrels == 0)
431  return;
432 
433  /*
434  * Get rid of any remaining buffers for the relations. bufmgr will just
435  * drop them without bothering to write the contents.
436  */
437  DropRelationsAllBuffers(rels, nrels);
438 
439  /*
440  * create an array which contains all relations to be dropped, and close
441  * each relation's forks at the smgr level while at it
442  */
443  rlocators = palloc(sizeof(RelFileLocatorBackend) * nrels);
444  for (i = 0; i < nrels; i++)
445  {
446  RelFileLocatorBackend rlocator = rels[i]->smgr_rlocator;
447  int which = rels[i]->smgr_which;
448 
449  rlocators[i] = rlocator;
450 
451  /* Close the forks at smgr level */
452  for (forknum = 0; forknum <= MAX_FORKNUM; forknum++)
453  smgrsw[which].smgr_close(rels[i], forknum);
454  }
455 
456  /*
457  * Send a shared-inval message to force other backends to close any
458  * dangling smgr references they may have for these rels. We should do
459  * this before starting the actual unlinking, in case we fail partway
460  * through that step. Note that the sinval messages will eventually come
461  * back to this backend, too, and thereby provide a backstop that we
462  * closed our own smgr rel.
463  */
464  for (i = 0; i < nrels; i++)
465  CacheInvalidateSmgr(rlocators[i]);
466 
467  /*
468  * Delete the physical file(s).
469  *
470  * Note: smgr_unlink must treat deletion failure as a WARNING, not an
471  * ERROR, because we've already decided to commit or abort the current
472  * xact.
473  */
474 
475  for (i = 0; i < nrels; i++)
476  {
477  int which = rels[i]->smgr_which;
478 
479  for (forknum = 0; forknum <= MAX_FORKNUM; forknum++)
480  smgrsw[which].smgr_unlink(rlocators[i], forknum, isRedo);
481  }
482 
483  pfree(rlocators);
484 }
void DropRelationsAllBuffers(SMgrRelation *smgr_reln, int nlocators)
Definition: bufmgr.c:3720
void CacheInvalidateSmgr(RelFileLocatorBackend rlocator)
Definition: inval.c:1462
void pfree(void *pointer)
Definition: mcxt.c:1456
void * palloc(Size size)
Definition: mcxt.c:1226

References CacheInvalidateSmgr(), DropRelationsAllBuffers(), i, MAX_FORKNUM, palloc(), pfree(), SMgrRelationData::smgr_rlocator, SMgrRelationData::smgr_which, and smgrsw.

Referenced by DropRelationFiles(), RelationSetNewRelfilenumber(), and smgrDoPendingDeletes().

◆ smgrexists()

◆ smgrextend()

void smgrextend ( SMgrRelation  reln,
ForkNumber  forknum,
BlockNumber  blocknum,
const void *  buffer,
bool  skipFsync 
)

Definition at line 497 of file smgr.c.

499 {
500  smgrsw[reln->smgr_which].smgr_extend(reln, forknum, blocknum,
501  buffer, skipFsync);
502 
503  /*
504  * Normally we expect this to increase nblocks by one, but if the cached
505  * value isn't as expected, just invalidate it so the next call asks the
506  * kernel.
507  */
508  if (reln->smgr_cached_nblocks[forknum] == blocknum)
509  reln->smgr_cached_nblocks[forknum] = blocknum + 1;
510  else
511  reln->smgr_cached_nblocks[forknum] = InvalidBlockNumber;
512 }
#define InvalidBlockNumber
Definition: block.h:33
BlockNumber smgr_cached_nblocks[MAX_FORKNUM+1]
Definition: smgr.h:54
void(* smgr_extend)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const void *buffer, bool skipFsync)
Definition: smgr.c:52

References InvalidBlockNumber, SMgrRelationData::smgr_cached_nblocks, f_smgr::smgr_extend, SMgrRelationData::smgr_which, and smgrsw.

Referenced by _bt_blwritepage(), _hash_alloc_buckets(), end_heap_rewrite(), gist_indexsortbuild(), gist_indexsortbuild_flush_ready_pages(), raw_heap_insert(), RelationCopyStorage(), and RelationCopyStorageUsingBuffer().

◆ smgrimmedsync()

◆ smgrinit()

void smgrinit ( void  )

Definition at line 115 of file smgr.c.

116 {
117  int i;
118 
119  for (i = 0; i < NSmgr; i++)
120  {
121  if (smgrsw[i].smgr_init)
122  smgrsw[i].smgr_init();
123  }
124 
125  /* register the shutdown proc */
127 }
void on_proc_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:305
static const int NSmgr
Definition: smgr.c:92
static void smgrshutdown(int code, Datum arg)
Definition: smgr.c:133
void(* smgr_init)(void)
Definition: smgr.c:43

References i, NSmgr, on_proc_exit(), f_smgr::smgr_init, smgrshutdown(), and smgrsw.

Referenced by BaseInit().

◆ smgrnblocks()

BlockNumber smgrnblocks ( SMgrRelation  reln,
ForkNumber  forknum 
)

Definition at line 608 of file smgr.c.

609 {
610  BlockNumber result;
611 
612  /* Check and return if we get the cached value for the number of blocks. */
613  result = smgrnblocks_cached(reln, forknum);
614  if (result != InvalidBlockNumber)
615  return result;
616 
617  result = smgrsw[reln->smgr_which].smgr_nblocks(reln, forknum);
618 
619  reln->smgr_cached_nblocks[forknum] = result;
620 
621  return result;
622 }
uint32 BlockNumber
Definition: block.h:31
BlockNumber smgrnblocks_cached(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:632
BlockNumber(* smgr_nblocks)(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:64

References InvalidBlockNumber, SMgrRelationData::smgr_cached_nblocks, f_smgr::smgr_nblocks, SMgrRelationData::smgr_which, smgrnblocks_cached(), and smgrsw.

Referenced by ExtendBufferedRelLocal(), ExtendBufferedRelShared(), ExtendBufferedRelTo(), FreeSpaceMapPrepareTruncateRel(), fsm_readbuf(), gistBuildCallback(), RelationCopyStorage(), RelationCopyStorageUsingBuffer(), RelationGetNumberOfBlocksInFork(), ScanSourceDatabasePgClass(), smgrDoPendingSyncs(), table_block_relation_size(), visibilitymap_prepare_truncate(), vm_readbuf(), XLogPrefetcherNextBlock(), and XLogReadBufferExtended().

◆ smgrnblocks_cached()

BlockNumber smgrnblocks_cached ( SMgrRelation  reln,
ForkNumber  forknum 
)

Definition at line 632 of file smgr.c.

633 {
634  /*
635  * For now, we only use cached values in recovery due to lack of a shared
636  * invalidation mechanism for changes in file size.
637  */
638  if (InRecovery && reln->smgr_cached_nblocks[forknum] != InvalidBlockNumber)
639  return reln->smgr_cached_nblocks[forknum];
640 
641  return InvalidBlockNumber;
642 }
bool InRecovery
Definition: xlogutils.c:53

References InRecovery, InvalidBlockNumber, and SMgrRelationData::smgr_cached_nblocks.

Referenced by DropRelationBuffers(), DropRelationsAllBuffers(), and smgrnblocks().

◆ smgropen()

SMgrRelation smgropen ( RelFileLocator  rlocator,
BackendId  backend 
)

Definition at line 150 of file smgr.c.

151 {
152  RelFileLocatorBackend brlocator;
153  SMgrRelation reln;
154  bool found;
155 
156  if (SMgrRelationHash == NULL)
157  {
158  /* First time through: initialize the hash table */
159  HASHCTL ctl;
160 
161  ctl.keysize = sizeof(RelFileLocatorBackend);
162  ctl.entrysize = sizeof(SMgrRelationData);
163  SMgrRelationHash = hash_create("smgr relation table", 400,
164  &ctl, HASH_ELEM | HASH_BLOBS);
166  }
167 
168  /* Look up or create an entry */
169  brlocator.locator = rlocator;
170  brlocator.backend = backend;
172  &brlocator,
173  HASH_ENTER, &found);
174 
175  /* Initialize it if not present before */
176  if (!found)
177  {
178  /* hash_search already filled in the lookup key */
179  reln->smgr_owner = NULL;
181  for (int i = 0; i <= MAX_FORKNUM; ++i)
183  reln->smgr_which = 0; /* we only have md.c at present */
184 
185  /* implementation-specific initialization */
186  smgrsw[reln->smgr_which].smgr_open(reln);
187 
188  /* it has no owner yet */
190  }
191 
192  return reln;
193 }
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
Definition: dynahash.c:350
@ HASH_ENTER
Definition: hsearch.h:114
#define HASH_ELEM
Definition: hsearch.h:95
#define HASH_BLOBS
Definition: hsearch.h:97
static void dlist_init(dlist_head *head)
Definition: ilist.h:314
struct RelFileLocatorBackend RelFileLocatorBackend
struct SMgrRelationData SMgrRelationData
Size keysize
Definition: hsearch.h:75
Size entrysize
Definition: hsearch.h:76
RelFileLocator locator
BlockNumber smgr_targblock
Definition: smgr.h:53
void(* smgr_open)(SMgrRelation reln)
Definition: smgr.c:45

References RelFileLocatorBackend::backend, dlist_init(), dlist_push_tail(), HASHCTL::entrysize, HASH_BLOBS, hash_create(), HASH_ELEM, HASH_ENTER, hash_search(), i, InvalidBlockNumber, HASHCTL::keysize, RelFileLocatorBackend::locator, MAX_FORKNUM, SMgrRelationData::node, SMgrRelationData::smgr_cached_nblocks, f_smgr::smgr_open, SMgrRelationData::smgr_owner, SMgrRelationData::smgr_targblock, SMgrRelationData::smgr_which, SMgrRelationHash, smgrsw, and unowned_relns.

Referenced by CreateAndCopyRelationData(), DropRelationFiles(), fill_seq_with_data(), FlushBuffer(), GetLocalVictimBuffer(), heapam_relation_copy_data(), index_copy_data(), IssuePendingWritebacks(), mdsyncfiletag(), ReadBufferWithoutRelcache(), RelationCopyStorageUsingBuffer(), RelationCreateStorage(), RelationGetSmgr(), RelationSetNewRelfilenumber(), ScanSourceDatabasePgClass(), smgr_redo(), smgrDoPendingDeletes(), smgrDoPendingSyncs(), XLogPrefetcherNextBlock(), and XLogReadBufferExtended().

◆ smgrprefetch()

bool smgrprefetch ( SMgrRelation  reln,
ForkNumber  forknum,
BlockNumber  blocknum 
)

Definition at line 547 of file smgr.c.

548 {
549  return smgrsw[reln->smgr_which].smgr_prefetch(reln, forknum, blocknum);
550 }
bool(* smgr_prefetch)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum)
Definition: smgr.c:56

References f_smgr::smgr_prefetch, SMgrRelationData::smgr_which, and smgrsw.

Referenced by PrefetchLocalBuffer(), and PrefetchSharedBuffer().

◆ smgrread()

void smgrread ( SMgrRelation  reln,
ForkNumber  forknum,
BlockNumber  blocknum,
void *  buffer 
)

Definition at line 561 of file smgr.c.

563 {
564  smgrsw[reln->smgr_which].smgr_read(reln, forknum, blocknum, buffer);
565 }
void(* smgr_read)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, void *buffer)
Definition: smgr.c:58

References f_smgr::smgr_read, SMgrRelationData::smgr_which, and smgrsw.

Referenced by pg_prewarm(), ReadBuffer_common(), and RelationCopyStorage().

◆ smgrrelease()

void smgrrelease ( SMgrRelation  reln)

Definition at line 292 of file smgr.c.

293 {
294  for (ForkNumber forknum = 0; forknum <= MAX_FORKNUM; forknum++)
295  {
296  smgrsw[reln->smgr_which].smgr_close(reln, forknum);
297  reln->smgr_cached_nblocks[forknum] = InvalidBlockNumber;
298  }
299 }

References InvalidBlockNumber, MAX_FORKNUM, SMgrRelationData::smgr_cached_nblocks, f_smgr::smgr_close, SMgrRelationData::smgr_which, and smgrsw.

Referenced by smgrreleaseall().

◆ smgrreleaseall()

void smgrreleaseall ( void  )

Definition at line 307 of file smgr.c.

308 {
309  HASH_SEQ_STATUS status;
310  SMgrRelation reln;
311 
312  /* Nothing to do if hashtable not set up */
313  if (SMgrRelationHash == NULL)
314  return;
315 
317 
318  while ((reln = (SMgrRelation) hash_seq_search(&status)) != NULL)
319  smgrrelease(reln);
320 }
void smgrrelease(SMgrRelation reln)
Definition: smgr.c:292

References hash_seq_init(), hash_seq_search(), SMgrRelationHash, and smgrrelease().

Referenced by ProcessBarrierSmgrRelease().

◆ smgrsetowner()

void smgrsetowner ( SMgrRelation owner,
SMgrRelation  reln 
)

Definition at line 202 of file smgr.c.

203 {
204  /* We don't support "disowning" an SMgrRelation here, use smgrclearowner */
205  Assert(owner != NULL);
206 
207  /*
208  * First, unhook any old owner. (Normally there shouldn't be any, but it
209  * seems possible that this can happen during swap_relation_files()
210  * depending on the order of processing. It's ok to close the old
211  * relcache entry early in that case.)
212  *
213  * If there isn't an old owner, then the reln should be in the unowned
214  * list, and we need to remove it.
215  */
216  if (reln->smgr_owner)
217  *(reln->smgr_owner) = NULL;
218  else
219  dlist_delete(&reln->node);
220 
221  /* Now establish the ownership relationship. */
222  reln->smgr_owner = owner;
223  *owner = reln;
224 }

References Assert(), dlist_delete(), SMgrRelationData::node, and SMgrRelationData::smgr_owner.

Referenced by RelationGetSmgr().

◆ smgrtruncate()

void smgrtruncate ( SMgrRelation  reln,
ForkNumber forknum,
int  nforks,
BlockNumber nblocks 
)

Definition at line 655 of file smgr.c.

656 {
657  int i;
658 
659  /*
660  * Get rid of any buffers for the about-to-be-deleted blocks. bufmgr will
661  * just drop them without bothering to write the contents.
662  */
663  DropRelationBuffers(reln, forknum, nforks, nblocks);
664 
665  /*
666  * Send a shared-inval message to force other backends to close any smgr
667  * references they may have for this rel. This is useful because they
668  * might have open file pointers to segments that got removed, and/or
669  * smgr_targblock variables pointing past the new rel end. (The inval
670  * message will come back to our backend, too, causing a
671  * probably-unnecessary local smgr flush. But we don't expect that this
672  * is a performance-critical path.) As in the unlink code, we want to be
673  * sure the message is sent before we start changing things on-disk.
674  */
676 
677  /* Do the truncation */
678  for (i = 0; i < nforks; i++)
679  {
680  /* Make the cached size is invalid if we encounter an error. */
681  reln->smgr_cached_nblocks[forknum[i]] = InvalidBlockNumber;
682 
683  smgrsw[reln->smgr_which].smgr_truncate(reln, forknum[i], nblocks[i]);
684 
685  /*
686  * We might as well update the local smgr_cached_nblocks values. The
687  * smgr cache inval message that this function sent will cause other
688  * backends to invalidate their copies of smgr_fsm_nblocks and
689  * smgr_vm_nblocks, and these ones too at the next command boundary.
690  * But these ensure they aren't outright wrong until then.
691  */
692  reln->smgr_cached_nblocks[forknum[i]] = nblocks[i];
693  }
694 }
void DropRelationBuffers(SMgrRelation smgr_reln, ForkNumber *forkNum, int nforks, BlockNumber *firstDelBlock)
Definition: bufmgr.c:3597
void(* smgr_truncate)(SMgrRelation reln, ForkNumber forknum, BlockNumber nblocks)
Definition: smgr.c:65

References CacheInvalidateSmgr(), DropRelationBuffers(), i, InvalidBlockNumber, SMgrRelationData::smgr_cached_nblocks, SMgrRelationData::smgr_rlocator, f_smgr::smgr_truncate, SMgrRelationData::smgr_which, and smgrsw.

Referenced by pg_truncate_visibility_map(), RelationTruncate(), and smgr_redo().

◆ smgrwrite()

void smgrwrite ( SMgrRelation  reln,
ForkNumber  forknum,
BlockNumber  blocknum,
const void *  buffer,
bool  skipFsync 
)

Definition at line 583 of file smgr.c.

585 {
586  smgrsw[reln->smgr_which].smgr_write(reln, forknum, blocknum,
587  buffer, skipFsync);
588 }
void(* smgr_write)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const void *buffer, bool skipFsync)
Definition: smgr.c:60

References SMgrRelationData::smgr_which, f_smgr::smgr_write, and smgrsw.

Referenced by _bt_blwritepage(), blbuildempty(), btbuildempty(), FlushBuffer(), FlushRelationBuffers(), GetLocalVictimBuffer(), gist_indexsortbuild(), and spgbuildempty().

◆ smgrwriteback()

void smgrwriteback ( SMgrRelation  reln,
ForkNumber  forknum,
BlockNumber  blocknum,
BlockNumber  nblocks 
)

Definition at line 596 of file smgr.c.

598 {
599  smgrsw[reln->smgr_which].smgr_writeback(reln, forknum, blocknum,
600  nblocks);
601 }
void(* smgr_writeback)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, BlockNumber nblocks)
Definition: smgr.c:62

References SMgrRelationData::smgr_which, f_smgr::smgr_writeback, and smgrsw.

Referenced by IssuePendingWritebacks().

◆ smgrzeroextend()

void smgrzeroextend ( SMgrRelation  reln,
ForkNumber  forknum,
BlockNumber  blocknum,
int  nblocks,
bool  skipFsync 
)

Definition at line 522 of file smgr.c.

524 {
525  smgrsw[reln->smgr_which].smgr_zeroextend(reln, forknum, blocknum,
526  nblocks, skipFsync);
527 
528  /*
529  * Normally we expect this to increase the fork size by nblocks, but if
530  * the cached value isn't as expected, just invalidate it so the next call
531  * asks the kernel.
532  */
533  if (reln->smgr_cached_nblocks[forknum] == blocknum)
534  reln->smgr_cached_nblocks[forknum] = blocknum + nblocks;
535  else
536  reln->smgr_cached_nblocks[forknum] = InvalidBlockNumber;
537 }
void(* smgr_zeroextend)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, int nblocks, bool skipFsync)
Definition: smgr.c:54

References InvalidBlockNumber, SMgrRelationData::smgr_cached_nblocks, SMgrRelationData::smgr_which, f_smgr::smgr_zeroextend, and smgrsw.

Referenced by ExtendBufferedRelLocal(), and ExtendBufferedRelShared().