Skip to content

Commit

Permalink
[#24818] YSQL: Add a test guc to fail drop commands
Browse files Browse the repository at this point in the history
Summary:
Add a test guc `yb_test_fail_all_drops` to fail all drop commands.
The GUC can be set per-session by a superuser.
Jira: DB-13922

Test Plan:
Manually tested.

```
yugabyte=# CREATE TABLE test (t int);
CREATE TABLE
yugabyte=# CREATE VIEW test2 AS SELECT * FROM test;
CREATE VIEW
yugabyte=# CREATE INDEX test3 ON test(t);
CREATE INDEX
yugabyte=# SET yb_test_fail_all_drops=true;
SET
yugabyte=# DROP INDEX test3;
ERROR:  TEST: failed drop operation as requested
HINT:  GUC yb_test_fail_all_drops is set to true.
yugabyte=# DROP VIEW test2;
ERROR:  TEST: failed drop operation as requested
HINT:  GUC yb_test_fail_all_drops is set to true.
yugabyte=# DROP TABLE test;
ERROR:  TEST: failed drop operation as requested
HINT:  GUC yb_test_fail_all_drops is set to true.
yugabyte=# RESET yb_test_fail_all_drops;
RESET
yugabyte=#  DROP INDEX test3;
DROP INDEX
yugabyte=# DROP VIEW test2;
DROP VIEW
yugabyte=# DROP TABLE test;
DROP TABLE
```

Reviewers: telgersma

Reviewed By: telgersma

Subscribers: yql

Differential Revision: https://phorge.dev.yugabyte.com/D39772
  • Loading branch information
fizaaluthra committed Nov 7, 2024
1 parent ee0a10e commit 27d3917
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/postgres/src/backend/tcop/utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -2102,6 +2102,12 @@ ProcessUtilityForAlterTable(Node *stmt, AlterTableUtilityContext *context)
static void
ExecDropStmt(DropStmt *stmt, bool isTopLevel)
{
if (yb_test_fail_all_drops && isTopLevel)
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR),
errmsg("TEST: failed drop operation as requested"),
errhint("GUC yb_test_fail_all_drops is set to true.")));

switch (stmt->removeType)
{
case OBJECT_INDEX:
Expand Down
11 changes: 11 additions & 0 deletions src/postgres/src/backend/utils/misc/guc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2586,6 +2586,17 @@ static struct config_bool ConfigureNamesBool[] =
NULL, NULL, NULL
},

{
{"yb_test_fail_all_drops", PGC_SUSET, DEVELOPER_OPTIONS,
gettext_noop("When set, all drops will fail"),
NULL,
GUC_NOT_IN_SAMPLE
},
&yb_test_fail_all_drops,
false,
NULL, NULL, NULL
},

{
{"yb_test_fail_next_inc_catalog_version", PGC_USERSET,DEVELOPER_OPTIONS,
gettext_noop("When set, the next increment catalog version will "
Expand Down
2 changes: 2 additions & 0 deletions src/postgres/src/backend/utils/misc/pg_yb_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1662,6 +1662,8 @@ bool yb_test_system_catalogs_creation = false;

bool yb_test_fail_next_ddl = false;

bool yb_test_fail_all_drops = false;

bool yb_test_fail_next_inc_catalog_version = false;

double yb_test_ybgin_disable_cost_factor = 2.0;
Expand Down
3 changes: 3 additions & 0 deletions src/postgres/src/include/pg_yb_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,9 @@ extern bool yb_test_system_catalogs_creation;
*/
extern bool yb_test_fail_next_ddl;

/* If set to true, all drop commands will fail. */
extern bool yb_test_fail_all_drops;

/*
* If set to true, next increment catalog version operation will fail and
* reset this back to false.
Expand Down

0 comments on commit 27d3917

Please sign in to comment.