gooderp18绿色标准版
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

111 行
4.4KB

  1. /*-------------------------------------------------------------------------
  2. *
  3. * smgr.h
  4. * storage manager switch public interface declarations.
  5. *
  6. *
  7. * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
  8. * Portions Copyright (c) 1994, Regents of the University of California
  9. *
  10. * src/include/storage/smgr.h
  11. *
  12. *-------------------------------------------------------------------------
  13. */
  14. #ifndef SMGR_H
  15. #define SMGR_H
  16. #include "lib/ilist.h"
  17. #include "storage/block.h"
  18. #include "storage/relfilenode.h"
  19. /*
  20. * smgr.c maintains a table of SMgrRelation objects, which are essentially
  21. * cached file handles. An SMgrRelation is created (if not already present)
  22. * by smgropen(), and destroyed by smgrclose(). Note that neither of these
  23. * operations imply I/O, they just create or destroy a hashtable entry.
  24. * (But smgrclose() may release associated resources, such as OS-level file
  25. * descriptors.)
  26. *
  27. * An SMgrRelation may have an "owner", which is just a pointer to it from
  28. * somewhere else; smgr.c will clear this pointer if the SMgrRelation is
  29. * closed. We use this to avoid dangling pointers from relcache to smgr
  30. * without having to make the smgr explicitly aware of relcache. There
  31. * can't be more than one "owner" pointer per SMgrRelation, but that's
  32. * all we need.
  33. *
  34. * SMgrRelations that do not have an "owner" are considered to be transient,
  35. * and are deleted at end of transaction.
  36. */
  37. typedef struct SMgrRelationData
  38. {
  39. /* rnode is the hashtable lookup key, so it must be first! */
  40. RelFileNodeBackend smgr_rnode; /* relation physical identifier */
  41. /* pointer to owning pointer, or NULL if none */
  42. struct SMgrRelationData **smgr_owner;
  43. /*
  44. * These next three fields are not actually used or manipulated by smgr,
  45. * except that they are reset to InvalidBlockNumber upon a cache flush
  46. * event (in particular, upon truncation of the relation). Higher levels
  47. * store cached state here so that it will be reset when truncation
  48. * happens. In all three cases, InvalidBlockNumber means "unknown".
  49. */
  50. BlockNumber smgr_targblock; /* current insertion target block */
  51. BlockNumber smgr_fsm_nblocks; /* last known size of fsm fork */
  52. BlockNumber smgr_vm_nblocks; /* last known size of vm fork */
  53. /* additional public fields may someday exist here */
  54. /*
  55. * Fields below here are intended to be private to smgr.c and its
  56. * submodules. Do not touch them from elsewhere.
  57. */
  58. int smgr_which; /* storage manager selector */
  59. /*
  60. * for md.c; per-fork arrays of the number of open segments
  61. * (md_num_open_segs) and the segments themselves (md_seg_fds).
  62. */
  63. int md_num_open_segs[MAX_FORKNUM + 1];
  64. struct _MdfdVec *md_seg_fds[MAX_FORKNUM + 1];
  65. /* if unowned, list link in list of all unowned SMgrRelations */
  66. dlist_node node;
  67. } SMgrRelationData;
  68. typedef SMgrRelationData *SMgrRelation;
  69. #define SmgrIsTemp(smgr) \
  70. RelFileNodeBackendIsTemp((smgr)->smgr_rnode)
  71. extern void smgrinit(void);
  72. extern SMgrRelation smgropen(RelFileNode rnode, BackendId backend);
  73. extern bool smgrexists(SMgrRelation reln, ForkNumber forknum);
  74. extern void smgrsetowner(SMgrRelation *owner, SMgrRelation reln);
  75. extern void smgrclearowner(SMgrRelation *owner, SMgrRelation reln);
  76. extern void smgrclose(SMgrRelation reln);
  77. extern void smgrcloseall(void);
  78. extern void smgrclosenode(RelFileNodeBackend rnode);
  79. extern void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo);
  80. extern void smgrdounlink(SMgrRelation reln, bool isRedo);
  81. extern void smgrdounlinkall(SMgrRelation *rels, int nrels, bool isRedo);
  82. extern void smgrdounlinkfork(SMgrRelation reln, ForkNumber forknum, bool isRedo);
  83. extern void smgrextend(SMgrRelation reln, ForkNumber forknum,
  84. BlockNumber blocknum, char *buffer, bool skipFsync);
  85. extern void smgrprefetch(SMgrRelation reln, ForkNumber forknum,
  86. BlockNumber blocknum);
  87. extern void smgrread(SMgrRelation reln, ForkNumber forknum,
  88. BlockNumber blocknum, char *buffer);
  89. extern void smgrwrite(SMgrRelation reln, ForkNumber forknum,
  90. BlockNumber blocknum, char *buffer, bool skipFsync);
  91. extern void smgrwriteback(SMgrRelation reln, ForkNumber forknum,
  92. BlockNumber blocknum, BlockNumber nblocks);
  93. extern BlockNumber smgrnblocks(SMgrRelation reln, ForkNumber forknum);
  94. extern void smgrtruncate(SMgrRelation reln, ForkNumber forknum,
  95. BlockNumber nblocks);
  96. extern void smgrimmedsync(SMgrRelation reln, ForkNumber forknum);
  97. extern void AtEOXact_SMgr(void);
  98. #endif /* SMGR_H */
上海开阖软件有限公司 沪ICP备12045867号-1