PostgreSQL Source Code git master
Data Structures | Typedefs | Functions
snapbuild_internal.h File Reference
#include "port/pg_crc32c.h"
#include "replication/reorderbuffer.h"
#include "replication/snapbuild.h"
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 ( SnapBuildOnDiskondisk,
XLogRecPtr  lsn,
MemoryContext  context,
bool  missing_ok 
)

Definition at line 1742 of file snapbuild.c.

1744{
1745 int fd;
1746 pg_crc32c checksum;
1747 Size sz;
1748 char path[MAXPGPATH];
1749
1750 sprintf(path, "%s/%X-%X.snap",
1752 LSN_FORMAT_ARGS(lsn));
1753
1754 fd = OpenTransientFile(path, O_RDONLY | PG_BINARY);
1755
1756 if (fd < 0)
1757 {
1758 if (missing_ok && errno == ENOENT)
1759 return false;
1760
1761 ereport(ERROR,
1763 errmsg("could not open file \"%s\": %m", path)));
1764 }
1765
1766 /* ----
1767 * Make sure the snapshot had been stored safely to disk, that's normally
1768 * cheap.
1769 * Note that we do not need PANIC here, nobody will be able to use the
1770 * slot without fsyncing, and saving it won't succeed without an fsync()
1771 * either...
1772 * ----
1773 */
1774 fsync_fname(path, false);
1776
1777 /* read statically sized portion of snapshot */
1779
1780 if (ondisk->magic != SNAPBUILD_MAGIC)
1781 ereport(ERROR,
1783 errmsg("snapbuild state file \"%s\" has wrong magic number: %u instead of %u",
1784 path, ondisk->magic, SNAPBUILD_MAGIC)));
1785
1786 if (ondisk->version != SNAPBUILD_VERSION)
1787 ereport(ERROR,
1789 errmsg("snapbuild state file \"%s\" has unsupported version: %u instead of %u",
1790 path, ondisk->version, SNAPBUILD_VERSION)));
1791
1792 INIT_CRC32C(checksum);
1793 COMP_CRC32C(checksum,
1794 ((char *) ondisk) + SnapBuildOnDiskNotChecksummedSize,
1796
1797 /* read SnapBuild */
1798 SnapBuildRestoreContents(fd, &ondisk->builder, sizeof(SnapBuild), path);
1799 COMP_CRC32C(checksum, &ondisk->builder, sizeof(SnapBuild));
1800
1801 /* restore committed xacts information */
1802 if (ondisk->builder.committed.xcnt > 0)
1803 {
1804 sz = sizeof(TransactionId) * ondisk->builder.committed.xcnt;
1805 ondisk->builder.committed.xip = MemoryContextAllocZero(context, sz);
1806 SnapBuildRestoreContents(fd, ondisk->builder.committed.xip, sz, path);
1807 COMP_CRC32C(checksum, ondisk->builder.committed.xip, sz);
1808 }
1809
1810 /* restore catalog modifying xacts information */
1811 if (ondisk->builder.catchange.xcnt > 0)
1812 {
1813 sz = sizeof(TransactionId) * ondisk->builder.catchange.xcnt;
1814 ondisk->builder.catchange.xip = MemoryContextAllocZero(context, sz);
1815 SnapBuildRestoreContents(fd, ondisk->builder.catchange.xip, sz, path);
1816 COMP_CRC32C(checksum, ondisk->builder.catchange.xip, sz);
1817 }
1818
1819 if (CloseTransientFile(fd) != 0)
1820 ereport(ERROR,
1822 errmsg("could not close file \"%s\": %m", path)));
1823
1824 FIN_CRC32C(checksum);
1825
1826 /* verify checksum of what we've read */
1827 if (!EQ_CRC32C(checksum, ondisk->checksum))
1828 ereport(ERROR,
1830 errmsg("checksum mismatch for snapbuild state file \"%s\": is %u, should be %u",
1831 path, checksum, ondisk->checksum)));
1832
1833 return true;
1834}
#define PG_BINARY
Definition: c.h:1272
uint32 TransactionId
Definition: c.h:657
size_t Size
Definition: c.h:610
int errcode_for_file_access(void)
Definition: elog.c:877
int errcode(int sqlerrcode)
Definition: elog.c:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:150
int CloseTransientFile(int fd)
Definition: fd.c:2868
void fsync_fname(const char *fname, bool isdir)
Definition: fd.c:753
int OpenTransientFile(const char *fileName, int fileFlags)
Definition: fd.c:2691
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:1263
#define ERRCODE_DATA_CORRUPTED
Definition: pg_basebackup.c:42
#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:241
static int fd(const char *x, int i)
Definition: preproc-init.c:105
#define PG_LOGICAL_SNAPSHOTS_DIR
Definition: reorderbuffer.h:24
#define SNAPBUILD_VERSION
Definition: snapbuild.c:1475
#define SnapBuildOnDiskNotChecksummedSize
Definition: snapbuild.c:1471
#define SNAPBUILD_MAGIC
Definition: snapbuild.c:1474
#define SnapBuildOnDiskConstantSize
Definition: snapbuild.c:1469
static void SnapBuildRestoreContents(int fd, void *dest, Size size, const char *path)
Definition: snapbuild.c:1933
struct SnapBuild::@112 committed
struct SnapBuild::@113 catchange
TransactionId * xip
#define LSN_FORMAT_ARGS(lsn)
Definition: xlogdefs.h:46

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, 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().

AltStyle によって変換されたページ (->オリジナル) /