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

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