diff --git a/src/backup.c b/src/backup.c index 4ec515a1..1bcae2c0 100644 --- a/src/backup.c +++ b/src/backup.c @@ -438,8 +438,9 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync) */ if (nodeInfo->ptrack_version_num >= 20) make_pagemap_from_ptrack_2(backup_files_list, backup_conn, - nodeInfo->ptrack_schema, - prev_backup_start_lsn); + nodeInfo->ptrack_schema, + nodeInfo->ptrack_version_num, + prev_backup_start_lsn); else if (nodeInfo->ptrack_version_num == 15 || nodeInfo->ptrack_version_num == 16 || nodeInfo->ptrack_version_num == 17) @@ -884,15 +885,10 @@ do_backup(time_t start_time, bool no_validate, #endif get_ptrack_version(backup_conn, &nodeInfo); -// elog(WARNING, "ptrack_version_num %d", ptrack_version_num); + // elog(WARNING, "ptrack_version_num %d", ptrack_version_num); if (nodeInfo.ptrack_version_num > 0) - { - if (nodeInfo.ptrack_version_num >= 20) - nodeInfo.is_ptrack_enable = pg_ptrack_enable2(backup_conn); - else - nodeInfo.is_ptrack_enable = pg_ptrack_enable(backup_conn); - } + nodeInfo.is_ptrack_enable = pg_ptrack_enable(backup_conn, nodeInfo.ptrack_version_num); if (current.backup_mode == BACKUP_MODE_DIFF_PTRACK) { diff --git a/src/pg_probackup.h b/src/pg_probackup.h index 93af776c..79de41b8 100644 --- a/src/pg_probackup.h +++ b/src/pg_probackup.h @@ -999,11 +999,12 @@ extern void parse_filelist_filenames(parray *files, const char *root); /* in ptrack.c */ extern void make_pagemap_from_ptrack_1(parray* files, PGconn* backup_conn); extern void make_pagemap_from_ptrack_2(parray* files, PGconn* backup_conn, - const char *ptrack_schema, XLogRecPtr lsn); + const char *ptrack_schema, + int ptrack_version_num, + XLogRecPtr lsn); extern void pg_ptrack_clear(PGconn *backup_conn, int ptrack_version_num); extern void get_ptrack_version(PGconn *backup_conn, PGNodeInfo *nodeInfo); -extern bool pg_ptrack_enable(PGconn *backup_conn); -extern bool pg_ptrack_enable2(PGconn *backup_conn); +extern bool pg_ptrack_enable(PGconn *backup_conn, int ptrack_version_num); extern bool pg_ptrack_get_and_clear_db(Oid dbOid, Oid tblspcOid, PGconn *backup_conn); extern char *pg_ptrack_get_and_clear(Oid tablespace_oid, Oid db_oid, @@ -1011,7 +1012,8 @@ extern char *pg_ptrack_get_and_clear(Oid tablespace_oid, size_t *result_size, PGconn *backup_conn); extern XLogRecPtr get_last_ptrack_lsn(PGconn *backup_conn, PGNodeInfo *nodeInfo); -extern parray * pg_ptrack_get_pagemapset(PGconn *backup_conn, const char *ptrack_schema, XLogRecPtr lsn); +extern parray * pg_ptrack_get_pagemapset(PGconn *backup_conn, const char *ptrack_schema, + int ptrack_version_num, XLogRecPtr lsn); /* FIO */ extern int fio_send_pages(FILE* in, FILE* out, pgFile *file, XLogRecPtr horizonLsn, diff --git a/src/ptrack.c b/src/ptrack.c index a267f3f4..035bad13 100644 --- a/src/ptrack.c +++ b/src/ptrack.c @@ -217,19 +217,29 @@ get_ptrack_version(PGconn *backup_conn, PGNodeInfo *nodeInfo) * Check if ptrack is enabled in target instance */ bool -pg_ptrack_enable(PGconn *backup_conn) +pg_ptrack_enable(PGconn *backup_conn, int ptrack_version_num) { PGresult *res_db; + bool result = false; - res_db = pgut_execute(backup_conn, "SHOW ptrack_enable", 0, NULL); - - if (strcmp(PQgetvalue(res_db, 0, 0), "on") != 0) + if (ptrack_version_num < 20) { - PQclear(res_db); - return false; + res_db = pgut_execute(backup_conn, "SHOW ptrack_enable", 0, NULL); + result = strcmp(PQgetvalue(res_db, 0, 0), "on") == 0; } + else if (ptrack_version_num == 20) + { + res_db = pgut_execute(backup_conn, "SHOW ptrack_map_size", 0, NULL); + result = strcmp(PQgetvalue(res_db, 0, 0), "0") != 0; + } + else + { + res_db = pgut_execute(backup_conn, "SHOW ptrack.map_size", 0, NULL); + result = strcmp(PQgetvalue(res_db, 0, 0), "0") != 0; + } + PQclear(res_db); - return true; + return result; } @@ -459,7 +469,11 @@ get_last_ptrack_lsn(PGconn *backup_conn, PGNodeInfo *nodeInfo) { char query[128]; - sprintf(query, "SELECT %s.pg_ptrack_control_lsn()", nodeInfo->ptrack_schema); + if (nodeInfo->ptrack_version_num == 20) + sprintf(query, "SELECT %s.pg_ptrack_control_lsn()", nodeInfo->ptrack_schema); + else + sprintf(query, "SELECT %s.ptrack_init_lsn()", nodeInfo->ptrack_schema); + res = pgut_execute(backup_conn, query, 0, NULL); } @@ -526,7 +540,10 @@ pg_ptrack_get_block(ConnectionArgs *arguments, if (!ptrack_schema) elog(ERROR, "Schema name of ptrack extension is missing"); - sprintf(query, "SELECT %s.pg_ptrack_get_block($1, $2, $3, $4)", ptrack_schema); + if (ptrack_version_num == 20) + sprintf(query, "SELECT %s.pg_ptrack_get_block($1, $2, $3, $4)", ptrack_schema); + else + sprintf(query, "SELECT %s.ptrack_get_block($1, $2, $3, $4)", ptrack_schema); res = pgut_execute_parallel(arguments->conn, arguments->cancel_conn, @@ -566,30 +583,12 @@ pg_ptrack_get_block(ConnectionArgs *arguments, * ---------------------------- */ -/* - * Check if ptrack is enabled in target instance - */ -bool -pg_ptrack_enable2(PGconn *backup_conn) -{ - PGresult *res_db; - - res_db = pgut_execute(backup_conn, "SHOW ptrack.map_size", 0, NULL); - - if (strcmp(PQgetvalue(res_db, 0, 0), "0") == 0) - { - PQclear(res_db); - return false; - } - PQclear(res_db); - return true; -} - /* * Fetch a list of changed files with their ptrack maps. */ parray * -pg_ptrack_get_pagemapset(PGconn *backup_conn, const char *ptrack_schema, XLogRecPtr lsn) +pg_ptrack_get_pagemapset(PGconn *backup_conn, const char *ptrack_schema, + int ptrack_version_num, XLogRecPtr lsn) { PGresult *res; char lsn_buf[17 + 1]; @@ -604,8 +603,12 @@ pg_ptrack_get_pagemapset(PGconn *backup_conn, const char *ptrack_schema, XLogRec if (!ptrack_schema) elog(ERROR, "Schema name of ptrack extension is missing"); - sprintf(query, "SELECT path, pagemap FROM %s.pg_ptrack_get_pagemapset($1) ORDER BY 1", - ptrack_schema); + if (ptrack_version_num == 20) + sprintf(query, "SELECT path, pagemap FROM %s.pg_ptrack_get_pagemapset($1) ORDER BY 1", + ptrack_schema); + else + sprintf(query, "SELECT path, pagemap FROM %s.ptrack_get_pagemapset($1) ORDER BY 1", + ptrack_schema); res = pgut_execute(backup_conn, query, 1, (const char **) params); pfree(params[0]); @@ -647,16 +650,18 @@ pg_ptrack_get_pagemapset(PGconn *backup_conn, const char *ptrack_schema, XLogRec */ void make_pagemap_from_ptrack_2(parray *files, - PGconn *backup_conn, - const char *ptrack_schema, - XLogRecPtr lsn) + PGconn *backup_conn, + const char *ptrack_schema, + int ptrack_version_num, + XLogRecPtr lsn) { parray *filemaps; int file_i = 0; page_map_entry *dummy_map = NULL; /* Receive all available ptrack bitmaps at once */ - filemaps = pg_ptrack_get_pagemapset(backup_conn, ptrack_schema, lsn); + filemaps = pg_ptrack_get_pagemapset(backup_conn, ptrack_schema, + ptrack_version_num, lsn); if (filemaps != NULL) parray_qsort(filemaps, pgFileMapComparePath); diff --git a/tests/ptrack.py b/tests/ptrack.py index 4678708b..9f9dbac5 100644 --- a/tests/ptrack.py +++ b/tests/ptrack.py @@ -4052,7 +4052,7 @@ class PtrackTest(ProbackupTest, unittest.TestCase): log_content = f.read() self.assertIn( - 'FATAL: incorrect checksum of file "{0}"'.format(ptrack_map), + 'FATAL: ptrack init: incorrect checksum of file "{0}"'.format(ptrack_map), log_content) self.set_auto_conf(node, {'ptrack.map_size': '0'})