35 #define ESTIMATED_BYTES_PER_MANIFEST_LINE 100
41 #define READ_CHUNK_SIZE (128 * 1024)
47 #define SH_PREFIX manifest_files
48 #define SH_ELEMENT_TYPE manifest_file
49 #define SH_KEY_TYPE char *
50 #define SH_KEY pathname
51 #define SH_HASH_KEY(tb, key) hash_string(key)
52 #define SH_EQUAL(tb, a, b) (strcmp(a, b) == 0)
53 #define SH_SCOPE extern
54 #define SH_RAW_ALLOCATOR pg_malloc0
59 int manifest_version);
61 uint64 manifest_system_identifier);
63 char *pathname,
size_t size,
66 uint8 *checksum_payload);
89 for (
i = 0;
i < n_backups; ++
i)
112 manifest_files_hash *ht;
121 if ((
fd = open(pathname, O_RDONLY |
PG_BINARY, 0)) < 0)
128 pg_fatal(
"could not open file \"%s\": %m", pathname);
133 pg_fatal(
"could not stat file \"%s\": %m", pathname);
140 ht = manifest_files_create(initial_size, NULL);
154 if (statbuf.
st_size <= chunk_size)
161 pg_fatal(
"could not read file \"%s\": %m", pathname);
163 pg_fatal(
"could not read file \"%s\": read %d of %lld",
164 pathname, rc, (
long long int) statbuf.
st_size);
175 int bytes_left = statbuf.
st_size;
182 while (bytes_left > 0)
184 int bytes_to_read = chunk_size;
191 if (bytes_left < chunk_size)
192 bytes_to_read = bytes_left;
193 else if (bytes_left < 2 * chunk_size)
194 bytes_to_read = bytes_left / 2;
195 rc =
read(
fd, buffer, bytes_to_read);
196 if (rc != bytes_to_read)
199 pg_fatal(
"could not read file \"%s\": %m", pathname);
201 pg_fatal(
"could not read file \"%s\": read %lld of %lld",
203 (
long long int) (statbuf.
st_size + rc - bytes_left),
204 (
long long int) statbuf.
st_size);
208 inc_state, buffer, rc, bytes_left == 0);
245 int manifest_version)
248 if (manifest_version == 1)
249 pg_fatal(
"backup manifest version 1 does not support incremental backup");
257 uint64 manifest_system_identifier)
262 manifest->system_identifier = manifest_system_identifier;
270 char *pathname,
size_t size,
272 int checksum_length,
uint8 *checksum_payload)
279 m = manifest_files_insert(
manifest->files, pathname, &found);
281 pg_fatal(
"duplicate path name in backup manifest: \"%s\"", pathname);
304 range->start_lsn = start_lsn;
305 range->end_lsn = end_lsn;
310 if (
manifest->first_wal_range == NULL)
#define pg_attribute_printf(f, a)
void * pg_malloc0(size_t size)
void * pg_malloc(size_t size)
static void const char * fmt
static void combinebackup_per_file_cb(JsonManifestParseContext *context, char *pathname, size_t size, pg_checksum_type checksum_type, int checksum_length, uint8 *checksum_payload)
#define ESTIMATED_BYTES_PER_MANIFEST_LINE
static void pg_attribute_noreturn()
static void report_manifest_error(JsonManifestParseContext *context, const char *fmt,...) pg_attribute_printf(2
static void combinebackup_version_cb(JsonManifestParseContext *context, int manifest_version)
manifest_data ** load_backup_manifests(int n_backups, char **backup_directories)
static void combinebackup_per_wal_range_cb(JsonManifestParseContext *context, TimeLineID tli, XLogRecPtr start_lsn, XLogRecPtr end_lsn)
manifest_data * load_backup_manifest(char *backup_directory)
static void combinebackup_system_identifier_cb(JsonManifestParseContext *context, uint64 manifest_system_identifier)
void pg_log_generic_v(enum pg_log_level level, enum pg_log_part part, const char *pg_restrict fmt, va_list ap)
void pfree(void *pointer)
void json_parse_manifest_incremental_chunk(JsonManifestParseIncrementalState *incstate, char *chunk, int size, bool is_last)
JsonManifestParseIncrementalState * json_parse_manifest_incremental_init(JsonManifestParseContext *context)
void json_parse_manifest(JsonManifestParseContext *context, char *buffer, size_t size)
void json_parse_manifest_incremental_shutdown(JsonManifestParseIncrementalState *incstate)
#define pg_log_warning(...)
static int fd(const char *x, int i)
static struct cvec * range(struct vars *v, chr a, chr b, int cases)
static pg_noinline void Size size
manifest_files_hash * files
pg_checksum_type checksum_type