32#define BLOCKS_PER_READ 512
40#define MAX_CHUNK (128 * 1024)
63#define SH_PREFIX backup_file
64#define SH_ELEMENT_TYPE backup_file_entry
65#define SH_KEY_TYPE const char *
67#define SH_HASH_KEY(tb, key) hash_string_pointer(key)
68#define SH_EQUAL(tb, a, b) (strcmp(a, b) == 0)
69#define SH_SCOPE static inline
129 int manifest_version);
131 uint64 manifest_system_identifier);
133 const char *pathname,
137 uint8 *checksum_payload);
292 errmsg(
"manifest contains no required WAL ranges")));
347 errmsg(
"timeline %u found in manifest, but not in this server's history",
412 errmsg(
"manifest requires WAL from initial timeline %u starting at %X/%08X, but that timeline begins at %X/%08X",
422 errmsg(
"manifest requires WAL from continuation timeline %u starting at %X/%08X, but that timeline begins at %X/%08X",
433 errmsg(
"manifest requires WAL from final timeline %u ending at %X/%08X, but this backup starts at %X/%08X",
437 errhint(
"This can happen for incremental backups on a standby if there was little activity since the previous backup.")));
444 errmsg(
"manifest requires WAL from non-final timeline %u ending at %X/%08X, but this server switched timelines at %X/%08X",
525 errmsg(
"WAL summaries are required on timeline %u from %X/%08X to %X/%08X, but no summaries for that timeline and LSN range exist",
532 errmsg(
"WAL summaries are required on timeline %u from %X/%08X to %X/%08X, but the summaries for that timeline and LSN range are incomplete",
536 errdetail(
"The first unsummarized LSN in this range is %X/%08X.",
594 forknum, limit_block);
606 for (
i = 0;
i < nblocks; ++
i)
666 unsigned segno,
size_t size,
669 unsigned *truncation_block_length)
740 rlocator.
dbOid = dboid;
743 &limit_block) !=
NULL)
773 *truncation_block_length = size /
BLCKSZ;
795 errmsg_internal(
"overflow computing block number bounds for segment %u with size %zu",
818 if (nblocks *
BLCKSZ > size * 0.9)
835 for (
i = 0;
i < nblocks; ++
i)
848 *truncation_block_length = size /
BLCKSZ;
933 unsigned char *ss = (
unsigned char *) s;
943 int manifest_version)
946 if (manifest_version == 1)
948 "backup manifest version 1 does not support incremental backup");
957 uint64 manifest_system_identifier)
964 if (manifest_system_identifier != system_identifier)
966 "system identifier in backup manifest is %" PRIu64 ", but database system identifier is %" PRIu64,
967 manifest_system_identifier,
979 const char *pathname,
uint64 size,
982 uint8 *checksum_payload)
1013 range->start_lsn = start_lsn;
1014 range->end_lsn = end_lsn;
List * readTimeLineHistory(TimeLineID targetTLI)
void AppendIncrementalManifestData(IncrementalBackupInfo *ib, const char *data, int len)
static void manifest_process_version(JsonManifestParseContext *context, int manifest_version)
static pg_noreturn void static int compare_block_numbers(const void *a, const void *b)
static uint32 hash_string_pointer(const char *s)
size_t GetIncrementalHeaderSize(unsigned num_blocks_required)
static void manifest_process_system_identifier(JsonManifestParseContext *context, uint64 manifest_system_identifier)
size_t GetIncrementalFileSize(unsigned num_blocks_required)
static void manifest_process_file(JsonManifestParseContext *context, const char *pathname, uint64 size, pg_checksum_type checksum_type, int checksum_length, uint8 *checksum_payload)
IncrementalBackupInfo * CreateIncrementalBackupInfo(MemoryContext mcxt)
FileBackupMethod GetFileBackupMethod(IncrementalBackupInfo *ib, const char *path, Oid dboid, Oid spcoid, RelFileNumber relfilenumber, ForkNumber forknum, unsigned segno, size_t size, unsigned *num_blocks_required, BlockNumber *relative_block_numbers, unsigned *truncation_block_length)
static pg_noreturn void manifest_report_error(JsonManifestParseContext *context, const char *fmt,...) pg_attribute_printf(2
char * GetIncrementalFilePath(Oid dboid, Oid spcoid, RelFileNumber relfilenumber, ForkNumber forknum, unsigned segno)
static void manifest_process_wal_range(JsonManifestParseContext *context, TimeLineID tli, XLogRecPtr start_lsn, XLogRecPtr end_lsn)
void PrepareForIncrementalBackup(IncrementalBackupInfo *ib, BackupState *backup_state)
void FinalizeIncrementalManifest(IncrementalBackupInfo *ib)
@ BACK_UP_FILE_INCREMENTALLY
BlockRefTableEntry * BlockRefTableGetEntry(BlockRefTable *brtab, const RelFileLocator *rlocator, ForkNumber forknum, BlockNumber *limit_block)
bool BlockRefTableReaderNextRelation(BlockRefTableReader *reader, RelFileLocator *rlocator, ForkNumber *forknum, BlockNumber *limit_block)
int BlockRefTableEntryGetBlocks(BlockRefTableEntry *entry, BlockNumber start_blkno, BlockNumber stop_blkno, BlockNumber *blocks, int nblocks)
void BlockRefTableMarkBlockModified(BlockRefTable *brtab, const RelFileLocator *rlocator, ForkNumber forknum, BlockNumber blknum)
BlockRefTableReader * CreateBlockRefTableReader(io_callback_fn read_callback, void *read_callback_arg, char *error_filename, report_error_fn error_callback, void *error_callback_arg)
unsigned BlockRefTableReaderGetBlocks(BlockRefTableReader *reader, BlockNumber *blocks, int nblocks)
void BlockRefTableSetLimitBlock(BlockRefTable *brtab, const RelFileLocator *rlocator, ForkNumber forknum, BlockNumber limit_block)
void DestroyBlockRefTableReader(BlockRefTableReader *reader)
void(*) BlockRefTable CreateEmptyBlockRefTable)(void)
static bool BlockNumberIsValid(BlockNumber blockNumber)
#define Assert(condition)
#define pg_attribute_printf(f, a)
#define OidIsValid(objectId)
int errmsg_internal(const char *fmt,...)
int errdetail(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
char * FilePathName(File file)
void FileClose(File file)
#define palloc_object(type)
#define palloc0_object(type)
uint32 hash_bytes(const unsigned char *k, int keylen)
static int pg_cmp_u32(uint32 a, uint32 b)
List * lappend(List *list, void *datum)
List * list_concat(List *list1, const List *list2)
char * MemoryContextStrdup(MemoryContext context, const char *string)
void pfree(void *pointer)
void * palloc0(Size size)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
JsonManifestParseIncrementalState * json_parse_manifest_incremental_init(JsonManifestParseContext *context)
void json_parse_manifest_incremental_shutdown(JsonManifestParseIncrementalState *incstate)
void json_parse_manifest_incremental_chunk(JsonManifestParseIncrementalState *incstate, const char *chunk, size_t size, bool is_last)
static int list_length(const List *l)
static void * list_nth(const List *list, int n)
#define qsort(a, b, c, d)
#define INVALID_PROC_NUMBER
char * psprintf(const char *fmt,...)
static struct cvec * range(struct vars *v, chr a, chr b, int cases)
RelPathStr GetRelationPath(Oid dbOid, Oid spcOid, RelFileNumber relNumber, int procNumber, ForkNumber forkNumber)
#define RelFileNumberIsValid(relnumber)
int appendStringInfoVA(StringInfo str, const char *fmt, va_list args)
void enlargeStringInfo(StringInfo str, int needed)
void appendBinaryStringInfo(StringInfo str, const void *data, int datalen)
void initStringInfo(StringInfo str)
List * manifest_wal_ranges
backup_file_hash * manifest_files
JsonManifestParseIncrementalState * inc_state
json_manifest_per_wal_range_callback per_wal_range_cb
json_manifest_system_identifier_callback system_identifier_cb
json_manifest_error_callback error_cb
json_manifest_per_file_callback per_file_cb
json_manifest_version_callback version_cb
char str[REL_PATH_STR_MAXLEN+1]
void WaitForWalSummarization(XLogRecPtr lsn)
File OpenWalSummaryFile(WalSummaryFile *ws, bool missing_ok)
bool WalSummariesAreComplete(List *wslist, XLogRecPtr start_lsn, XLogRecPtr end_lsn, XLogRecPtr *missing_lsn)
int ReadWalSummary(void *wal_summary_io, void *data, int length)
List * GetWalSummaries(TimeLineID tli, XLogRecPtr start_lsn, XLogRecPtr end_lsn)
void ReportWalSummaryError(void *callback_arg, char *fmt,...)
List * FilterWalSummaries(List *wslist, TimeLineID tli, XLogRecPtr start_lsn, XLogRecPtr end_lsn)
uint64 GetSystemIdentifier(void)
#define XLogRecPtrIsValid(r)
#define LSN_FORMAT_ARGS(lsn)
#define InvalidXLogRecPtr
static BackupState * backup_state
static List * expectedTLEs