-
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.
[#20300] YSQL: Fix CREATE INDEX failure in upgrading to perdb catalog…
… version mode Summary: To reproduce the bug, create a universe with `ysql_enable_db_catalog_version_mode=true` and `allowed_preview_flags_csv=ysql_enable_db_catalog_version_mode`. Do NOT execute the following ``` SET yb_non_ddl_txn_for_sys_tables_allowed=true; SELECT yb_fix_catalog_version_table(true); ``` Run the next test ``` yugabyte=# create table t(id int); CREATE TABLE yugabyte=# insert into t values(1); INSERT 0 1 yugabyte=# CREATE TABLE tempTable AS SELECT * FROM t limit 1000000; SELECT 1 yugabyte=# CREATE INDEX idx2 ON tempTable(id); NOTICE: Retrying wait for backends catalog version: Requested catalog version is too high: req version 2, master version 0 NOTICE: Retrying wait for backends catalog version: Requested catalog version is too high: req version 2, master version 0 NOTICE: Retrying wait for backends catalog version: Requested catalog version is too high: req version 2, master version 0 NOTICE: Retrying wait for backends catalog version: Requested catalog version is too high: req version 2, master version 0 ERROR: Requested catalog version is too high: req version 2, master version 0 ``` This configuration has an mismatch between --ysql_enable_db_catalog_version_mode and pg_yb_catalog_version: --ysql_enable_db_catalog_version_mode=true but pg_yb_catalog_version is still in global-catalog version mode (only has one row for database template1). This is a special configuration that can legitimately happen during cluster upgrade to a new release that has the per-database catalog version mode on by default. The new binary executables are upgraded first which will have --ysql_enable_db_catalog_version_mode=true, but the YSQL migration script will be executed at a later time in the finalization phase of the upgrade process. There is a tryout phase before the finalization phase to allow possible rolling back of the upgrade. The tryout phase can last for an extended period of time (e.g., 1 month). Therefore we need to support DDL statements during the tryout phase when the gflag is on but the table pg_yb_catalog_version isn't upgraded yet. However we should still advise customers not to run any DDL statements during the finalization phase which includes running the YSQL migration scripts (at present this is not enforced). I added a variable `catalog_version_table_in_perdb_mode_` that is used to cache the state of pg_yb_catalog_version: whether it has been upgraded to have one row per database. The intention is to only support rolling upgrade to per-database catalog version mode (not downgrade back to global catalog version mode). Therefore once set to true, the variable `catalog_version_table_in_perdb_mode_` is never reset back to false. This variable is introduced in both yb-master and yb-tserver. Normally PG request carries the catalog version mode as part of the RPC arguments (`ysql_catalog_version` vs `ysql_db_catalog_version`) and yb-tserver will respect that. Before this fix, when no PG request is available, yb-tserver only uses --ysql_enable_db_catalog_version_mode to tell which catalog version mode to use. After this fix, only when both the gflag --ysql_enable_db_catalog_version_mode and `catalog_version_table_in_perdb_mode_` are true, yb-tserver operates in per-database catalog version mode. This fixes the CREATE INDEX failure. The variable `catalog_version_table_in_perdb_mode_` is also stored in shared memory to allow fast PG access to improve the performance of `YBIsDBCatalogVersionMode()` by replacing `YbGetNumberOfDatabases() > 1)` so we avoid a local RPC call during the tryout phase. Jira: DB-9266 Test Plan: ./yb_build.sh --cxx-test pg_catalog_version-test Reviewers: jason, tverona Reviewed By: jason Subscribers: ybase, yql, bogdan Differential Revision: https://phorge.dev.yugabyte.com/D32299
- Loading branch information
Showing
18 changed files
with
101 additions
and
12 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
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