-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#21230] YSQL: Fix create index error "Requested catalog version is t…
…oo high" Summary: Recent commit a76f9e6 introduced DDL support during the tryout phase in the new cluster upgrade work flow. When upgrading to a release that has the gflag `--ysql_enable_db_catalog_version_mode` default on, during the tryout phase, the table `pg_yb_catalog_version` is still in global-mode: it has only one row for database `template`. The above commit introduced a regression: What happened is that yb-master used to only rely on the gflag `--ysql_enable_db_catalog_version_mode=true` to decide whether it operates in perdb mode or not. After the above change, it also reads the `pg_yb_catalog_version` table to see if it has more than 1 rows. Only when both conditions are met, master will start to operate in perdb mode. But it is reading `pg_yb_catalog_version` as part of heartbeat response message preparation. Let’s say after a new master leader is elected, before it receives the very first heartbeat request, it receives a request to get the current catalog version operation mode: its `catalog_version_table_in_perdb_mode_` is initialized to `false` so it will return `false`. But that’s not right, it should be unknown or return an error, because the value isn’t set yet. Without doing a just-in-time read of `pg_yb_catalog_version` the master does not know which mode it should return. Because it returns false, the caller will think this new master leader still operates in global catalog version mode. In global catalog version mode it will read the current version from `template1` in `pg_yb_catalog_version`, that’s incorrect because in reality `pg_yb_catalog_version` has multiple rows already. When a cluster already runs in perdb mode, there should not be any initial moment when the master **thinks** it runs in global mode and later switch to perdb mode when it receives a tserver heartbeat request. Same issue also exists in tserver and PG backend. In tserver, when a tserver is restarted, it may not have received heartbeat response from master yet to properly initialize its `catalog_version_table_in_perdb_mode_`. Likewise, PG backend should wait for the `catalog_version_table_in_perdb_mode_` in shared memory to properly initialize. At master side, I fixed the bug by adding a new function that will do on-demand read of `pg_yb_catalog_version` table when --ysql_enable_db_catalog_version_mode=true and `catalog_version_table_in_perdb_mode_` is still false (`CatalogManager::IsCatalogVersionTableInPerdbMode`). Once `catalog_version_table_in_perdb_mode_` is set to true, it remains so and will not be affected even if the table `pg_yb_catalog_version` is later changed back to global mode. For tserver and PG backend, I changed `catalog_version_table_in_perdb_mode_` from bool to std::optional<bool> so that we can tell whether the variable has been properly initialized. Added a new unit test which has a TEST gflag. Jira: DB-10157 Test Plan: (1) ./yb_build.sh --cxx-test pg_catalog_version-test (2) Verify that when the new unit test (and the new TEST gflag) is run without the fix, it would fail with an error like: ``` Bad status: Network error (yb/yql/pgwrapper/libpq_utils.cc:410): Execute of 'CREATE INDEX idx ON t(id)' failed: 7, message: ERROR: Requested catalog version is too high: req version 3, master version 1 (pgsql error XX000) (aux msg ERROR: Requested catalog version is too high: req version 3, master version 1) ``` (3) With QA help, ran the test that reported this bug on two clusters and verified the fix successfully. Reviewers: jason, tverona Reviewed By: jason Subscribers: yql, ybase, bogdan Differential Revision: https://phorge.dev.yugabyte.com/D32738
- Loading branch information
Showing
13 changed files
with
117 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters