mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-25 16:16:29 +00:00
Fix history file parsing
Also add additional debugging output.
This commit is contained in:
58
dbutils.c
58
dbutils.c
@@ -1521,11 +1521,13 @@ get_timeline_history(PGconn *repl_conn, TimeLineID tli)
|
|||||||
PQExpBufferData query;
|
PQExpBufferData query;
|
||||||
PGresult *res = NULL;
|
PGresult *res = NULL;
|
||||||
|
|
||||||
int nfields;
|
PQExpBufferData result;
|
||||||
TimeLineID file_tli;
|
char *resptr;
|
||||||
|
|
||||||
|
TimeLineHistoryEntry *history;
|
||||||
|
TimeLineID file_tli = UNKNOWN_TIMELINE_ID;
|
||||||
uint32 switchpoint_hi;
|
uint32 switchpoint_hi;
|
||||||
uint32 switchpoint_lo;
|
uint32 switchpoint_lo;
|
||||||
TimeLineHistoryEntry *history;
|
|
||||||
|
|
||||||
initPQExpBuffer(&query);
|
initPQExpBuffer(&query);
|
||||||
|
|
||||||
@@ -1555,19 +1557,51 @@ get_timeline_history(PGconn *repl_conn, TimeLineID tli)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
nfields = sscanf(PQgetvalue(res, 0, 1),
|
initPQExpBuffer(&result);
|
||||||
"%u\t%X/%X",
|
appendPQExpBufferStr(&result, PQgetvalue(res, 0, 1));
|
||||||
&file_tli, &switchpoint_hi, &switchpoint_lo);
|
PQclear(res);
|
||||||
|
|
||||||
if (nfields != 3)
|
resptr = result.data;
|
||||||
|
|
||||||
|
while (*resptr)
|
||||||
{
|
{
|
||||||
log_error(_("unable to parse timeline history file content"));
|
char buf[MAXLEN];
|
||||||
log_detail(_("content is: \"%s\""), PQgetvalue(res, 0, 1));
|
char *bufptr = buf;
|
||||||
PQclear(res);
|
|
||||||
return NULL;
|
if (*resptr != '\n')
|
||||||
|
{
|
||||||
|
int len = 0;
|
||||||
|
|
||||||
|
memset(buf, 0, MAXLEN);
|
||||||
|
|
||||||
|
while (*resptr && *resptr != '\n' && len < MAXLEN)
|
||||||
|
{
|
||||||
|
*bufptr++ = *resptr++;
|
||||||
|
len++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buf[0])
|
||||||
|
{
|
||||||
|
int nfields = sscanf(buf,
|
||||||
|
"%u\t%X/%X",
|
||||||
|
&file_tli, &switchpoint_hi, &switchpoint_lo);
|
||||||
|
if (nfields == 3 && file_tli == tli - 1)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*resptr)
|
||||||
|
resptr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
PQclear(res);
|
termPQExpBuffer(&result);
|
||||||
|
|
||||||
|
if (file_tli == UNKNOWN_TIMELINE_ID || file_tli != tli - 1)
|
||||||
|
{
|
||||||
|
log_error(_("timeline %i not found in timeline history file content"), tli);
|
||||||
|
log_detail(_("content is: \"%s\""), result.data);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
history = (TimeLineHistoryEntry *) palloc(sizeof(TimeLineHistoryEntry));
|
history = (TimeLineHistoryEntry *) palloc(sizeof(TimeLineHistoryEntry));
|
||||||
history->tli = file_tli;
|
history->tli = file_tli;
|
||||||
|
|||||||
@@ -3380,6 +3380,12 @@ check_node_can_attach(TimeLineID local_tli, XLogRecPtr local_xlogpos, PGconn *fo
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log_debug("local tli: %i; local_xlogpos: %X/%X; follow_target_history->tli: %i; follow_target_history->end: %X/%X",
|
||||||
|
local_tli,
|
||||||
|
format_lsn(local_xlogpos),
|
||||||
|
follow_target_history->tli,
|
||||||
|
format_lsn(follow_target_history->end));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Local node has proceeded beyond the follow target's fork, so we
|
* Local node has proceeded beyond the follow target's fork, so we
|
||||||
* definitely can't attach.
|
* definitely can't attach.
|
||||||
@@ -3432,6 +3438,10 @@ check_node_can_attach(TimeLineID local_tli, XLogRecPtr local_xlogpos, PGconn *fo
|
|||||||
}
|
}
|
||||||
|
|
||||||
PQfinish(follow_target_repl_conn);
|
PQfinish(follow_target_repl_conn);
|
||||||
|
|
||||||
|
if (follow_target_history)
|
||||||
|
pfree(follow_target_history);
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user