PostgreSQL Source Code git master
Loading...
Searching...
No Matches
snapbuild_internal.h File Reference
Include dependency graph for snapbuild_internal.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SnapBuild
 
struct  SnapBuildOnDisk
 

Typedefs

typedef struct SnapBuildOnDisk SnapBuildOnDisk
 

Functions

bool SnapBuildRestoreSnapshot (SnapBuildOnDisk *ondisk, XLogRecPtr lsn, MemoryContext context, bool missing_ok)
 

Typedef Documentation

◆ SnapBuildOnDisk

Function Documentation

◆ SnapBuildRestoreSnapshot()

bool SnapBuildRestoreSnapshot ( SnapBuildOnDisk ondisk,
XLogRecPtr  lsn,
MemoryContext  context,
bool  missing_ok 
)
extern

Definition at line 1747 of file snapbuild.c.

1749{
1750 int fd;
1751 pg_crc32c checksum;
1752 Size sz;
1753 char path[MAXPGPATH];
1754
1755 sprintf(path, "%s/%X-%X.snap",
1757 LSN_FORMAT_ARGS(lsn));
1758
1760
1761 if (fd < 0)
1762 {
1763 if (missing_ok && errno == ENOENT)
1764 return false;
1765
1766 ereport(ERROR,
1768 errmsg("could not open file \"%s\": %m", path)));
1769 }
1770
1771 /* ----
1772 * Make sure the snapshot had been stored safely to disk, that's normally
1773 * cheap.
1774 * Note that we do not need PANIC here, nobody will be able to use the
1775 * slot without fsyncing, and saving it won't succeed without an fsync()
1776 * either...
1777 * ----
1778 */
1779 fsync_fname(path, false);
1781
1782 /* read statically sized portion of snapshot */
1784
1785 if (ondisk->magic != SNAPBUILD_MAGIC)
1786 ereport(ERROR,
1788 errmsg("snapbuild state file \"%s\" has wrong magic number: %u instead of %u",
1789 path, ondisk->magic, SNAPBUILD_MAGIC)));
1790
1791 if (ondisk->version != SNAPBUILD_VERSION)
1792 ereport(ERROR,
1794 errmsg("snapbuild state file \"%s\" has unsupported version: %u instead of %u",
1795 path, ondisk->version, SNAPBUILD_VERSION)));
1796
1797 INIT_CRC32C(checksum);
1798 COMP_CRC32C(checksum,
1799 ((char *) ondisk) + SnapBuildOnDiskNotChecksummedSize,
1801
1802 /* read SnapBuild */
1803 SnapBuildRestoreContents(fd, &ondisk->builder, sizeof(SnapBuild), path);
1804 COMP_CRC32C(checksum, &ondisk->builder, sizeof(SnapBuild));
1805
1806 /* restore committed xacts information */
1807 if (ondisk->builder.committed.xcnt > 0)
1808 {
1809 sz = sizeof(TransactionId) * ondisk->builder.committed.xcnt;
1810 ondisk->builder.committed.xip = MemoryContextAllocZero(context, sz);
1812 COMP_CRC32C(checksum, ondisk->builder.committed.xip, sz);
1813 }
1814
1815 /* restore catalog modifying xacts information */
1816 if (ondisk->builder.catchange.xcnt > 0)
1817 {
1818 sz = sizeof(TransactionId) * ondisk->builder.catchange.xcnt;
1819 ondisk->builder.catchange.xip = MemoryContextAllocZero(context, sz);
1821 COMP_CRC32C(checksum, ondisk->builder.catchange.xip, sz);
1822 }
1823
1824 if (CloseTransientFile(fd) != 0)
1825 ereport(ERROR,
1827 errmsg("could not close file \"%s\": %m", path)));
1828
1829 FIN_CRC32C(checksum);
1830
1831 /* verify checksum of what we've read */
1832 if (!EQ_CRC32C(checksum, ondisk->checksum))
1833 ereport(ERROR,
1835 errmsg("checksum mismatch for snapbuild state file \"%s\": is %u, should be %u",
1836 path, checksum, ondisk->checksum)));
1837
1838 return true;
1839}
#define PG_BINARY
Definition c.h:1431
uint32 TransactionId
Definition c.h:795
size_t Size
Definition c.h:748
int errcode_for_file_access(void)
Definition elog.c:898
int errcode(int sqlerrcode)
Definition elog.c:875
#define ERROR
Definition elog.h:40
#define ereport(elevel,...)
Definition elog.h:152
int CloseTransientFile(int fd)
Definition fd.c:2855
void fsync_fname(const char *fname, bool isdir)
Definition fd.c:757
int OpenTransientFile(const char *fileName, int fileFlags)
Definition fd.c:2678
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition mcxt.c:1269
static char * errmsg
#define ERRCODE_DATA_CORRUPTED
#define MAXPGPATH
uint32 pg_crc32c
Definition pg_crc32c.h:38
#define COMP_CRC32C(crc, data, len)
Definition pg_crc32c.h:177
#define EQ_CRC32C(c1, c2)
Definition pg_crc32c.h:42
#define INIT_CRC32C(crc)
Definition pg_crc32c.h:41
#define FIN_CRC32C(crc)
Definition pg_crc32c.h:182
#define sprintf
Definition port.h:263
static int fd(const char *x, int i)
static int fb(int x)
#define PG_LOGICAL_SNAPSHOTS_DIR
#define SNAPBUILD_VERSION
Definition snapbuild.c:1480
#define SnapBuildOnDiskNotChecksummedSize
Definition snapbuild.c:1476
#define SNAPBUILD_MAGIC
Definition snapbuild.c:1479
#define SnapBuildOnDiskConstantSize
Definition snapbuild.c:1474
static void SnapBuildRestoreContents(int fd, void *dest, Size size, const char *path)
Definition snapbuild.c:1938
TransactionId * xip
struct SnapBuild::@117 catchange
struct SnapBuild::@116 committed
#define LSN_FORMAT_ARGS(lsn)
Definition xlogdefs.h:47

References SnapBuildOnDisk::builder, SnapBuild::catchange, SnapBuildOnDisk::checksum, CloseTransientFile(), SnapBuild::committed, COMP_CRC32C, EQ_CRC32C, ereport, errcode(), ERRCODE_DATA_CORRUPTED, errcode_for_file_access(), errmsg, ERROR, fb(), fd(), FIN_CRC32C, fsync_fname(), INIT_CRC32C, LSN_FORMAT_ARGS, SnapBuildOnDisk::magic, MAXPGPATH, MemoryContextAllocZero(), OpenTransientFile(), PG_BINARY, PG_LOGICAL_SNAPSHOTS_DIR, SNAPBUILD_MAGIC, SNAPBUILD_VERSION, SnapBuildOnDiskConstantSize, SnapBuildOnDiskNotChecksummedSize, SnapBuildRestoreContents(), sprintf, SnapBuildOnDisk::version, SnapBuild::xcnt, and SnapBuild::xip.

Referenced by pg_get_logical_snapshot_info(), pg_get_logical_snapshot_meta(), and SnapBuildRestore().