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