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

1804{
1805 int fd;
1806 pg_crc32c checksum;
1807 Size sz;
1808 char path[MAXPGPATH];
1809
1810 sprintf(path, "%s/%X-%X.snap",
1812 LSN_FORMAT_ARGS(lsn));
1813
1815
1816 if (fd < 0)
1817 {
1818 if (missing_ok && errno == ENOENT)
1819 return false;
1820
1821 ereport(ERROR,
1823 errmsg("could not open file \"%s\": %m", path)));
1824 }
1825
1826 /* ----
1827 * Make sure the snapshot had been stored safely to disk, that's normally
1828 * cheap.
1829 * Note that we do not need PANIC here, nobody will be able to use the
1830 * slot without fsyncing, and saving it won't succeed without an fsync()
1831 * either...
1832 * ----
1833 */
1834 fsync_fname(path, false);
1836
1837 /* read statically sized portion of snapshot */
1839
1840 if (ondisk->magic != SNAPBUILD_MAGIC)
1841 ereport(ERROR,
1843 errmsg("snapbuild state file \"%s\" has wrong magic number: %u instead of %u",
1844 path, ondisk->magic, SNAPBUILD_MAGIC)));
1845
1846 if (ondisk->version != SNAPBUILD_VERSION)
1847 ereport(ERROR,
1849 errmsg("snapbuild state file \"%s\" has unsupported version: %u instead of %u",
1850 path, ondisk->version, SNAPBUILD_VERSION)));
1851
1852 INIT_CRC32C(checksum);
1853 COMP_CRC32C(checksum,
1854 ((char *) ondisk) + SnapBuildOnDiskNotChecksummedSize,
1856
1857 /* read SnapBuild */
1858 SnapBuildRestoreContents(fd, &ondisk->builder, sizeof(SnapBuild), path);
1859 COMP_CRC32C(checksum, &ondisk->builder, sizeof(SnapBuild));
1860
1861 /* restore committed xacts information */
1862 if (ondisk->builder.committed.xcnt > 0)
1863 {
1864 sz = sizeof(TransactionId) * ondisk->builder.committed.xcnt;
1865 ondisk->builder.committed.xip = MemoryContextAllocZero(context, sz);
1867 COMP_CRC32C(checksum, ondisk->builder.committed.xip, sz);
1868 }
1869
1870 /* restore catalog modifying xacts information */
1871 if (ondisk->builder.catchange.xcnt > 0)
1872 {
1873 sz = sizeof(TransactionId) * ondisk->builder.catchange.xcnt;
1874 ondisk->builder.catchange.xip = MemoryContextAllocZero(context, sz);
1876 COMP_CRC32C(checksum, ondisk->builder.catchange.xip, sz);
1877 }
1878
1879 if (CloseTransientFile(fd) != 0)
1880 ereport(ERROR,
1882 errmsg("could not close file \"%s\": %m", path)));
1883
1884 FIN_CRC32C(checksum);
1885
1886 /* verify checksum of what we've read */
1887 if (!EQ_CRC32C(checksum, ondisk->checksum))
1888 ereport(ERROR,
1890 errmsg("checksum mismatch for snapbuild state file \"%s\": is %u, should be %u",
1891 path, checksum, ondisk->checksum)));
1892
1893 return true;
1894}
#define PG_BINARY
Definition c.h:1374
uint32 TransactionId
Definition c.h:736
size_t Size
Definition c.h:689
int errcode_for_file_access(void)
Definition elog.c:897
int errcode(int sqlerrcode)
Definition elog.c:874
#define ERROR
Definition elog.h:39
#define ereport(elevel,...)
Definition elog.h:151
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:1266
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:173
#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:178
#define sprintf
Definition port.h:262
static int fd(const char *x, int i)
static int fb(int x)
#define PG_LOGICAL_SNAPSHOTS_DIR
#define SNAPBUILD_VERSION
Definition snapbuild.c:1535
#define SnapBuildOnDiskNotChecksummedSize
Definition snapbuild.c:1531
#define SNAPBUILD_MAGIC
Definition snapbuild.c:1534
#define SnapBuildOnDiskConstantSize
Definition snapbuild.c:1529
static void SnapBuildRestoreContents(int fd, void *dest, Size size, const char *path)
Definition snapbuild.c:1993
TransactionId * xip
struct SnapBuild::@121 committed
struct SnapBuild::@124 catchange
#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().