Skip to content

Commit a2ae264

Browse files
committed
[#9797] DocDB: Avoid catalog version going backward during online upgrade
Summary: Before and during a major YSQL version upgrade, through the heartbeat mechanism, the master provides current catalog versions to tservers from the PG11 catalog versions table. Note that DDLs are not allowed during a YSQL major version upgrade, and the PG15 catalogs are being updated by being set to semantic equivalents of PG11. To the PG11-only clients (tservers), there is only one valid catalog version state and that is the state when the upgrade began. While going through the upgrade flow, the C++ upgrade tests keep the cluster running while the YB master is switched out of upgrade mode. When the master is switched out of upgrade mode in this way, it switches to providing the current catalog versions from the PG15 catalog versions table, which is fresh and sets everything as version 1. Thus tservers see the version number going down and probabilistically crash themselves with the following error message: Ignoring ysql db 13245 catalog version update: new version too old. New: 1, Old: 2, ignored count: 31 Fix this incorrect state by copying the contents of the PG11 catalog versions table to PG15, right after the PG15 catalog is established, and before returning success of the catalog upgrade. Jira: DB-1591 Test Plan: Jenkins On MacOS arm64: ./yb_build.sh release --cxx-test pg15_upgrade-test On AlmaLinux 8: ./yb_build fastdebug --gcc11 --sj pg15_tests/get_shell_test_specs.sh | grep upgrade | pg15_tests/run_tests.sh Reviewers: hsunder Reviewed By: hsunder Subscribers: ybase, yql Differential Revision: https://phorge.dev.yugabyte.com/D38961
1 parent 407158d commit a2ae264

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/yb/master/ysql/ysql_initdb_major_upgrade_handler.cc

+19-3
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,25 @@ Status YsqlInitDBAndMajorUpgradeHandler::InitDBAndSnapshotSysCatalog(
153153
}
154154

155155
void YsqlInitDBAndMajorUpgradeHandler::RunMajorVersionUpgrade(const LeaderEpoch& epoch) {
156-
auto status = RunMajorVersionCatalogUpgrade(epoch);
157-
WARN_NOT_OK(
158-
MajorVersionCatalogUpgradeFinished(status, epoch), "Failed to run major version upgrade");
156+
auto status = RunMajorVersionUpgradeImpl(epoch);
157+
WARN_NOT_OK(MajorVersionCatalogUpgradeFinished(status, epoch),
158+
"Failed to run major version upgrade");
159+
}
160+
161+
Status YsqlInitDBAndMajorUpgradeHandler::RunMajorVersionUpgradeImpl(const LeaderEpoch& epoch) {
162+
RETURN_NOT_OK(RunMajorVersionCatalogUpgrade(epoch));
163+
RETURN_NOT_OK_PREPEND(UpdateCatalogVersions(epoch), "Failed to update catalog versions");
164+
return Status::OK();
165+
}
166+
167+
// pg_upgrade does not migrate the catalog version table, so we have to explicitly copy the contents
168+
// of the pre-existing catalog table to the PG15 version of the table.
169+
Status YsqlInitDBAndMajorUpgradeHandler::UpdateCatalogVersions(const LeaderEpoch& epoch) {
170+
RETURN_NOT_OK(sys_catalog_.DeleteAllYsqlCatalogTableRows({kPgYbCatalogVersionTableId},
171+
epoch.leader_term));
172+
RETURN_NOT_OK(sys_catalog_.CopyPgsqlTables({kPgYbCatalogVersionTableIdPg11},
173+
{kPgYbCatalogVersionTableId}, epoch.leader_term));
174+
return Status::OK();
159175
}
160176

161177
Status YsqlInitDBAndMajorUpgradeHandler::RunMajorVersionCatalogUpgrade(const LeaderEpoch& epoch) {

src/yb/master/ysql/ysql_initdb_major_upgrade_handler.h

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ class YsqlInitDBAndMajorUpgradeHandler {
5959

6060
void RunMajorVersionUpgrade(const LeaderEpoch& epoch);
6161

62+
Status RunMajorVersionUpgradeImpl(const LeaderEpoch& epoch);
63+
64+
Status UpdateCatalogVersions(const LeaderEpoch& epoch);
65+
6266
Status RunMajorVersionCatalogUpgrade(const LeaderEpoch& epoch);
6367

6468
// Runs the initdb process to create the initial ysql sys catalog and snapshot the sys_catalog if

0 commit comments

Comments
 (0)