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 1746 of file snapbuild.c.

1748{
1749 int fd;
1750 pg_crc32c checksum;
1751 Size sz;
1752 char path[MAXPGPATH];
1753
1754 sprintf(path, "%s/%X-%X.snap",
1756 LSN_FORMAT_ARGS(lsn));
1757
1759
1760 if (fd < 0)
1761 {
1762 if (missing_ok && errno == ENOENT)
1763 return false;
1764
1765 ereport(ERROR,
1767 errmsg("could not open file \"%s\": %m", path)));
1768 }
1769
1770 /* ----
1771 * Make sure the snapshot had been stored safely to disk, that's normally
1772 * cheap.
1773 * Note that we do not need PANIC here, nobody will be able to use the
1774 * slot without fsyncing, and saving it won't succeed without an fsync()
1775 * either...
1776 * ----
1777 */
1778 fsync_fname(path, false);
1780
1781 /* read statically sized portion of snapshot */
1783
1784 if (ondisk->magic != SNAPBUILD_MAGIC)
1785 ereport(ERROR,
1787 errmsg("snapbuild state file \"%s\" has wrong magic number: %u instead of %u",
1788 path, ondisk->magic, SNAPBUILD_MAGIC)));
1789
1790 if (ondisk->version != SNAPBUILD_VERSION)
1791 ereport(ERROR,
1793 errmsg("snapbuild state file \"%s\" has unsupported version: %u instead of %u",
1794 path, ondisk->version, SNAPBUILD_VERSION)));
1795
1796 INIT_CRC32C(checksum);
1797 COMP_CRC32C(checksum,
1798 ((char *) ondisk) + SnapBuildOnDiskNotChecksummedSize,
1800
1801 /* read SnapBuild */
1802 SnapBuildRestoreContents(fd, &ondisk->builder, sizeof(SnapBuild), path);
1803 COMP_CRC32C(checksum, &ondisk->builder, sizeof(SnapBuild));
1804
1805 /* restore committed xacts information */
1806 if (ondisk->builder.committed.xcnt > 0)
1807 {
1808 sz = sizeof(TransactionId) * ondisk->builder.committed.xcnt;
1809 ondisk->builder.committed.xip = MemoryContextAllocZero(context, sz);
1811 COMP_CRC32C(checksum, ondisk->builder.committed.xip, sz);
1812 }
1813
1814 /* restore catalog modifying xacts information */
1815 if (ondisk->builder.catchange.xcnt > 0)
1816 {
1817 sz = sizeof(TransactionId) * ondisk->builder.catchange.xcnt;
1818 ondisk->builder.catchange.xip = MemoryContextAllocZero(context, sz);
1820 COMP_CRC32C(checksum, ondisk->builder.catchange.xip, sz);
1821 }
1822
1823 if (CloseTransientFile(fd) != 0)
1824 ereport(ERROR,
1826 errmsg("could not close file \"%s\": %m", path)));
1827
1828 FIN_CRC32C(checksum);
1829
1830 /* verify checksum of what we've read */
1831 if (!EQ_CRC32C(checksum, ondisk->checksum))
1832 ereport(ERROR,
1834 errmsg("checksum mismatch for snapbuild state file \"%s\": is %u, should be %u",
1835 path, checksum, ondisk->checksum)));
1836
1837 return true;
1838}
#define PG_BINARY
Definition c.h:1386
uint32 TransactionId
Definition c.h:736
size_t Size
Definition c.h:689
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:1479
#define SnapBuildOnDiskNotChecksummedSize
Definition snapbuild.c:1475
#define SNAPBUILD_MAGIC
Definition snapbuild.c:1478
#define SnapBuildOnDiskConstantSize
Definition snapbuild.c:1473
static void SnapBuildRestoreContents(int fd, void *dest, Size size, const char *path)
Definition snapbuild.c:1937
struct SnapBuild::@119 catchange
struct SnapBuild::@118 committed
TransactionId * xip
#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().