Remove dependency to StringInfo in xlogbackup.{c.h}
authorMichael Paquier
Tue, 27 Sep 2022 00:15:07 +0000 (09:15 +0900)
committerMichael Paquier
Tue, 27 Sep 2022 00:15:07 +0000 (09:15 +0900)
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/[email protected]

src/backend/access/transam/xlog.c
src/backend/access/transam/xlogbackup.c
src/backend/access/transam/xlogfuncs.c
src/backend/backup/basebackup.c
src/include/access/xlogbackup.h

index 7606ee128a98b019be634fc3b17c25f88e141367..1dd6df0fe1514b8614ab0744f3d41d528ac18cae 100644 (file)
@@ -8711,7 +8711,7 @@ do_pg_backup_stop(BackupState *state, bool waitforarchive)
    }
    else
    {
-       StringInfo  history_file;
+       char       *history_file;
 
        /*
         * Write the backup-end xlog record
@@ -8751,8 +8751,7 @@ do_pg_backup_stop(BackupState *state, bool waitforarchive)
 
        /* Build and save the contents of the backup history file */
        history_file = build_backup_content(state, true);
-       fprintf(fp, "%s", history_file->data);
-       pfree(history_file->data);
+       fprintf(fp, "%s", history_file);
        pfree(history_file);
 
        if (fflush(fp) || ferror(fp) || FreeFile(fp))
index c01c1f90102388483bcd6381dcfe245e24cbf046..90b5273b0281aea21a1009b2c6b4cdb1ff53e5a7 100644 (file)
  * When ishistoryfile is true, it creates the contents for a backup history
  * file, otherwise it creates contents for a backup_label file.
  *
- * Returns the result generated as a palloc'd StringInfo.
+ * Returns the result generated as a palloc'd string.
  */
-StringInfo
+char *
 build_backup_content(BackupState *state, bool ishistoryfile)
 {
    char        startstrbuf[128];
    char        startxlogfile[MAXFNAMELEN]; /* backup start WAL file */
    XLogSegNo   startsegno;
    StringInfo  result = makeStringInfo();
+   char       *data;
 
    Assert(state != NULL);
 
@@ -76,5 +77,8 @@ build_backup_content(BackupState *state, bool ishistoryfile)
        appendStringInfo(result, "STOP TIMELINE: %u\n", state->stoptli);
    }
 
-   return result;
+   data = result->data;
+   pfree(result);
+
+   return data;
 }
index f724b18733ac06f84c9ca711a1ae172e9dea1c56..a801a94fe852c52e1586a81419241afaee95b8a9 100644 (file)
@@ -130,7 +130,7 @@ pg_backup_stop(PG_FUNCTION_ARGS)
    Datum       values[PG_BACKUP_STOP_V2_COLS] = {0};
    bool        nulls[PG_BACKUP_STOP_V2_COLS] = {0};
    bool        waitforarchive = PG_GETARG_BOOL(0);
-   StringInfo  backup_label;
+   char       *backup_label;
    SessionBackupState status = get_backup_status();
 
    /* Initialize attributes information in the tuple descriptor */
@@ -153,7 +153,7 @@ pg_backup_stop(PG_FUNCTION_ARGS)
    backup_label = build_backup_content(backup_state, false);
 
    values[0] = LSNGetDatum(backup_state->stoppoint);
-   values[1] = CStringGetTextDatum(backup_label->data);
+   values[1] = CStringGetTextDatum(backup_label);
    values[2] = CStringGetTextDatum(tablespace_map->data);
 
    /* Deallocate backup-related variables */
@@ -162,7 +162,6 @@ pg_backup_stop(PG_FUNCTION_ARGS)
    pfree(tablespace_map->data);
    pfree(tablespace_map);
    tablespace_map = NULL;
-   pfree(backup_label->data);
    pfree(backup_label);
 
    /* Returns the record as Datum */
index 495bbb506a95d1c5e18f5c87ee286d5eea077775..411cac9be3f84c3aee1a024b3ea4d4702a9a07d1 100644 (file)
@@ -317,15 +317,14 @@ perform_base_backup(basebackup_options *opt, bbsink *sink)
            {
                struct stat statbuf;
                bool        sendtblspclinks = true;
-               StringInfo  backup_label;
+               char       *backup_label;
 
                bbsink_begin_archive(sink, "base.tar");
 
                /* In the main tar, include the backup_label first... */
                backup_label = build_backup_content(backup_state, false);
                sendFileWithContent(sink, BACKUP_LABEL_FILE,
-                                   backup_label->data, &manifest);
-               pfree(backup_label->data);
+                                   backup_label, &manifest);
                pfree(backup_label);
 
                /* Then the tablespace_map file, if required... */
index cb15b8b80a364fd7f27f42302b3b6a898443b961..8ec3d88b0a882deb1692da877a95621910b361dc 100644 (file)
@@ -15,7 +15,6 @@
 #define XLOG_BACKUP_H
 
 #include "access/xlogdefs.h"
-#include "lib/stringinfo.h"
 #include "pgtime.h"
 
 /* Structure to hold backup state. */
@@ -36,7 +35,7 @@ typedef struct BackupState
    pg_time_t   stoptime;       /* backup stop time */
 } BackupState;
 
-extern StringInfo build_backup_content(BackupState *state,
-                                      bool ishistoryfile);
+extern char *build_backup_content(BackupState *state,
+                                 bool ishistoryfile);
 
 #endif                         /* XLOG_BACKUP_H */