Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BACKPORT 2.20][#19975] YSQL: Fix assertion failure in per-database c…
…atalog version Summary: To reproduce the bug: 1. Create a cluster and convert it into per-database catalog version mode ``` yugabyte=# select * from pg_yb_catalog_version; db_oid | current_version | last_breaking_version --------+-----------------+----------------------- 1 | 1 | 1 13242 | 1 | 1 13243 | 1 | 1 13245 | 1 | 1 13246 | 1 | 1 (5 rows) ``` The above query output indicates that the cluster is running in per-database catalog version mode. 2. Run the following DDL global-impact DDL statement ``` yugabyte=# ALTER ROLE yugabyte SUPERUSER; server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. ``` In the PG log: ``` F1122 01:04:40.396021 15991 pg_txn_manager.cc:346] Check failed: !IsDdlMode() READ COMMITTED semantics don't apply to DDL transactions ``` This happens when we call `yb_increment_all_db_catalog_versions` to increment catalog versions for all databases. This is done inside function `YBDecrementDdlNestingLevel` which first does ``` --ddl_transaction_state.nesting_level; ``` and then if `ddl_transaction_state.nesting_level == 0` it calls `yb_increment_all_db_catalog_versions` if the current DDL statement has global impact. In `GetTransactionSnapshot` we have ``` if (IsYBReadCommitted() && YBGetDdlNestingLevel() == 0) ``` The function `yb_increment_all_db_catalog_versions` is still called as part of the DDL statement, but `ddl_transaction_state.nesting_level` is already 0 so `YBGetDdlNestingLevel()` returns 0. As a result the above `if` condition is true and the DDL statement is treated as a non-DDL statement, eventually leading to the assertion failure. The DDL mode is already transferred to pggate when we call `YBCPgEnterSeparateDdlTxnMode`. So I added `YBCPgIsDdlMode()` and uses it to replace `YBGetDdlNestingLevel() == 0`. I reverted some work arounds in `pg_catalog_version-test.cc` which used snapshot isolation because otherwise those unit tests would fail under read committed isolation. Original commit: 417e2de / D30417 Test Plan: ./yb_build.sh debug --cxx-test pg_catalog_version-test Reviewers: tvesely, pjain Reviewed By: tvesely Subscribers: yql Tags: #jenkins-ready Differential Revision: https://phorge.dev.yugabyte.com/D30840
- Loading branch information