gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 line
5.3KB

  1. /*-------------------------------------------------------------------------
  2. *
  3. * slru.h
  4. * Simple LRU buffering for transaction status logfiles
  5. *
  6. * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
  7. * Portions Copyright (c) 1994, Regents of the University of California
  8. *
  9. * src/include/access/slru.h
  10. *
  11. *-------------------------------------------------------------------------
  12. */
  13. #ifndef SLRU_H
  14. #define SLRU_H
  15. #include "access/xlogdefs.h"
  16. #include "storage/lwlock.h"
  17. /*
  18. * Define SLRU segment size. A page is the same BLCKSZ as is used everywhere
  19. * else in Postgres. The segment size can be chosen somewhat arbitrarily;
  20. * we make it 32 pages by default, or 256Kb, i.e. 1M transactions for CLOG
  21. * or 64K transactions for SUBTRANS.
  22. *
  23. * Note: because TransactionIds are 32 bits and wrap around at 0xFFFFFFFF,
  24. * page numbering also wraps around at 0xFFFFFFFF/xxxx_XACTS_PER_PAGE (where
  25. * xxxx is CLOG or SUBTRANS, respectively), and segment numbering at
  26. * 0xFFFFFFFF/xxxx_XACTS_PER_PAGE/SLRU_PAGES_PER_SEGMENT. We need
  27. * take no explicit notice of that fact in slru.c, except when comparing
  28. * segment and page numbers in SimpleLruTruncate (see PagePrecedes()).
  29. */
  30. #define SLRU_PAGES_PER_SEGMENT 32
  31. /* Maximum length of an SLRU name */
  32. #define SLRU_MAX_NAME_LENGTH 32
  33. /*
  34. * Page status codes. Note that these do not include the "dirty" bit.
  35. * page_dirty can be true only in the VALID or WRITE_IN_PROGRESS states;
  36. * in the latter case it implies that the page has been re-dirtied since
  37. * the write started.
  38. */
  39. typedef enum
  40. {
  41. SLRU_PAGE_EMPTY, /* buffer is not in use */
  42. SLRU_PAGE_READ_IN_PROGRESS, /* page is being read in */
  43. SLRU_PAGE_VALID, /* page is valid and not being written */
  44. SLRU_PAGE_WRITE_IN_PROGRESS /* page is being written out */
  45. } SlruPageStatus;
  46. /*
  47. * Shared-memory state
  48. */
  49. typedef struct SlruSharedData
  50. {
  51. LWLock *ControlLock;
  52. /* Number of buffers managed by this SLRU structure */
  53. int num_slots;
  54. /*
  55. * Arrays holding info for each buffer slot. Page number is undefined
  56. * when status is EMPTY, as is page_lru_count.
  57. */
  58. char **page_buffer;
  59. SlruPageStatus *page_status;
  60. bool *page_dirty;
  61. int *page_number;
  62. int *page_lru_count;
  63. /*
  64. * Optional array of WAL flush LSNs associated with entries in the SLRU
  65. * pages. If not zero/NULL, we must flush WAL before writing pages (true
  66. * for pg_xact, false for multixact, pg_subtrans, pg_notify). group_lsn[]
  67. * has lsn_groups_per_page entries per buffer slot, each containing the
  68. * highest LSN known for a contiguous group of SLRU entries on that slot's
  69. * page.
  70. */
  71. XLogRecPtr *group_lsn;
  72. int lsn_groups_per_page;
  73. /*----------
  74. * We mark a page "most recently used" by setting
  75. * page_lru_count[slotno] = ++cur_lru_count;
  76. * The oldest page is therefore the one with the highest value of
  77. * cur_lru_count - page_lru_count[slotno]
  78. * The counts will eventually wrap around, but this calculation still
  79. * works as long as no page's age exceeds INT_MAX counts.
  80. *----------
  81. */
  82. int cur_lru_count;
  83. /*
  84. * latest_page_number is the page number of the current end of the log;
  85. * this is not critical data, since we use it only to avoid swapping out
  86. * the latest page.
  87. */
  88. int latest_page_number;
  89. /* LWLocks */
  90. int lwlock_tranche_id;
  91. char lwlock_tranche_name[SLRU_MAX_NAME_LENGTH];
  92. LWLockPadded *buffer_locks;
  93. } SlruSharedData;
  94. typedef SlruSharedData *SlruShared;
  95. /*
  96. * SlruCtlData is an unshared structure that points to the active information
  97. * in shared memory.
  98. */
  99. typedef struct SlruCtlData
  100. {
  101. SlruShared shared;
  102. /*
  103. * This flag tells whether to fsync writes (true for pg_xact and multixact
  104. * stuff, false for pg_subtrans and pg_notify).
  105. */
  106. bool do_fsync;
  107. /*
  108. * Decide which of two page numbers is "older" for truncation purposes. We
  109. * need to use comparison of TransactionIds here in order to do the right
  110. * thing with wraparound XID arithmetic.
  111. */
  112. bool (*PagePrecedes) (int, int);
  113. /*
  114. * Dir is set during SimpleLruInit and does not change thereafter. Since
  115. * it's always the same, it doesn't need to be in shared memory.
  116. */
  117. char Dir[64];
  118. } SlruCtlData;
  119. typedef SlruCtlData *SlruCtl;
  120. extern Size SimpleLruShmemSize(int nslots, int nlsns);
  121. extern void SimpleLruInit(SlruCtl ctl, const char *name, int nslots, int nlsns,
  122. LWLock *ctllock, const char *subdir, int tranche_id);
  123. extern int SimpleLruZeroPage(SlruCtl ctl, int pageno);
  124. extern int SimpleLruReadPage(SlruCtl ctl, int pageno, bool write_ok,
  125. TransactionId xid);
  126. extern int SimpleLruReadPage_ReadOnly(SlruCtl ctl, int pageno,
  127. TransactionId xid);
  128. extern void SimpleLruWritePage(SlruCtl ctl, int slotno);
  129. extern void SimpleLruFlush(SlruCtl ctl, bool allow_redirtied);
  130. extern void SimpleLruTruncate(SlruCtl ctl, int cutoffPage);
  131. extern bool SimpleLruDoesPhysicalPageExist(SlruCtl ctl, int pageno);
  132. typedef bool (*SlruScanCallback) (SlruCtl ctl, char *filename, int segpage,
  133. void *data);
  134. extern bool SlruScanDirectory(SlruCtl ctl, SlruScanCallback callback, void *data);
  135. extern void SlruDeleteSegment(SlruCtl ctl, int segno);
  136. /* SlruScanDirectory public callbacks */
  137. extern bool SlruScanDirCbReportPresence(SlruCtl ctl, char *filename,
  138. int segpage, void *data);
  139. extern bool SlruScanDirCbDeleteAll(SlruCtl ctl, char *filename, int segpage,
  140. void *data);
  141. #endif /* SLRU_H */
上海开阖软件有限公司 沪ICP备12045867号-1