xlogdefs.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * xlogdefs.h
  3. *
  4. * Postgres transaction log manager record pointer and
  5. * timeline number definitions
  6. *
  7. * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
  8. * Portions Copyright (c) 1994, Regents of the University of California
  9. *
  10. * src/include/access/xlogdefs.h
  11. */
  12. #ifndef XLOG_DEFS_H
  13. #define XLOG_DEFS_H
  14. #include <fcntl.h> /* need open() flags */
  15. /*
  16. * Pointer to a location in the XLOG. These pointers are 64 bits wide,
  17. * because we don't want them ever to overflow.
  18. */
  19. typedef uint64 XLogRecPtr;
  20. /*
  21. * Zero is used indicate an invalid pointer. Bootstrap skips the first possible
  22. * WAL segment, initializing the first WAL page at XLOG_SEG_SIZE, so no XLOG
  23. * record can begin at zero.
  24. */
  25. #define InvalidXLogRecPtr 0
  26. #define XLogRecPtrIsInvalid(r) ((r) == InvalidXLogRecPtr)
  27. /*
  28. * XLogSegNo - physical log file sequence number.
  29. */
  30. typedef uint64 XLogSegNo;
  31. /*
  32. * TimeLineID (TLI) - identifies different database histories to prevent
  33. * confusion after restoring a prior state of a database installation.
  34. * TLI does not change in a normal stop/restart of the database (including
  35. * crash-and-recover cases); but we must assign a new TLI after doing
  36. * a recovery to a prior state, a/k/a point-in-time recovery. This makes
  37. * the new WAL logfile sequence we generate distinguishable from the
  38. * sequence that was generated in the previous incarnation.
  39. */
  40. typedef uint32 TimeLineID;
  41. /*
  42. * Replication origin id - this is located in this file to avoid having to
  43. * include origin.h in a bunch of xlog related places.
  44. */
  45. typedef uint16 RepOriginId;
  46. /*
  47. * Because O_DIRECT bypasses the kernel buffers, and because we never
  48. * read those buffers except during crash recovery or if wal_level != minimal,
  49. * it is a win to use it in all cases where we sync on each write(). We could
  50. * allow O_DIRECT with fsync(), but it is unclear if fsync() could process
  51. * writes not buffered in the kernel. Also, O_DIRECT is never enough to force
  52. * data to the drives, it merely tries to bypass the kernel cache, so we still
  53. * need O_SYNC/O_DSYNC.
  54. */
  55. #ifdef O_DIRECT
  56. #define PG_O_DIRECT O_DIRECT
  57. #else
  58. #define PG_O_DIRECT 0
  59. #endif
  60. /*
  61. * This chunk of hackery attempts to determine which file sync methods
  62. * are available on the current platform, and to choose an appropriate
  63. * default method. We assume that fsync() is always available, and that
  64. * configure determined whether fdatasync() is.
  65. */
  66. #if defined(O_SYNC)
  67. #define OPEN_SYNC_FLAG O_SYNC
  68. #elif defined(O_FSYNC)
  69. #define OPEN_SYNC_FLAG O_FSYNC
  70. #endif
  71. #if defined(O_DSYNC)
  72. #if defined(OPEN_SYNC_FLAG)
  73. /* O_DSYNC is distinct? */
  74. #if O_DSYNC != OPEN_SYNC_FLAG
  75. #define OPEN_DATASYNC_FLAG O_DSYNC
  76. #endif
  77. #else /* !defined(OPEN_SYNC_FLAG) */
  78. /* Win32 only has O_DSYNC */
  79. #define OPEN_DATASYNC_FLAG O_DSYNC
  80. #endif
  81. #endif
  82. #if defined(PLATFORM_DEFAULT_SYNC_METHOD)
  83. #define DEFAULT_SYNC_METHOD PLATFORM_DEFAULT_SYNC_METHOD
  84. #elif defined(OPEN_DATASYNC_FLAG)
  85. #define DEFAULT_SYNC_METHOD SYNC_METHOD_OPEN_DSYNC
  86. #elif defined(HAVE_FDATASYNC)
  87. #define DEFAULT_SYNC_METHOD SYNC_METHOD_FDATASYNC
  88. #else
  89. #define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC
  90. #endif
  91. #endif /* XLOG_DEFS_H */