PostgreSQL Source Code  git master
smgr.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * smgr.c
4  * public interface routines to storage manager switch.
5  *
6  * All file system operations in POSTGRES dispatch through these
7  * routines.
8  *
9  * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
10  * Portions Copyright (c) 1994, Regents of the University of California
11  *
12  *
13  * IDENTIFICATION
14  * src/backend/storage/smgr/smgr.c
15  *
16  *-------------------------------------------------------------------------
17  */
18 #include "postgres.h"
19 
20 #include "access/xlog.h"
21 #include "lib/ilist.h"
22 #include "storage/bufmgr.h"
23 #include "storage/ipc.h"
24 #include "storage/md.h"
25 #include "storage/smgr.h"
26 #include "utils/hsearch.h"
27 #include "utils/inval.h"
28 
29 
30 /*
31  * This struct of function pointers defines the API between smgr.c and
32  * any individual storage manager module. Note that smgr subfunctions are
33  * generally expected to report problems via elog(ERROR). An exception is
34  * that smgr_unlink should use elog(WARNING), rather than erroring out,
35  * because we normally unlink relations during post-commit/abort cleanup,
36  * and so it's too late to raise an error. Also, various conditions that
37  * would normally be errors should be allowed during bootstrap and/or WAL
38  * recovery --- see comments in md.c for details.
39  */
40 typedef struct f_smgr
41 {
42  void (*smgr_init) (void); /* may be NULL */
43  void (*smgr_shutdown) (void); /* may be NULL */
44  void (*smgr_open) (SMgrRelation reln);
45  void (*smgr_close) (SMgrRelation reln, ForkNumber forknum);
46  void (*smgr_create) (SMgrRelation reln, ForkNumber forknum,
47  bool isRedo);
49  void (*smgr_unlink) (RelFileNodeBackend rnode, ForkNumber forknum,
50  bool isRedo);
51  void (*smgr_extend) (SMgrRelation reln, ForkNumber forknum,
52  BlockNumber blocknum, char *buffer, bool skipFsync);
54  BlockNumber blocknum);
55  void (*smgr_read) (SMgrRelation reln, ForkNumber forknum,
56  BlockNumber blocknum, char *buffer);
57  void (*smgr_write) (SMgrRelation reln, ForkNumber forknum,
58  BlockNumber blocknum, char *buffer, bool skipFsync);
59  void (*smgr_writeback) (SMgrRelation reln, ForkNumber forknum,
60  BlockNumber blocknum, BlockNumber nblocks);
62  void (*smgr_truncate) (SMgrRelation reln, ForkNumber forknum,
63  BlockNumber nblocks);
64  void (*smgr_immedsync) (SMgrRelation reln, ForkNumber forknum);
65 } f_smgr;
66 
67 static const f_smgr smgrsw[] = {
68  /* magnetic disk */
69  {
70  .smgr_init = mdinit,
71  .smgr_shutdown = NULL,
72  .smgr_open = mdopen,
73  .smgr_close = mdclose,
74  .smgr_create = mdcreate,
75  .smgr_exists = mdexists,
76  .smgr_unlink = mdunlink,
77  .smgr_extend = mdextend,
78  .smgr_prefetch = mdprefetch,
79  .smgr_read = mdread,
80  .smgr_write = mdwrite,
81  .smgr_writeback = mdwriteback,
82  .smgr_nblocks = mdnblocks,
83  .smgr_truncate = mdtruncate,
84  .smgr_immedsync = mdimmedsync,
85  }
86 };
87 
88 static const int NSmgr = lengthof(smgrsw);
89 
90 /*
91  * Each backend has a hashtable that stores all extant SMgrRelation objects.
92  * In addition, "unowned" SMgrRelation objects are chained together in a list.
93  */
94 static HTAB *SMgrRelationHash = NULL;
95 
97 
98 /* local function prototypes */
99 static void smgrshutdown(int code, Datum arg);
100 
101 
102 /*
103  * smgrinit(), smgrshutdown() -- Initialize or shut down storage
104  * managers.
105  *
106  * Note: smgrinit is called during backend startup (normal or standalone
107  * case), *not* during postmaster start. Therefore, any resources created
108  * here or destroyed in smgrshutdown are backend-local.
109  */
110 void
111 smgrinit(void)
112 {
113  int i;
114 
115  for (i = 0; i < NSmgr; i++)
116  {
117  if (smgrsw[i].smgr_init)
118  smgrsw[i].smgr_init();
119  }
120 
121  /* register the shutdown proc */
123 }
124 
125 /*
126  * on_proc_exit hook for smgr cleanup during backend shutdown
127  */
128 static void
130 {
131  int i;
132 
133  for (i = 0; i < NSmgr; i++)
134  {
135  if (smgrsw[i].smgr_shutdown)
136  smgrsw[i].smgr_shutdown();
137  }
138 }
139 
140 /*
141  * smgropen() -- Return an SMgrRelation object, creating it if need be.
142  *
143  * This does not attempt to actually open the underlying file.
144  */
147 {
148  RelFileNodeBackend brnode;
149  SMgrRelation reln;
150  bool found;
151 
152  if (SMgrRelationHash == NULL)
153  {
154  /* First time through: initialize the hash table */
155  HASHCTL ctl;
156 
157  MemSet(&ctl, 0, sizeof(ctl));
158  ctl.keysize = sizeof(RelFileNodeBackend);
159  ctl.entrysize = sizeof(SMgrRelationData);
160  SMgrRelationHash = hash_create("smgr relation table", 400,
161  &ctl, HASH_ELEM | HASH_BLOBS);
162  dlist_init(&unowned_relns);
163  }
164 
165  /* Look up or create an entry */
166  brnode.node = rnode;
167  brnode.backend = backend;
168  reln = (SMgrRelation) hash_search(SMgrRelationHash,
169  (void *) &brnode,
170  HASH_ENTER, &found);
171 
172  /* Initialize it if not present before */
173  if (!found)
174  {
175  /* hash_search already filled in the lookup key */
176  reln->smgr_owner = NULL;
178  for (int i = 0; i <= MAX_FORKNUM; ++i)
180  reln->smgr_which = 0; /* we only have md.c at present */
181 
182  /* implementation-specific initialization */
183  smgrsw[reln->smgr_which].smgr_open(reln);
184 
185  /* it has no owner yet */
186  dlist_push_tail(&unowned_relns, &reln->node);
187  }
188 
189  return reln;
190 }
191 
192 /*
193  * smgrsetowner() -- Establish a long-lived reference to an SMgrRelation object
194  *
195  * There can be only one owner at a time; this is sufficient since currently
196  * the only such owners exist in the relcache.
197  */
198 void
200 {
201  /* We don't support "disowning" an SMgrRelation here, use smgrclearowner */
202  Assert(owner != NULL);
203 
204  /*
205  * First, unhook any old owner. (Normally there shouldn't be any, but it
206  * seems possible that this can happen during swap_relation_files()
207  * depending on the order of processing. It's ok to close the old
208  * relcache entry early in that case.)
209  *
210  * If there isn't an old owner, then the reln should be in the unowned
211  * list, and we need to remove it.
212  */
213  if (reln->smgr_owner)
214  *(reln->smgr_owner) = NULL;
215  else
216  dlist_delete(&reln->node);
217 
218  /* Now establish the ownership relationship. */
219  reln->smgr_owner = owner;
220  *owner = reln;
221 }
222 
223 /*
224  * smgrclearowner() -- Remove long-lived reference to an SMgrRelation object
225  * if one exists
226  */
227 void
229 {
230  /* Do nothing if the SMgrRelation object is not owned by the owner */
231  if (reln->smgr_owner != owner)
232  return;
233 
234  /* unset the owner's reference */
235  *owner = NULL;
236 
237  /* unset our reference to the owner */
238  reln->smgr_owner = NULL;
239 
240  /* add to list of unowned relations */
241  dlist_push_tail(&unowned_relns, &reln->node);
242 }
243 
244 /*
245  * smgrexists() -- Does the underlying file for a fork exist?
246  */
247 bool
249 {
250  return smgrsw[reln->smgr_which].smgr_exists(reln, forknum);
251 }
252 
253 /*
254  * smgrclose() -- Close and delete an SMgrRelation object.
255  */
256 void
258 {
259  SMgrRelation *owner;
260  ForkNumber forknum;
261 
262  for (forknum = 0; forknum <= MAX_FORKNUM; forknum++)
263  smgrsw[reln->smgr_which].smgr_close(reln, forknum);
264 
265  owner = reln->smgr_owner;
266 
267  if (!owner)
268  dlist_delete(&reln->node);
269 
270  if (hash_search(SMgrRelationHash,
271  (void *) &(reln->smgr_rnode),
272  HASH_REMOVE, NULL) == NULL)
273  elog(ERROR, "SMgrRelation hashtable corrupted");
274 
275  /*
276  * Unhook the owner pointer, if any. We do this last since in the remote
277  * possibility of failure above, the SMgrRelation object will still exist.
278  */
279  if (owner)
280  *owner = NULL;
281 }
282 
283 /*
284  * smgrcloseall() -- Close all existing SMgrRelation objects.
285  */
286 void
288 {
290  SMgrRelation reln;
291 
292  /* Nothing to do if hashtable not set up */
293  if (SMgrRelationHash == NULL)
294  return;
295 
296  hash_seq_init(&status, SMgrRelationHash);
297 
298  while ((reln = (SMgrRelation) hash_seq_search(&status)) != NULL)
299  smgrclose(reln);
300 }
301 
302 /*
303  * smgrclosenode() -- Close SMgrRelation object for given RelFileNode,
304  * if one exists.
305  *
306  * This has the same effects as smgrclose(smgropen(rnode)), but it avoids
307  * uselessly creating a hashtable entry only to drop it again when no
308  * such entry exists already.
309  */
310 void
312 {
313  SMgrRelation reln;
314 
315  /* Nothing to do if hashtable not set up */
316  if (SMgrRelationHash == NULL)
317  return;
318 
319  reln = (SMgrRelation) hash_search(SMgrRelationHash,
320  (void *) &rnode,
321  HASH_FIND, NULL);
322  if (reln != NULL)
323  smgrclose(reln);
324 }
325 
326 /*
327  * smgrcreate() -- Create a new relation.
328  *
329  * Given an already-created (but presumably unused) SMgrRelation,
330  * cause the underlying disk file or other storage for the fork
331  * to be created.
332  */
333 void
334 smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo)
335 {
336  smgrsw[reln->smgr_which].smgr_create(reln, forknum, isRedo);
337 }
338 
339 /*
340  * smgrdosyncall() -- Immediately sync all forks of all given relations
341  *
342  * All forks of all given relations are synced out to the store.
343  *
344  * This is equivalent to FlushRelationBuffers() for each smgr relation,
345  * then calling smgrimmedsync() for all forks of each relation, but it's
346  * significantly quicker so should be preferred when possible.
347  */
348 void
349 smgrdosyncall(SMgrRelation *rels, int nrels)
350 {
351  int i = 0;
352  ForkNumber forknum;
353 
354  if (nrels == 0)
355  return;
356 
357  FlushRelationsAllBuffers(rels, nrels);
358 
359  /*
360  * Sync the physical file(s).
361  */
362  for (i = 0; i < nrels; i++)
363  {
364  int which = rels[i]->smgr_which;
365 
366  for (forknum = 0; forknum <= MAX_FORKNUM; forknum++)
367  {
368  if (smgrsw[which].smgr_exists(rels[i], forknum))
369  smgrsw[which].smgr_immedsync(rels[i], forknum);
370  }
371  }
372 }
373 
374 /*
375  * smgrdounlinkall() -- Immediately unlink all forks of all given relations
376  *
377  * All forks of all given relations are removed from the store. This
378  * should not be used during transactional operations, since it can't be
379  * undone.
380  *
381  * If isRedo is true, it is okay for the underlying file(s) to be gone
382  * already.
383  */
384 void
385 smgrdounlinkall(SMgrRelation *rels, int nrels, bool isRedo)
386 {
387  int i = 0;
388  RelFileNodeBackend *rnodes;
389  ForkNumber forknum;
390 
391  if (nrels == 0)
392  return;
393 
394  /*
395  * create an array which contains all relations to be dropped, and close
396  * each relation's forks at the smgr level while at it
397  */
398  rnodes = palloc(sizeof(RelFileNodeBackend) * nrels);
399  for (i = 0; i < nrels; i++)
400  {
401  RelFileNodeBackend rnode = rels[i]->smgr_rnode;
402  int which = rels[i]->smgr_which;
403 
404  rnodes[i] = rnode;
405 
406  /* Close the forks at smgr level */
407  for (forknum = 0; forknum <= MAX_FORKNUM; forknum++)
408  smgrsw[which].smgr_close(rels[i], forknum);
409  }
410 
411  /*
412  * Get rid of any remaining buffers for the relations. bufmgr will just
413  * drop them without bothering to write the contents.
414  */
415  DropRelFileNodesAllBuffers(rnodes, nrels);
416 
417  /*
418  * It'd be nice to tell the stats collector to forget them immediately,
419  * too. But we can't because we don't know the OIDs.
420  */
421 
422  /*
423  * Send a shared-inval message to force other backends to close any
424  * dangling smgr references they may have for these rels. We should do
425  * this before starting the actual unlinking, in case we fail partway
426  * through that step. Note that the sinval messages will eventually come
427  * back to this backend, too, and thereby provide a backstop that we
428  * closed our own smgr rel.
429  */
430  for (i = 0; i < nrels; i++)
431  CacheInvalidateSmgr(rnodes[i]);
432 
433  /*
434  * Delete the physical file(s).
435  *
436  * Note: smgr_unlink must treat deletion failure as a WARNING, not an
437  * ERROR, because we've already decided to commit or abort the current
438  * xact.
439  */
440 
441  for (i = 0; i < nrels; i++)
442  {
443  int which = rels[i]->smgr_which;
444 
445  for (forknum = 0; forknum <= MAX_FORKNUM; forknum++)
446  smgrsw[which].smgr_unlink(rnodes[i], forknum, isRedo);
447  }
448 
449  pfree(rnodes);
450 }
451 
452 
453 /*
454  * smgrextend() -- Add a new block to a file.
455  *
456  * The semantics are nearly the same as smgrwrite(): write at the
457  * specified position. However, this is to be used for the case of
458  * extending a relation (i.e., blocknum is at or beyond the current
459  * EOF). Note that we assume writing a block beyond current EOF
460  * causes intervening file space to become filled with zeroes.
461  */
462 void
464  char *buffer, bool skipFsync)
465 {
466  smgrsw[reln->smgr_which].smgr_extend(reln, forknum, blocknum,
467  buffer, skipFsync);
468 
469  /*
470  * Normally we expect this to increase nblocks by one, but if the cached
471  * value isn't as expected, just invalidate it so the next call asks the
472  * kernel.
473  */
474  if (reln->smgr_cached_nblocks[forknum] == blocknum)
475  reln->smgr_cached_nblocks[forknum] = blocknum + 1;
476  else
477  reln->smgr_cached_nblocks[forknum] = InvalidBlockNumber;
478 }
479 
480 /*
481  * smgrprefetch() -- Initiate asynchronous read of the specified block of a relation.
482  *
483  * In recovery only, this can return false to indicate that a file
484  * doesn't exist (presumably it has been dropped by a later WAL
485  * record).
486  */
487 bool
489 {
490  return smgrsw[reln->smgr_which].smgr_prefetch(reln, forknum, blocknum);
491 }
492 
493 /*
494  * smgrread() -- read a particular block from a relation into the supplied
495  * buffer.
496  *
497  * This routine is called from the buffer manager in order to
498  * instantiate pages in the shared buffer cache. All storage managers
499  * return pages in the format that POSTGRES expects.
500  */
501 void
502 smgrread(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
503  char *buffer)
504 {
505  smgrsw[reln->smgr_which].smgr_read(reln, forknum, blocknum, buffer);
506 }
507 
508 /*
509  * smgrwrite() -- Write the supplied buffer out.
510  *
511  * This is to be used only for updating already-existing blocks of a
512  * relation (ie, those before the current EOF). To extend a relation,
513  * use smgrextend().
514  *
515  * This is not a synchronous write -- the block is not necessarily
516  * on disk at return, only dumped out to the kernel. However,
517  * provisions will be made to fsync the write before the next checkpoint.
518  *
519  * skipFsync indicates that the caller will make other provisions to
520  * fsync the relation, so we needn't bother. Temporary relations also
521  * do not require fsync.
522  */
523 void
525  char *buffer, bool skipFsync)
526 {
527  smgrsw[reln->smgr_which].smgr_write(reln, forknum, blocknum,
528  buffer, skipFsync);
529 }
530 
531 
532 /*
533  * smgrwriteback() -- Trigger kernel writeback for the supplied range of
534  * blocks.
535  */
536 void
538  BlockNumber nblocks)
539 {
540  smgrsw[reln->smgr_which].smgr_writeback(reln, forknum, blocknum,
541  nblocks);
542 }
543 
544 /*
545  * smgrnblocks() -- Calculate the number of blocks in the
546  * supplied relation.
547  */
550 {
551  BlockNumber result;
552 
553  /*
554  * For now, we only use cached values in recovery due to lack of a shared
555  * invalidation mechanism for changes in file size.
556  */
557  if (InRecovery && reln->smgr_cached_nblocks[forknum] != InvalidBlockNumber)
558  return reln->smgr_cached_nblocks[forknum];
559 
560  result = smgrsw[reln->smgr_which].smgr_nblocks(reln, forknum);
561 
562  reln->smgr_cached_nblocks[forknum] = result;
563 
564  return result;
565 }
566 
567 /*
568  * smgrtruncate() -- Truncate the given forks of supplied relation to
569  * each specified numbers of blocks
570  *
571  * The truncation is done immediately, so this can't be rolled back.
572  *
573  * The caller must hold AccessExclusiveLock on the relation, to ensure that
574  * other backends receive the smgr invalidation event that this function sends
575  * before they access any forks of the relation again.
576  */
577 void
578 smgrtruncate(SMgrRelation reln, ForkNumber *forknum, int nforks, BlockNumber *nblocks)
579 {
580  int i;
581 
582  /*
583  * Get rid of any buffers for the about-to-be-deleted blocks. bufmgr will
584  * just drop them without bothering to write the contents.
585  */
586  DropRelFileNodeBuffers(reln->smgr_rnode, forknum, nforks, nblocks);
587 
588  /*
589  * Send a shared-inval message to force other backends to close any smgr
590  * references they may have for this rel. This is useful because they
591  * might have open file pointers to segments that got removed, and/or
592  * smgr_targblock variables pointing past the new rel end. (The inval
593  * message will come back to our backend, too, causing a
594  * probably-unnecessary local smgr flush. But we don't expect that this
595  * is a performance-critical path.) As in the unlink code, we want to be
596  * sure the message is sent before we start changing things on-disk.
597  */
599 
600  /* Do the truncation */
601  for (i = 0; i < nforks; i++)
602  {
603  /* Make the cached size is invalid if we encounter an error. */
604  reln->smgr_cached_nblocks[forknum[i]] = InvalidBlockNumber;
605 
606  smgrsw[reln->smgr_which].smgr_truncate(reln, forknum[i], nblocks[i]);
607 
608  /*
609  * We might as well update the local smgr_cached_nblocks values. The
610  * smgr cache inval message that this function sent will cause other
611  * backends to invalidate their copies of smgr_fsm_nblocks and
612  * smgr_vm_nblocks, and these ones too at the next command boundary.
613  * But these ensure they aren't outright wrong until then.
614  */
615  reln->smgr_cached_nblocks[forknum[i]] = nblocks[i];
616  }
617 }
618 
619 /*
620  * smgrimmedsync() -- Force the specified relation to stable storage.
621  *
622  * Synchronously force all previous writes to the specified relation
623  * down to disk.
624  *
625  * This is useful for building completely new relations (eg, new
626  * indexes). Instead of incrementally WAL-logging the index build
627  * steps, we can just write completed index pages to disk with smgrwrite
628  * or smgrextend, and then fsync the completed index file before
629  * committing the transaction. (This is sufficient for purposes of
630  * crash recovery, since it effectively duplicates forcing a checkpoint
631  * for the completed index. But it is *not* sufficient if one wishes
632  * to use the WAL log for PITR or replication purposes: in that case
633  * we have to make WAL entries as well.)
634  *
635  * The preceding writes should specify skipFsync = true to avoid
636  * duplicative fsyncs.
637  *
638  * Note that you need to do FlushRelationBuffers() first if there is
639  * any possibility that there are dirty buffers for the relation;
640  * otherwise the sync is not very meaningful.
641  */
642 void
644 {
645  smgrsw[reln->smgr_which].smgr_immedsync(reln, forknum);
646 }
647 
648 /*
649  * AtEOXact_SMgr
650  *
651  * This routine is called during transaction commit or abort (it doesn't
652  * particularly care which). All transient SMgrRelation objects are closed.
653  *
654  * We do this as a compromise between wanting transient SMgrRelations to
655  * live awhile (to amortize the costs of blind writes of multiple blocks)
656  * and needing them to not live forever (since we're probably holding open
657  * a kernel file descriptor for the underlying file, and we need to ensure
658  * that gets closed reasonably soon if the file gets deleted).
659  */
660 void
662 {
663  dlist_mutable_iter iter;
664 
665  /*
666  * Zap all unowned SMgrRelations. We rely on smgrclose() to remove each
667  * one from the list.
668  */
669  dlist_foreach_modify(iter, &unowned_relns)
670  {
672  iter.cur);
673 
674  Assert(rel->smgr_owner == NULL);
675 
676  smgrclose(rel);
677  }
678 }
void CacheInvalidateSmgr(RelFileNodeBackend rnode)
Definition: inval.c:1377
void(* smgr_truncate)(SMgrRelation reln, ForkNumber forknum, BlockNumber nblocks)
Definition: smgr.c:62
struct SMgrRelationData SMgrRelationData
void(* smgr_write)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, char *buffer, bool skipFsync)
Definition: smgr.c:57
void mdimmedsync(SMgrRelation reln, ForkNumber forknum)
Definition: md.c:892
void smgrclose(SMgrRelation reln)
Definition: smgr.c:257
dlist_node * cur
Definition: ilist.h:180
void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo)
Definition: smgr.c:334
void smgrclearowner(SMgrRelation *owner, SMgrRelation reln)
Definition: smgr.c:228
#define HASH_ELEM
Definition: hsearch.h:87
#define dlist_foreach_modify(iter, lhead)
Definition: ilist.h:524
SMgrRelationData * SMgrRelation
Definition: smgr.h:75
void on_proc_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:305
BlockNumber mdnblocks(SMgrRelation reln, ForkNumber forknum)
Definition: md.c:735
struct f_smgr f_smgr
static const f_smgr smgrsw[]
Definition: smgr.c:67
static void smgrshutdown(int code, Datum arg)
Definition: smgr.c:129
static void dlist_push_tail(dlist_head *head, dlist_node *node)
Definition: ilist.h:317
bool InRecovery
Definition: xlog.c:204
void(* smgr_close)(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:45
Size entrysize
Definition: hsearch.h:73
void(* smgr_immedsync)(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:64
static HTAB * SMgrRelationHash
Definition: smgr.c:94
void smgrdounlinkall(SMgrRelation *rels, int nrels, bool isRedo)
Definition: smgr.c:385
void(* smgr_create)(SMgrRelation reln, ForkNumber forknum, bool isRedo)
Definition: smgr.c:46
#define MemSet(start, val, len)
Definition: c.h:949
uint32 BlockNumber
Definition: block.h:31
bool smgrexists(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:248
#define lengthof(array)
Definition: c.h:675
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:927
void mdinit(void)
Definition: md.c:148
void FlushRelationsAllBuffers(SMgrRelation *smgrs, int nrels)
Definition: bufmgr.c:3351
BlockNumber smgr_cached_nblocks[MAX_FORKNUM+1]
Definition: smgr.h:54
void mdextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, char *buffer, bool skipFsync)
Definition: md.c:387
void(* smgr_open)(SMgrRelation reln)
Definition: smgr.c:44
void smgrcloseall(void)
Definition: smgr.c:287
void smgrread(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, char *buffer)
Definition: smgr.c:502
bool(* smgr_exists)(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:48
Definition: dynahash.c:220
#define dlist_container(type, membername, ptr)
Definition: ilist.h:477
void AtEOXact_SMgr(void)
Definition: smgr.c:661
void pfree(void *pointer)
Definition: mcxt.c:1056
#define ERROR
Definition: elog.h:43
void(* smgr_init)(void)
Definition: smgr.c:42
static const int NSmgr
Definition: smgr.c:88
bool(* smgr_prefetch)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum)
Definition: smgr.c:53
RelFileNodeBackend smgr_rnode
Definition: smgr.h:42
void mdunlink(RelFileNodeBackend rnode, ForkNumber forkNum, bool isRedo)
Definition: md.c:277
void smgrwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, char *buffer, bool skipFsync)
Definition: smgr.c:524
void mdwriteback(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, BlockNumber nblocks)
Definition: md.c:556
void smgrwriteback(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, BlockNumber nblocks)
Definition: smgr.c:537
static void dlist_delete(dlist_node *node)
Definition: ilist.h:358
void(* smgr_unlink)(RelFileNodeBackend rnode, ForkNumber forknum, bool isRedo)
Definition: smgr.c:49
void smgrclosenode(RelFileNodeBackend rnode)
Definition: smgr.c:311
SMgrRelation smgropen(RelFileNode rnode, BackendId backend)
Definition: smgr.c:146
ForkNumber
Definition: relpath.h:40
void(* smgr_read)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, char *buffer)
Definition: smgr.c:55
Definition: smgr.c:40
struct SMgrRelationData ** smgr_owner
Definition: smgr.h:45
void mdopen(SMgrRelation reln)
Definition: md.c:494
#define HASH_BLOBS
Definition: hsearch.h:88
void smgrinit(void)
Definition: smgr.c:111
void DropRelFileNodesAllBuffers(RelFileNodeBackend *rnodes, int nnodes)
Definition: bufmgr.c:3051
HTAB * hash_create(const char *tabname, long nelem, HASHCTL *info, int flags)
Definition: dynahash.c:328
uintptr_t Datum
Definition: postgres.h:367
BlockNumber(* smgr_nblocks)(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:61
int smgr_which
Definition: smgr.h:62
int BackendId
Definition: backendid.h:21
struct RelFileNodeBackend RelFileNodeBackend
Size keysize
Definition: hsearch.h:72
void smgrtruncate(SMgrRelation reln, ForkNumber *forknum, int nforks, BlockNumber *nblocks)
Definition: smgr.c:578
static void dlist_init(dlist_head *head)
Definition: ilist.h:278
void mdtruncate(SMgrRelation reln, ForkNumber forknum, BlockNumber nblocks)
Definition: md.c:790
bool mdexists(SMgrRelation reln, ForkNumber forkNum)
Definition: md.c:161
RelFileNode node
Definition: relfilenode.h:74
BlockNumber smgrnblocks(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:549
void mdwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, char *buffer, bool skipFsync)
Definition: md.c:670
#define Assert(condition)
Definition: c.h:745
void(* smgr_writeback)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, BlockNumber nblocks)
Definition: smgr.c:59
void smgrsetowner(SMgrRelation *owner, SMgrRelation reln)
Definition: smgr.c:199
BlockNumber smgr_targblock
Definition: smgr.h:53
BackendId backend
Definition: relfilenode.h:75
#define InvalidBlockNumber
Definition: block.h:33
#define MAX_FORKNUM
Definition: relpath.h:55
void * hash_seq_search(HASH_SEQ_STATUS *status)
Definition: dynahash.c:1410
bool smgrprefetch(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum)
Definition: smgr.c:488
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
Definition: dynahash.c:1400
void mdclose(SMgrRelation reln, ForkNumber forknum)
Definition: md.c:505
void DropRelFileNodeBuffers(RelFileNodeBackend rnode, ForkNumber *forkNum, int nforks, BlockNumber *firstDelBlock)
Definition: bufmgr.c:2982
void smgrextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, char *buffer, bool skipFsync)
Definition: smgr.c:463
bool mdprefetch(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum)
Definition: md.c:528
void * palloc(Size size)
Definition: mcxt.c:949
void(* smgr_extend)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, char *buffer, bool skipFsync)
Definition: smgr.c:51
#define elog(elevel,...)
Definition: elog.h:214
int i
void mdcreate(SMgrRelation reln, ForkNumber forkNum, bool isRedo)
Definition: md.c:178
void * arg
void(* smgr_shutdown)(void)
Definition: smgr.c:43
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:225
void smgrimmedsync(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:643
unsigned char bool
Definition: c.h:324
dlist_node node
Definition: smgr.h:72
static dlist_head unowned_relns
Definition: smgr.c:96
void smgrdosyncall(SMgrRelation *rels, int nrels)
Definition: smgr.c:349
void mdread(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, char *buffer)
Definition: md.c:605