#include "miscadmin.h"
#include "postgres.h"
+#include "gtm/gtm.h"
/*
* these values are passed in by makefile defines
static void check_input(char *path);
static void set_null_conf(void);
static void setup_config(void);
+static void setup_control(void);
static void trapsig(int signum);
static void check_ok(void);
static void usage(const char *progname);
check_ok();
}
+/*
+ * set up all the control file
+ */
+static void
+setup_control(void)
+{
+ char path[MAXPGPATH];
+ char *controlline = NULL;
+
+ if (!is_gtm)
+ return;
+
+ fputs(_("creating control file ... "), stdout);
+ fflush(stdout);
+
+ snprintf(path, sizeof(path), "%s/gtm.control", pg_data);
+ writefile(path, &controlline);
+ chmod(path, S_IRUSR | S_IWUSR);
+
+ check_ok();
+}
/*
* signal handler in case we are interrupted.
/* Now create all the text config files */
setup_config();
+ /* Now create the control file */
+ setup_control();
+
/* Get directory specification used to start this executable */
strcpy(bin_dir, argv[0]);
get_parent_directory(bin_dir);
#define GTM_MAX_PATH 1024
#define GTM_DEFAULT_HOSTNAME "*"
#define GTM_DEFAULT_PORT 6666
-#define GTM_CONTROL_FILE "gtm.control"
#define GTM_PID_FILE "gtm.pid"
#define GTM_LOG_FILE "gtm.log"
GTM_MutexLockAcquire(&control_lock);
ctlf = fopen(GTMControlFile, "r");
+
+ /*
+ * When the GTMControlFile file is updated, we first write the updated
+ * contents to a GTMControlFileTmp, delete the original GTMControlFile
+ * and then rename the GTMControlFileTmp file to GTMControlFile
+ *
+ * In a rare situation, the GTMControlFile may get deleted, but the
+ * GTMControlFileTmp may not get renamed. If we don't find the
+ * GTMControlFile file, then look for the GTMControlFileTmp file. If
+ * none exists, then its an error condition and we must not start.
+ */
+ if (ctlf == NULL)
+ {
+ switch (errno)
+ {
+ case ENOENT:
+ elog(WARNING, "%s not found, now looking for %s",
+ GTMControlFile, GTMControlFileTmp);
+ break;
+ default:
+ elog(ERROR, "Could not open %s, errno %d - aborting GTM start",
+ GTMControlFile, errno);
+ }
+ ctlf = fopen(GTMControlFileTmp, "r");
+ if (ctlf == NULL)
+ elog(ERROR, "Could not open %s, errno %d - aborting GTM start",
+ GTMControlFileTmp, errno);
+
+ /*
+ * Ok, so the GTMControlFileTmp exists. Just rename it to the
+ * GTMControlFile and open again with the new name
+ */
+ elog(WARNING, "Renaming %s to %s", GTMControlFileTmp,
+ GTMControlFile);
+ fclose(ctlf);
+ rename(GTMControlFileTmp, GTMControlFile);
+ ctlf = fopen(GTMControlFile, "r");
+ if (ctlf == NULL)
+ elog(ERROR, "Could not open %s, errno %d - aborting GTM start",
+ GTMControlFile, errno);
+ }
GTM_RestoreTxnInfo(ctlf, next_gxid);
GTM_RestoreSeqInfo(ctlf);
if (ctlf)
GTM_ThreadInfo * GTM_GetThreadInfo(GTM_ThreadID thrid);
#ifdef XCP
extern void SaveControlInfo(void);
-#define CONTROL_INTERVAL 1000
+#define CONTROL_INTERVAL 50000
#endif
/*
(!GTM_CLIENT_ID_LT(a, b) && !GTM_CLIENT_ID_EQ(a, b))
#define GTM_CLIENT_ID_NEXT(a) \
((((a) + 1) == UINT32_MAX) ? 1 : ((a) + 1))
+
+#define GTM_CONTROL_FILE "gtm.control"
+
#endif