Skip to content

Commit ad932d8

Browse files
authored
[PGPRO-6037] fix catchup timeline history checking (#462)
* [PGPRO-6037] fix catchup timeline history checking
1 parent 64ff0bb commit ad932d8

File tree

4 files changed

+46
-11
lines changed

4 files changed

+46
-11
lines changed

Diff for: src/catchup.c

+14-5
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ catchup_preflight_checks(PGNodeInfo *source_node_info, PGconn *source_conn,
203203

204204
/* fill dest_redo.lsn and dest_redo.tli */
205205
get_redo(dest_pgdata, FIO_LOCAL_HOST, &dest_redo);
206+
elog(VERBOSE, "source.tli = %X, dest_redo.lsn = %X/%X, dest_redo.tli = %X",
207+
current.tli, (uint32) (dest_redo.lsn >> 32), (uint32) dest_redo.lsn, dest_redo.tli);
206208

207209
if (current.tli != 1)
208210
{
@@ -285,11 +287,12 @@ catchup_check_tablespaces_existance_in_tbsmapping(PGconn *conn)
285287
static parray*
286288
catchup_get_tli_history(ConnectionOptions *conn_opt, TimeLineID tli)
287289
{
288-
PGresult *res;
289-
PGconn *conn;
290-
char *history;
291-
char query[128];
292-
parray *result = NULL;
290+
PGresult *res;
291+
PGconn *conn;
292+
char *history;
293+
char query[128];
294+
parray *result = NULL;
295+
TimeLineHistoryEntry *entry = NULL;
293296

294297
snprintf(query, sizeof(query), "TIMELINE_HISTORY %u", tli);
295298

@@ -336,6 +339,12 @@ catchup_get_tli_history(ConnectionOptions *conn_opt, TimeLineID tli)
336339
pg_free(history);
337340
PQclear(res);
338341

342+
/* append last timeline entry (as read_timeline_history() do) */
343+
entry = pgut_new(TimeLineHistoryEntry);
344+
entry->tli = tli;
345+
entry->end = InvalidXLogRecPtr;
346+
parray_insert(result, 0, entry);
347+
339348
return result;
340349
}
341350

Diff for: src/restore.c

+4
Original file line numberDiff line numberDiff line change
@@ -1821,11 +1821,15 @@ satisfy_timeline(const parray *timelines, TimeLineID tli, XLogRecPtr lsn)
18211821
{
18221822
int i;
18231823

1824+
elog(VERBOSE, "satisfy_timeline() checking: tli = %X, lsn = %X/%X",
1825+
tli, (uint32) (lsn >> 32), (uint32) lsn);
18241826
for (i = 0; i < parray_num(timelines); i++)
18251827
{
18261828
TimeLineHistoryEntry *timeline;
18271829

18281830
timeline = (TimeLineHistoryEntry *) parray_get(timelines, i);
1831+
elog(VERBOSE, "satisfy_timeline() check %i entry: timeline->tli = %X, timeline->end = %X/%X",
1832+
i, timeline->tli, (uint32) (timeline->end >> 32), (uint32) timeline->end);
18291833
if (tli == timeline->tli &&
18301834
(XLogRecPtrIsInvalid(timeline->end) ||
18311835
lsn <= timeline->end))

Diff for: src/stream.c

+2
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,8 @@ parse_tli_history_buffer(char *history, TimeLineID tli)
615615
if (!result)
616616
result = parray_new();
617617
parray_append(result, entry);
618+
elog(VERBOSE, "parse_tli_history_buffer() found entry: tli = %X, end = %X/%X",
619+
tli, switchpoint_hi, switchpoint_lo);
618620

619621
/* we ignore the remainder of each line */
620622
}

Diff for: tests/catchup.py

+26-6
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def test_tli_delta_catchup(self):
292292
src_pg.safe_psql("postgres", "CREATE TABLE ultimate_question AS SELECT 42 AS answer")
293293
src_query_result = src_pg.safe_psql("postgres", "SELECT * FROM ultimate_question")
294294

295-
# do catchup
295+
# do catchup (src_tli = 2, dst_tli = 1)
296296
self.catchup_node(
297297
backup_mode = 'DELTA',
298298
source_pgdata = src_pg.data_dir,
@@ -310,15 +310,25 @@ def test_tli_delta_catchup(self):
310310
dst_options = {}
311311
dst_options['port'] = str(dst_pg.port)
312312
self.set_auto_conf(dst_pg, dst_options)
313-
dst_pg.slow_start()
313+
self.set_replica(master = src_pg, replica = dst_pg)
314+
dst_pg.slow_start(replica = True)
314315

315316
# 2nd check: run verification query
316317
dst_query_result = dst_pg.safe_psql("postgres", "SELECT * FROM ultimate_question")
317318
self.assertEqual(src_query_result, dst_query_result, 'Different answer from copy')
318319

320+
dst_pg.stop()
321+
322+
# do catchup (src_tli = 2, dst_tli = 2)
323+
self.catchup_node(
324+
backup_mode = 'DELTA',
325+
source_pgdata = src_pg.data_dir,
326+
destination_node = dst_pg,
327+
options = ['-d', 'postgres', '-p', str(src_pg.port), '--stream']
328+
)
329+
319330
# Cleanup
320331
src_pg.stop()
321-
dst_pg.stop()
322332
self.del_test_dir(module_name, self.fname)
323333

324334
def test_tli_ptrack_catchup(self):
@@ -365,7 +375,7 @@ def test_tli_ptrack_catchup(self):
365375
src_pg.safe_psql("postgres", "CREATE TABLE ultimate_question AS SELECT 42 AS answer")
366376
src_query_result = src_pg.safe_psql("postgres", "SELECT * FROM ultimate_question")
367377

368-
# do catchup
378+
# do catchup (src_tli = 2, dst_tli = 1)
369379
self.catchup_node(
370380
backup_mode = 'PTRACK',
371381
source_pgdata = src_pg.data_dir,
@@ -383,15 +393,25 @@ def test_tli_ptrack_catchup(self):
383393
dst_options = {}
384394
dst_options['port'] = str(dst_pg.port)
385395
self.set_auto_conf(dst_pg, dst_options)
386-
dst_pg.slow_start()
396+
self.set_replica(master = src_pg, replica = dst_pg)
397+
dst_pg.slow_start(replica = True)
387398

388399
# 2nd check: run verification query
389400
dst_query_result = dst_pg.safe_psql("postgres", "SELECT * FROM ultimate_question")
390401
self.assertEqual(src_query_result, dst_query_result, 'Different answer from copy')
391402

403+
dst_pg.stop()
404+
405+
# do catchup (src_tli = 2, dst_tli = 2)
406+
self.catchup_node(
407+
backup_mode = 'PTRACK',
408+
source_pgdata = src_pg.data_dir,
409+
destination_node = dst_pg,
410+
options = ['-d', 'postgres', '-p', str(src_pg.port), '--stream']
411+
)
412+
392413
# Cleanup
393414
src_pg.stop()
394-
dst_pg.stop()
395415
self.del_test_dir(module_name, self.fname)
396416

397417
#########################################

0 commit comments

Comments
 (0)