2
0

old_snapshot.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*-------------------------------------------------------------------------
  2. *
  3. * old_snapshot.h
  4. * Data structures for 'snapshot too old'
  5. *
  6. * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
  7. * Portions Copyright (c) 1994, Regents of the University of California
  8. *
  9. * IDENTIFICATION
  10. * src/include/utils/old_snapshot.h
  11. *
  12. *-------------------------------------------------------------------------
  13. */
  14. #ifndef OLD_SNAPSHOT_H
  15. #define OLD_SNAPSHOT_H
  16. #include "datatype/timestamp.h"
  17. #include "storage/s_lock.h"
  18. /*
  19. * Structure for dealing with old_snapshot_threshold implementation.
  20. */
  21. typedef struct OldSnapshotControlData
  22. {
  23. /*
  24. * Variables for old snapshot handling are shared among processes and are
  25. * only allowed to move forward.
  26. */
  27. slock_t mutex_current; /* protect current_timestamp */
  28. TimestampTz current_timestamp; /* latest snapshot timestamp */
  29. slock_t mutex_latest_xmin; /* protect latest_xmin and next_map_update */
  30. TransactionId latest_xmin; /* latest snapshot xmin */
  31. TimestampTz next_map_update; /* latest snapshot valid up to */
  32. slock_t mutex_threshold; /* protect threshold fields */
  33. TimestampTz threshold_timestamp; /* earlier snapshot is old */
  34. TransactionId threshold_xid; /* earlier xid may be gone */
  35. /*
  36. * Keep one xid per minute for old snapshot error handling.
  37. *
  38. * Use a circular buffer with a head offset, a count of entries currently
  39. * used, and a timestamp corresponding to the xid at the head offset. A
  40. * count_used value of zero means that there are no times stored; a
  41. * count_used value of OLD_SNAPSHOT_TIME_MAP_ENTRIES means that the buffer
  42. * is full and the head must be advanced to add new entries. Use
  43. * timestamps aligned to minute boundaries, since that seems less
  44. * surprising than aligning based on the first usage timestamp. The
  45. * latest bucket is effectively stored within latest_xmin. The circular
  46. * buffer is updated when we get a new xmin value that doesn't fall into
  47. * the same interval.
  48. *
  49. * It is OK if the xid for a given time slot is from earlier than
  50. * calculated by adding the number of minutes corresponding to the
  51. * (possibly wrapped) distance from the head offset to the time of the
  52. * head entry, since that just results in the vacuuming of old tuples
  53. * being slightly less aggressive. It would not be OK for it to be off in
  54. * the other direction, since it might result in vacuuming tuples that are
  55. * still expected to be there.
  56. *
  57. * Use of an SLRU was considered but not chosen because it is more
  58. * heavyweight than is needed for this, and would probably not be any less
  59. * code to implement.
  60. *
  61. * Persistence is not needed.
  62. */
  63. int head_offset; /* subscript of oldest tracked time */
  64. TimestampTz head_timestamp; /* time corresponding to head xid */
  65. int count_used; /* how many slots are in use */
  66. TransactionId xid_by_minute[FLEXIBLE_ARRAY_MEMBER];
  67. } OldSnapshotControlData;
  68. extern PGDLLIMPORT volatile OldSnapshotControlData *oldSnapshotControl;
  69. #endif