Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[YSQL] Prevent objects created after dependent object dropped #15080

Open
jasonyb opened this issue Nov 19, 2022 · 1 comment
Open

[YSQL] Prevent objects created after dependent object dropped #15080

jasonyb opened this issue Nov 19, 2022 · 1 comment
Labels
area/ysql Yugabyte SQL (YSQL) kind/bug This issue is a bug priority/medium Medium priority issue
Projects

Comments

@jasonyb
Copy link
Contributor

jasonyb commented Nov 19, 2022

Jira Link: DB-4296

Description

It is possible to create objects as a user after that user is dropped by a different connection. Two possible ways:

  1. Breaking catalog change is not propagated: DropRole is a breaking catalog change, but catalog changes may not be communicated quickly enough such that one connection doing DROP USER and another connection quickly doing CREATE TABLE as that user can succeed.
  2. Transaction block takes catalog snapshot and doesn't check breaking catalog change unless DML is done: see below.

yugabyte: CREATE USER u;
u: BEGIN;
yugabyte: DROP USER u;
u: CREATE TABLE t (i int);
u: CREATE VIEW v AS SELECT * FROM t WHERE 1 > 5;
u: ALTER TABLE t ADD PRIMARY KEY (i);
u: CREATE FUNCTION f() RETURNS int LANGUAGE sql AS $$select 1;$$;
u: COMMIT;

I also managed to insert data into the table whose user was dropped, but I do not remember how and have a hard time reproducing.

The first way may possibly be fixed by catalog consistency project (#13369) part 1, depending on the implementation. The second way could be fixed by catalog consistency project part 2, also depending on part 1, if DDLs in txn block would be rolled back on txn block abort. That is not the case today. Then another way to catch it is to send catalog version in read/write requests to master sys catalog and validate it there (currently not done).

Part 1 has been discussed whether it can be relaxed to be eventually consistent, but that appears to be a problem with the specific examples here leaving the metadata inconsistent.

Example of what it looks like when user is dropped but object's owner is that user:

yugabyte=# \d
              List of relations
 Schema | Name | Type  |        Owner        
--------+------+-------+---------------------
 public | t    | table | unknown (OID=16488)
(1 row)
@jasonyb jasonyb added kind/bug This issue is a bug area/ysql Yugabyte SQL (YSQL) status/awaiting-triage Issue awaiting triage labels Nov 19, 2022
@yugabyte-ci yugabyte-ci added the priority/medium Medium priority issue label Nov 19, 2022
@jasonyb
Copy link
Contributor Author

jasonyb commented Dec 3, 2022

It appears creating view on nonexisting table is also a problem:

A: CREATE TABLE t (i int);
B: BEGIN;
A: DROP TABLE t;
B: CREATE VIEW v AS SELECT * FROM t;
B: COMMIT;
B: SELECT * FROM v;

ERROR:  cache lookup failed for relation 16384

I tried also

create foreign data wrapper useless;
create server useless_server foreign data wrapper useless; -- depending on fdw
create user mapping for yugabyte server useless_server; -- depending on server

create table rtest_t1 (a int4, b int4);
create view rtest_v1 as select * from rtest_t1;
create rule rtest_v1_del as on delete to rtest_v1 do instead delete from rtest_t1 where a = old.a; -- depending on view
COMMENT ON RULE rtest_v1_del ON rtest_v1 IS 'delete rule'; -- depending on rule

CREATE TEXT SEARCH CONFIGURATION alt_ts_conf1 (copy=english);
ALTER TEXT SEARCH CONFIGURATION alt_ts_conf1 RENAME TO alt_ts_conf3; -- depending on ts config

but those don't have issue. For some of them, I even tried doing ops to cache the metadata beforehand, but it didn't make a differenc. Have to take a close look to figure out why.

@jasonyb jasonyb changed the title [YSQL] Prevent objects created after user dropped [YSQL] Prevent objects created after dependent object dropped Dec 3, 2022
@jasonyb jasonyb added this to Backlog in YSQL via automation Dec 3, 2022
@yugabyte-ci yugabyte-ci removed the status/awaiting-triage Issue awaiting triage label Jan 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ysql Yugabyte SQL (YSQL) kind/bug This issue is a bug priority/medium Medium priority issue
Projects
YSQL
  
Backlog
Development

No branches or pull requests

2 participants