MCPcopy Create free account
hub / github.com/apache/cloudberry / rewind_parseTimeLineHistory

Function rewind_parseTimeLineHistory

src/bin/pg_rewind/timeline.c:28–130  ·  view source on GitHub ↗

* This is copy-pasted from the backend readTimeLineHistory, modified to * return a malloc'd array and to work without backend functions. */ * Try to read a timeline's history file. * * If successful, return the list of component TLIs (the given TLI followed by * its ancestor TLIs). If we can't find the history file, assume that the * timeline has no parents, and return a list of just the sp

Source from the content-addressed store, hash-verified

26 * ID.
27 */
28TimeLineHistoryEntry *
29rewind_parseTimeLineHistory(char *buffer, TimeLineID targetTLI, int *nentries)
30{
31 char *fline;
32 TimeLineHistoryEntry *entry;
33 TimeLineHistoryEntry *entries = NULL;
34 int nlines = 0;
35 TimeLineID lasttli = 0;
36 XLogRecPtr prevend;
37 char *bufptr;
38 bool lastline = false;
39
40 /*
41 * Parse the file...
42 */
43 prevend = InvalidXLogRecPtr;
44 bufptr = buffer;
45 while (!lastline)
46 {
47 char *ptr;
48 TimeLineID tli;
49 uint32 switchpoint_hi;
50 uint32 switchpoint_lo;
51 int nfields;
52
53 fline = bufptr;
54 while (*bufptr && *bufptr != '\n')
55 bufptr++;
56 if (!(*bufptr))
57 lastline = true;
58 else
59 *bufptr++ = '\0';
60
61 /* skip leading whitespace and check for # comment */
62 for (ptr = fline; *ptr; ptr++)
63 {
64 if (!isspace((unsigned char) *ptr))
65 break;
66 }
67 if (*ptr == '\0' || *ptr == '#')
68 continue;
69
70 nfields = sscanf(fline, "%u\t%X/%X", &tli, &switchpoint_hi, &switchpoint_lo);
71
72 if (nfields < 1)
73 {
74 /* expect a numeric timeline ID as first field of line */
75 pg_log_error("syntax error in history file: %s", fline);
76 pg_log_error("Expected a numeric timeline ID.");
77 exit(1);
78 }
79 if (nfields != 3)
80 {
81 pg_log_error("syntax error in history file: %s", fline);
82 pg_log_error("Expected a write-ahead log switchpoint location.");
83 exit(1);
84 }
85 if (entries && tli <= lasttli)

Callers 1

getTimelineHistoryFunction · 0.85

Calls 2

pg_reallocFunction · 0.85
pg_mallocFunction · 0.85

Tested by

no test coverage detected