Fix couple of regressions introduced in the previous commit.
authorPavan Deolasee <[email protected]>
Mon, 15 Oct 2018 08:19:22 +0000 (13:49 +0530)
committerPavan Deolasee <[email protected]>
Mon, 15 Oct 2018 08:21:26 +0000 (13:51 +0530)
The format of the GTM control file setup during `initgtm` was broken. Also, we
failed to consider the case of GTM standby initialising which might pass a NULL
File handle.

src/bin/initgtm/initgtm.c
src/gtm/main/main.c

index b14b7dd5397b55287c4d6eb6bf31be90fab03011..9b06b363d8cbf53c7cbd0c3daf5d74fada2d0c17 100644 (file)
@@ -556,20 +556,22 @@ static void
 setup_control(void)
 {
        char            path[MAXPGPATH];
-       char            controlline_bufs[3][MAXNAMLEN];
-       char        *controllines[4];
+       char            controlline_bufs[4][MAXNAMLEN];
+       char        *controllines[5];
 
        if (!is_gtm)
                return;
 
-       snprintf(controlline_bufs[0], MAXNAMLEN, "version: %u", GTM_CONTROL_VERSION);
-       snprintf(controlline_bufs[1], MAXNAMLEN, "next_xid: %u", InitialGXIDValue_Default);
-       snprintf(controlline_bufs[2], MAXNAMLEN, "global_xmin: %u", InitialGXIDValue_Default);
+       snprintf(controlline_bufs[0], MAXNAMLEN, "version: %u\n", GTM_CONTROL_VERSION);
+       snprintf(controlline_bufs[1], MAXNAMLEN, "next_xid: %u\n", InitialGXIDValue_Default);
+       snprintf(controlline_bufs[2], MAXNAMLEN, "global_xmin: %u\n", InitialGXIDValue_Default);
+       snprintf(controlline_bufs[3], MAXNAMLEN, "snap_id: %u\n", 1);
 
        controllines[0] = strdup(controlline_bufs[0]);
        controllines[1] = strdup(controlline_bufs[1]);
        controllines[2] = strdup(controlline_bufs[2]);
-       controllines[3] = NULL;
+       controllines[3] = strdup(controlline_bufs[3]);
+       controllines[4] = NULL;
 
        fputs(_("creating control file ... "), stdout);
        fflush(stdout);
index 7f33360c970df8173b39cce9efcbf5cbd9616470..9b9d2909d790bce70bd905cb0ba53f9b4518d20a 100644 (file)
@@ -2362,7 +2362,11 @@ GTM_RestoreTxnInfo(FILE *ctlf, GlobalTransactionId next_gxid,
                                                 GTMControlFile)));
                }
        }
-       else
+       /*
+        * GTM control file handle is not passed during GTM standby initialization
+        * mode. That's not an ERROR case.
+        */
+       else if (!Recovery_IsStandby())
        {
                ereport(FATAL,
                                (EINVAL,