Skip to content

Commit e1e6f8f

Browse files
committed
Remove dependency to StringInfo in xlogbackup.{c.h}
This was used as the returned result type of the generated contents for the backup_label and backup history files. This is replaced by a simple string, reducing the cleanup burden of all the callers of build_backup_content(). Reviewed-by: Bharath Rupireddy Discussion: https://postgr.es/m/YzERvNPaZivHEKZJ@paquier.xyz
1 parent 31d2c47 commit e1e6f8f

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

src/backend/access/transam/xlog.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8711,7 +8711,7 @@ do_pg_backup_stop(BackupState *state, bool waitforarchive)
87118711
}
87128712
else
87138713
{
8714-
StringInfo history_file;
8714+
char *history_file;
87158715

87168716
/*
87178717
* Write the backup-end xlog record
@@ -8751,8 +8751,7 @@ do_pg_backup_stop(BackupState *state, bool waitforarchive)
87518751

87528752
/* Build and save the contents of the backup history file */
87538753
history_file = build_backup_content(state, true);
8754-
fprintf(fp, "%s", history_file->data);
8755-
pfree(history_file->data);
8754+
fprintf(fp, "%s", history_file);
87568755
pfree(history_file);
87578756

87588757
if (fflush(fp) || ferror(fp) || FreeFile(fp))

src/backend/access/transam/xlogbackup.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@
2323
* When ishistoryfile is true, it creates the contents for a backup history
2424
* file, otherwise it creates contents for a backup_label file.
2525
*
26-
* Returns the result generated as a palloc'd StringInfo.
26+
* Returns the result generated as a palloc'd string.
2727
*/
28-
StringInfo
28+
char *
2929
build_backup_content(BackupState *state, bool ishistoryfile)
3030
{
3131
char startstrbuf[128];
3232
char startxlogfile[MAXFNAMELEN]; /* backup start WAL file */
3333
XLogSegNo startsegno;
3434
StringInfo result = makeStringInfo();
35+
char *data;
3536

3637
Assert(state != NULL);
3738

@@ -76,5 +77,8 @@ build_backup_content(BackupState *state, bool ishistoryfile)
7677
appendStringInfo(result, "STOP TIMELINE: %u\n", state->stoptli);
7778
}
7879

79-
return result;
80+
data = result->data;
81+
pfree(result);
82+
83+
return data;
8084
}

src/backend/access/transam/xlogfuncs.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pg_backup_stop(PG_FUNCTION_ARGS)
130130
Datum values[PG_BACKUP_STOP_V2_COLS] = {0};
131131
bool nulls[PG_BACKUP_STOP_V2_COLS] = {0};
132132
bool waitforarchive = PG_GETARG_BOOL(0);
133-
StringInfo backup_label;
133+
char *backup_label;
134134
SessionBackupState status = get_backup_status();
135135

136136
/* Initialize attributes information in the tuple descriptor */
@@ -153,7 +153,7 @@ pg_backup_stop(PG_FUNCTION_ARGS)
153153
backup_label = build_backup_content(backup_state, false);
154154

155155
values[0] = LSNGetDatum(backup_state->stoppoint);
156-
values[1] = CStringGetTextDatum(backup_label->data);
156+
values[1] = CStringGetTextDatum(backup_label);
157157
values[2] = CStringGetTextDatum(tablespace_map->data);
158158

159159
/* Deallocate backup-related variables */
@@ -162,7 +162,6 @@ pg_backup_stop(PG_FUNCTION_ARGS)
162162
pfree(tablespace_map->data);
163163
pfree(tablespace_map);
164164
tablespace_map = NULL;
165-
pfree(backup_label->data);
166165
pfree(backup_label);
167166

168167
/* Returns the record as Datum */

src/backend/backup/basebackup.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,15 +317,14 @@ perform_base_backup(basebackup_options *opt, bbsink *sink)
317317
{
318318
struct stat statbuf;
319319
bool sendtblspclinks = true;
320-
StringInfo backup_label;
320+
char *backup_label;
321321

322322
bbsink_begin_archive(sink, "base.tar");
323323

324324
/* In the main tar, include the backup_label first... */
325325
backup_label = build_backup_content(backup_state, false);
326326
sendFileWithContent(sink, BACKUP_LABEL_FILE,
327-
backup_label->data, &manifest);
328-
pfree(backup_label->data);
327+
backup_label, &manifest);
329328
pfree(backup_label);
330329

331330
/* Then the tablespace_map file, if required... */

src/include/access/xlogbackup.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#define XLOG_BACKUP_H
1616

1717
#include "access/xlogdefs.h"
18-
#include "lib/stringinfo.h"
1918
#include "pgtime.h"
2019

2120
/* Structure to hold backup state. */
@@ -36,7 +35,7 @@ typedef struct BackupState
3635
pg_time_t stoptime; /* backup stop time */
3736
} BackupState;
3837

39-
extern StringInfo build_backup_content(BackupState *state,
40-
bool ishistoryfile);
38+
extern char *build_backup_content(BackupState *state,
39+
bool ishistoryfile);
4140

4241
#endif /* XLOG_BACKUP_H */

0 commit comments

Comments
 (0)