diff options
| author | Pavan Deolasee | 2016-02-04 13:33:34 +0000 |
|---|---|---|
| committer | Pavan Deolasee | 2016-10-18 09:48:14 +0000 |
| commit | 076dae8ff2a956ecffb1588c9735a92bc0bca09c (patch) | |
| tree | c920bb2295b7939b828a3e538d494364b3159828 /src/gtm | |
| parent | 83bcfb83b82ff1112611b43b5f8ccf771377bcab (diff) | |
If we don't find GTM control file on startup, look for the temporary control
file and use that.
While updating the control file, GTM first writes updated content to a temp
file, then deletes the old file and renames the temp to the control file. But
in a rare situation, its possible that GTM may exit before renaming the temp
file. In such cases, we should use the temp file after renaming it to the
orignal file.
More improvements in this area are necessary.
P.S. This commit gets distinction to be the first commit, pushed from 41000
feet in the air ;-)
Diffstat (limited to 'src/gtm')
| -rw-r--r-- | src/gtm/main/main.c | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/src/gtm/main/main.c b/src/gtm/main/main.c index d122591f32..123350029e 100644 --- a/src/gtm/main/main.c +++ b/src/gtm/main/main.c @@ -59,7 +59,6 @@ extern char *optarg; #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" @@ -658,6 +657,47 @@ main(int argc, char *argv[]) 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) |
