PostgreSQL Source Code: src/bin/pg_rewind/timeline.c Source File (original) (raw)
1
2
3
4
5
6
7
8
9
11
14
15
16
17
18
19
20
21
22
23
24
25
26
29{
30 char *fline;
33 int nlines = 0;
36 char *bufptr;
37 bool lastline = false;
38
39
40
41
43 bufptr = buffer;
44 while (!lastline)
45 {
46 char *ptr;
48 uint32 switchpoint_hi;
49 uint32 switchpoint_lo;
50 int nfields;
51
52 fline = bufptr;
53 while (*bufptr && *bufptr != '\n')
54 bufptr++;
55 if (!(*bufptr))
56 lastline = true;
57 else
58 *bufptr++ = '\0';
59
60
61 for (ptr = fline; *ptr; ptr++)
62 {
63 if (!isspace((unsigned char) *ptr))
64 break;
65 }
66 if (*ptr == '\0' || *ptr == '#')
67 continue;
68
69 nfields = sscanf(fline, "%u\t%X/%X", &tli, &switchpoint_hi, &switchpoint_lo);
70
71 if (nfields < 1)
72 {
73
74 pg_log_error("syntax error in history file: %s", fline);
76 exit(1);
77 }
78 if (nfields != 3)
79 {
80 pg_log_error("syntax error in history file: %s", fline);
82 exit(1);
83 }
84 if (entries && tli <= lasttli)
85 {
86 pg_log_error("invalid data in history file: %s", fline);
88 exit(1);
89 }
90
91 lasttli = tli;
92
93 nlines++;
95
96 entry = &entries[nlines - 1];
97 entry->tli = tli;
98 entry->begin = prevend;
99 entry->end = ((uint64) (switchpoint_hi)) << 32 | (uint64) switchpoint_lo;
100 prevend = entry->end;
101
102
103 }
104
105 if (entries && targetTLI <= lasttli)
106 {
107 pg_log_error("invalid data in history file");
108 pg_log_error_detail("Timeline IDs must be less than child timeline's ID.");
109 exit(1);
110 }
111
112
113
114
115
116 nlines++;
117 if (entries)
119 else
121
122 entry = &entries[nlines - 1];
123 entry->tli = targetTLI;
124 entry->begin = prevend;
126
127 *nentries = nlines;
128 return entries;
129}
TimeLineHistoryEntry * rewind_parseTimeLineHistory(char *buffer, TimeLineID targetTLI, int *nentries)
void * pg_malloc(size_t size)
void * pg_realloc(void *ptr, size_t size)
#define pg_log_error(...)
#define pg_log_error_detail(...)
#define InvalidXLogRecPtr