-
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.
[#21199] YSQL: Refactor TRUNCATE to use table rewrite
Summary: This diff changes the `TRUNCATE` implementation (for both colocated and non-colocated tables) to use table rewrite. The new implementation is guarded by the auto-flag for table rewrite - `yb_enable_alter_table_rewrite`. Specific code changes: - Move the logic for creating a new DocDB table (relfilenode) from `cluster.c` to `YbRelationSetNewRelfileNode` in `pg_yb_utils.c`. - Change the `TRUNCATE` implementation: Simply drop the old DocDB table and create a new one using `YbRelationSetNewRelfileNode()`. After the new DocDB table (relfilenode) is created, `reindex_relation` re-creates the DocDB tables associated with the secondary indexes. Note: the PG OIDs of the table and its indexes remain unchanged. - `TRUNCATE` operations will now increment the catalog version, as they change the metadata of the affected tables (`pg_class.relfilenode`). - Changes in `index.c` (for `reindex_index()` and `RelationSetNewRelfilenode()`) -- move `YBCDropIndex()` out of `RelationSetNewRelfilenode()` and into the caller (`reindex_index()`). We do not need to perform a `YBCDropIndex()` in the case of a table rewrite, because dropping the base DocDB table will automatically drop all the secondary indexes. Additionally, execute `reindex_index()` for PK indexes. Although PK indexes do not need a new "relfilenode" in YB, we still want to reset their `pg_class.reltuples` entry (done in `RelationSetNewRelfilenode()`). - Since the new `TRUNCATE` approach does not require table level tombstones for colocated tables, we can, in the future, avoid tombstone checks on colocated tables. For this purpose, the diff also introduces a new tablet metadata field - `skip_table_tombstone_check`. This field is set for all newly created DocDB tables. In a subsequent diff, this field will also be set upon compaction, so that colocated tables that were created (and possibly truncated) on an older version of YB will not require tombstone checks. - Add an `is_truncate` field to create table requests -- used to allow `TRUNCATE`s on CDC tables if `enable_truncate_cdcsdk_table` is set. - Allow truncate with PITR. The existing flag `enable_truncate_on_pitr_table` now only applies to YCQL tables. - The flag `enable_delete_truncate_xcluster_replicated_table` now only applies to YCQL. Deletion is always allowed for YSQL tables in xCluster (existing behavior) and now, `TRUNCATE` is always disallowed. Test changes: - `TestMasterMetrics.java` : `TRUNCATE` uses table rewrite, so the relevant metrics are now under `Create_Tablet_Attempt` / `Create_Tablet_Task`. - `TestPgSavepoints.java` : add an extra commit to tests that use `TRUNCATE` so that we don't mix `TRUNCATE` with other DMLs (this would lead to the transaction being aborted). - `TestYbBackup.java` : can no longer use `TRUNCATE` in a test that performs a backup/restore into the same DB, as we do not support a restore into the same DB after DDLs have been performed. - `colocation-test.cc`: Deleted `CreateAndTruncateOnSeparateTables`. `TRUNCATE` bumps catalog version, so it is not expected to work concurrently with a `CREATE INDEX`. - `colocation-test.cc`: Refactor `InsertOnTablesWithFK`, `TransactionsOnTablesWithFK` : De-duplicate code between these two tests. Also, rewrite the test logic to fix potential flakiness. - `pg_fkey-test.cc`: All the tests in this file check RPC counts, which now change due to a different implementation of `TRUNCATE`. Simply change the `TRUNCATE` in `SetUp()` to a `DELETE` to fix this. - `pg_libpq-test.cc`: Reduce the number of iterations in `ConcurrentInsertAndDeleteOnTablesWithForeignKey` to prevent TSAN failures due to timeout. - `pg_tablet_shutdown-test.cc`: Disable retry on cache refresh so that we can correctly test abort due to tablet shutdown. - Refer to the "Test Plan" for new tests. Upgrade/Downgrade safety: - This feature is scoped under the existing `LocalPersisted` autoflag `yb_enable_alter_table_rewrite`. The feature will only be turned on after upgrade is finalized. Jira: DB-10129 Test Plan: Regress tests: `yb_truncate` and `yb_pg_truncate` Atomicity tests: `PgLibPqTableRewrite.TestTableRewriteRollback`, `PgLibPqTableRewrite.TestTableRewriteSuccess` Backup/restore tests: `YBBackupTestWithTableRewrite.TestYSQLBackupAndRestoreAfterRewrite`, `TestYSQLBackupAndRestoreAfterFailedRewrite` PITR test: `YbAdminSnapshotScheduleTestWithYsqlParam.PgsqlTestTruncate` xCluster test: `XClusterYsqlTest.TestTableRewriteOperations` CDC test: `CDCSDKYsqlTest.TestTableRewriteOperations` Reviewers: myang, asrivastava, timur, qhu, bogdan Reviewed By: myang, timur Subscribers: timur, arybochkin, yql, ybase, bogdan Differential Revision: https://phorge.dev.yugabyte.com/D32071
- Loading branch information
1 parent
c1bd57d
commit fad94f7
Showing
56 changed files
with
591 additions
and
336 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
Oops, something went wrong.