Rename exposed identifiers to say "backup manifest".

Function names declared "extern" now use BackupManifest in the name
rather than just Manifest, and data types use backup_manifest
rather than just manifest.

Per note from Michael Paquier.

Discussion: http://postgr.es/m/20200418125713.GG350229@paquier.xyz
This commit is contained in:
Robert Haas 2020-04-23 08:44:06 -04:00
parent 299298bc87
commit 3989dbdf12
3 changed files with 65 additions and 59 deletions

View File

@ -20,6 +20,8 @@
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/json.h" #include "utils/json.h"
static void AppendStringToManifest(backup_manifest_info *manifest, char *s);
/* /*
* Does the user want a backup manifest? * Does the user want a backup manifest?
* *
@ -28,7 +30,7 @@
* want a manifest, we set manifest->buffile to NULL. * want a manifest, we set manifest->buffile to NULL.
*/ */
static inline bool static inline bool
IsManifestEnabled(manifest_info *manifest) IsManifestEnabled(backup_manifest_info *manifest)
{ {
return (manifest->buffile != NULL); return (manifest->buffile != NULL);
} }
@ -51,7 +53,8 @@ IsManifestEnabled(manifest_info *manifest)
* SendBackupManifest. * SendBackupManifest.
*/ */
void void
InitializeManifest(manifest_info *manifest, manifest_option want_manifest, InitializeBackupManifest(backup_manifest_info *manifest,
backup_manifest_option want_manifest,
pg_checksum_type manifest_checksum_type) pg_checksum_type manifest_checksum_type)
{ {
if (want_manifest == MANIFEST_OPTION_NO) if (want_manifest == MANIFEST_OPTION_NO)
@ -71,31 +74,11 @@ InitializeManifest(manifest_info *manifest, manifest_option want_manifest,
"\"Files\": ["); "\"Files\": [");
} }
/*
* Append a cstring to the manifest.
*/
void
AppendStringToManifest(manifest_info *manifest, char *s)
{
int len = strlen(s);
size_t written;
Assert(manifest != NULL);
if (manifest->still_checksumming)
pg_sha256_update(&manifest->manifest_ctx, (uint8 *) s, len);
written = BufFileWrite(manifest->buffile, s, len);
if (written != len)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not write to temporary file: %m")));
manifest->manifest_size += len;
}
/* /*
* Add an entry to the backup manifest for a file. * Add an entry to the backup manifest for a file.
*/ */
void void
AddFileToManifest(manifest_info *manifest, const char *spcoid, AddFileToBackupManifest(backup_manifest_info *manifest, const char *spcoid,
const char *pathname, size_t size, pg_time_t mtime, const char *pathname, size_t size, pg_time_t mtime,
pg_checksum_context * checksum_ctx) pg_checksum_context * checksum_ctx)
{ {
@ -203,8 +186,9 @@ AddFileToManifest(manifest_info *manifest, const char *spcoid,
* this backup to the manifest. * this backup to the manifest.
*/ */
void void
AddWALInfoToManifest(manifest_info *manifest, XLogRecPtr startptr, AddWALInfoToBackupManifest(backup_manifest_info *manifest, XLogRecPtr startptr,
TimeLineID starttli, XLogRecPtr endptr, TimeLineID endtli) TimeLineID starttli, XLogRecPtr endptr,
TimeLineID endtli)
{ {
List *timelines; List *timelines;
ListCell *lc; ListCell *lc;
@ -299,7 +283,7 @@ AddWALInfoToManifest(manifest_info *manifest, XLogRecPtr startptr,
* Finalize the backup manifest, and send it to the client. * Finalize the backup manifest, and send it to the client.
*/ */
void void
SendBackupManifest(manifest_info *manifest) SendBackupManifest(backup_manifest_info *manifest)
{ {
StringInfoData protobuf; StringInfoData protobuf;
uint8 checksumbuf[PG_SHA256_DIGEST_LENGTH]; uint8 checksumbuf[PG_SHA256_DIGEST_LENGTH];
@ -373,3 +357,23 @@ SendBackupManifest(manifest_info *manifest)
/* Release resources */ /* Release resources */
BufFileClose(manifest->buffile); BufFileClose(manifest->buffile);
} }
/*
* Append a cstring to the manifest.
*/
static void
AppendStringToManifest(backup_manifest_info *manifest, char *s)
{
int len = strlen(s);
size_t written;
Assert(manifest != NULL);
if (manifest->still_checksumming)
pg_sha256_update(&manifest->manifest_ctx, (uint8 *) s, len);
written = BufFileWrite(manifest->buffile, s, len);
if (written != len)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not write to temporary file: %m")));
manifest->manifest_size += len;
}

View File

@ -54,18 +54,18 @@ typedef struct
bool includewal; bool includewal;
uint32 maxrate; uint32 maxrate;
bool sendtblspcmapfile; bool sendtblspcmapfile;
manifest_option manifest; backup_manifest_option manifest;
pg_checksum_type manifest_checksum_type; pg_checksum_type manifest_checksum_type;
} basebackup_options; } basebackup_options;
static int64 sendDir(const char *path, int basepathlen, bool sizeonly, static int64 sendDir(const char *path, int basepathlen, bool sizeonly,
List *tablespaces, bool sendtblspclinks, List *tablespaces, bool sendtblspclinks,
manifest_info *manifest, const char *spcoid); backup_manifest_info *manifest, const char *spcoid);
static bool sendFile(const char *readfilename, const char *tarfilename, static bool sendFile(const char *readfilename, const char *tarfilename,
struct stat *statbuf, bool missing_ok, Oid dboid, struct stat *statbuf, bool missing_ok, Oid dboid,
manifest_info *manifest, const char *spcoid); backup_manifest_info *manifest, const char *spcoid);
static void sendFileWithContent(const char *filename, const char *content, static void sendFileWithContent(const char *filename, const char *content,
manifest_info *manifest); backup_manifest_info *manifest);
static int64 _tarWriteHeader(const char *filename, const char *linktarget, static int64 _tarWriteHeader(const char *filename, const char *linktarget,
struct stat *statbuf, bool sizeonly); struct stat *statbuf, bool sizeonly);
static int64 _tarWriteDir(const char *pathbuf, int basepathlen, struct stat *statbuf, static int64 _tarWriteDir(const char *pathbuf, int basepathlen, struct stat *statbuf,
@ -268,7 +268,7 @@ perform_base_backup(basebackup_options *opt)
TimeLineID endtli; TimeLineID endtli;
StringInfo labelfile; StringInfo labelfile;
StringInfo tblspc_map_file = NULL; StringInfo tblspc_map_file = NULL;
manifest_info manifest; backup_manifest_info manifest;
int datadirpathlen; int datadirpathlen;
List *tablespaces = NIL; List *tablespaces = NIL;
@ -298,7 +298,8 @@ perform_base_backup(basebackup_options *opt)
labelfile = makeStringInfo(); labelfile = makeStringInfo();
tblspc_map_file = makeStringInfo(); tblspc_map_file = makeStringInfo();
InitializeManifest(&manifest, opt->manifest, opt->manifest_checksum_type); InitializeBackupManifest(&manifest, opt->manifest,
opt->manifest_checksum_type);
total_checksum_failures = 0; total_checksum_failures = 0;
@ -710,7 +711,7 @@ perform_base_backup(basebackup_options *opt)
pq_putemptymessage('c'); pq_putemptymessage('c');
} }
AddWALInfoToManifest(&manifest, startptr, starttli, endptr, endtli); AddWALInfoToBackupManifest(&manifest, startptr, starttli, endptr, endtli);
SendBackupManifest(&manifest); SendBackupManifest(&manifest);
@ -1085,7 +1086,7 @@ SendXlogRecPtrResult(XLogRecPtr ptr, TimeLineID tli)
*/ */
static void static void
sendFileWithContent(const char *filename, const char *content, sendFileWithContent(const char *filename, const char *content,
manifest_info *manifest) backup_manifest_info *manifest)
{ {
struct stat statbuf; struct stat statbuf;
int pad, int pad,
@ -1129,9 +1130,8 @@ sendFileWithContent(const char *filename, const char *content,
} }
pg_checksum_update(&checksum_ctx, (uint8 *) content, len); pg_checksum_update(&checksum_ctx, (uint8 *) content, len);
AddFileToManifest(manifest, NULL, filename, len, AddFileToBackupManifest(manifest, NULL, filename, len,
(pg_time_t) statbuf.st_mtime, (pg_time_t) statbuf.st_mtime, &checksum_ctx);
&checksum_ctx);
} }
/* /*
@ -1143,7 +1143,7 @@ sendFileWithContent(const char *filename, const char *content,
*/ */
int64 int64
sendTablespace(char *path, char *spcoid, bool sizeonly, sendTablespace(char *path, char *spcoid, bool sizeonly,
manifest_info *manifest) backup_manifest_info *manifest)
{ {
int64 size; int64 size;
char pathbuf[MAXPGPATH]; char pathbuf[MAXPGPATH];
@ -1196,7 +1196,8 @@ sendTablespace(char *path, char *spcoid, bool sizeonly,
*/ */
static int64 static int64
sendDir(const char *path, int basepathlen, bool sizeonly, List *tablespaces, sendDir(const char *path, int basepathlen, bool sizeonly, List *tablespaces,
bool sendtblspclinks, manifest_info *manifest, const char *spcoid) bool sendtblspclinks, backup_manifest_info *manifest,
const char *spcoid)
{ {
DIR *dir; DIR *dir;
struct dirent *de; struct dirent *de;
@ -1558,7 +1559,7 @@ is_checksummed_file(const char *fullpath, const char *filename)
static bool static bool
sendFile(const char *readfilename, const char *tarfilename, sendFile(const char *readfilename, const char *tarfilename,
struct stat *statbuf, bool missing_ok, Oid dboid, struct stat *statbuf, bool missing_ok, Oid dboid,
manifest_info *manifest, const char *spcoid) backup_manifest_info *manifest, const char *spcoid)
{ {
FILE *fp; FILE *fp;
BlockNumber blkno = 0; BlockNumber blkno = 0;
@ -1810,7 +1811,7 @@ sendFile(const char *readfilename, const char *tarfilename,
total_checksum_failures += checksum_failures; total_checksum_failures += checksum_failures;
AddFileToManifest(manifest, spcoid, tarfilename, statbuf->st_size, AddFileToBackupManifest(manifest, spcoid, tarfilename, statbuf->st_size,
(pg_time_t) statbuf->st_mtime, &checksum_ctx); (pg_time_t) statbuf->st_mtime, &checksum_ctx);
return true; return true;

View File

@ -22,7 +22,7 @@ typedef enum manifest_option
MANIFEST_OPTION_YES, MANIFEST_OPTION_YES,
MANIFEST_OPTION_NO, MANIFEST_OPTION_NO,
MANIFEST_OPTION_FORCE_ENCODE MANIFEST_OPTION_FORCE_ENCODE
} manifest_option; } backup_manifest_option;
typedef struct manifest_info typedef struct manifest_info
{ {
@ -33,19 +33,20 @@ typedef struct manifest_info
bool force_encode; bool force_encode;
bool first_file; bool first_file;
bool still_checksumming; bool still_checksumming;
} manifest_info; } backup_manifest_info;
extern void InitializeManifest(manifest_info *manifest, extern void InitializeBackupManifest(backup_manifest_info *manifest,
manifest_option want_manifest, backup_manifest_option want_manifest,
pg_checksum_type manifest_checksum_type); pg_checksum_type manifest_checksum_type);
extern void AppendStringToManifest(manifest_info *manifest, char *s); extern void AddFileToBackupManifest(backup_manifest_info *manifest,
extern void AddFileToManifest(manifest_info *manifest, const char *spcoid, const char *spcoid,
const char *pathname, size_t size, const char *pathname, size_t size,
pg_time_t mtime, pg_time_t mtime,
pg_checksum_context * checksum_ctx); pg_checksum_context * checksum_ctx);
extern void AddWALInfoToManifest(manifest_info *manifest, XLogRecPtr startptr, extern void AddWALInfoToBackupManifest(backup_manifest_info *manifest,
XLogRecPtr startptr,
TimeLineID starttli, XLogRecPtr endptr, TimeLineID starttli, XLogRecPtr endptr,
TimeLineID endtli); TimeLineID endtli);
extern void SendBackupManifest(manifest_info *manifest); extern void SendBackupManifest(backup_manifest_info *manifest);
#endif #endif