-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
sql: create an admin owned trash
database for dropped tables
#26476
Comments
As an alternative to targeting by ID in ALTER TABLE, we could have an undelete/undrop command to bring the table back from its "trash" state and give it a name again. Also, in either case, we'll need to make sure there's some way to discover the ID to use. |
good catch @benesch . The TestDropTableDeleteData test uses
but that facility is only available to root. |
My personal preference would be to have DROP of anything actually move the thing to a root-owned "trash" database, where it can be renamed from, until the data deletion actually completes (then the descriptor can be removed). |
Filed #26543 for per-ID access. |
trash
database for dropped tables
The goal here is to change DROP to rename the table to An admin can use Once this is complete, we will stop allowing AS OF SYSTEM TIME queries over the original table before the DROP timestamp. |
Some of what's covered by this longstanding issue came to the forefront in a recent incident. As a user, I should be able to change the GC TTL of a table after it's dropped, but I can't. We need to fix this. |
The proposal of the moment is to create a vtable which discovers all dropped descriptors which can hold zone configs (tables, materialized views, sequences, databases), and it lists
Then, additionally, we create a builtin which can be used by an admin to inject a new TTL for a given ID which is dropped. Taken together, this will allow users to find and update the TTL for dropped things. In terms of implementation details, the code which goes to write the zone config entry should make sure that the descriptor exists and is dropped in the same transaction that writes the new zone config entry. |
This commit adds a new virtual view which exposes which relations are currently being dropped and are waiting for garbage collection. Informs cockroachdb#26476. Release note (sql change): users can query crdb_internal.kv_dropped_relation to see which tables, materialized views and sequences are currently already dropped but have not yet been garbage collected, along with the garbage collection TTL setting that's currently in force. This setting originates from the table's own zone configuration, or from its parent database which it inherits, or in turn from the default zone configuration. These settings are typically set using ALTER TABLE ... CONFIGURE ZONE USING gc.ttlseconds = ...;
This new builtin can be used to set the GC TTL for tables, sequences and materialized views which have already been dropped. Fixes cockroachdb#26476. Release note (sql change): administrators may now call a new builtin function crdb_internal.upsert_dropped_relation_gc_ttl to retroactively set the garbage collection TTL on a table, materialized view or sequence which has already been dropped. Effectively, this retroactively performs ALTER TABLE ... CONFIGURE ZONE USING gc.ttlseconds = ... Note that this statement is prevented from being executed on dropped tables because they can no longer be referenced by name at that point. Usage of this builtin is typically in conjunction with the recently added crdb_internal.kv_dropped_relations virtual table. For example, garbage collection can be triggered ASAP for all dropped relations by querying: SELECT crdb_internal.upsert_dropped_relation_gc_ttl(id, '1 second') FROM crdb_internal.kv_dropped_relations; Doing so for all tables in a dropped database requires filtering on the parent_id column, the database name being lost at that point.
This commit adds a new virtual view which exposes which relations are currently being dropped and are waiting for garbage collection. Informs cockroachdb#26476. Release note (sql change): users can query crdb_internal.kv_dropped_relation to see which tables, materialized views and sequences are currently already dropped but have not yet been garbage collected, along with the garbage collection TTL setting that's currently in force. This setting originates from the table's own zone configuration, or from its parent database which it inherits, or in turn from the default zone configuration. These settings are typically set using ALTER TABLE ... CONFIGURE ZONE USING gc.ttlseconds = ...;
96217: sql: add crdb_internal.upsert_dropped_relation_gc_ttl builtin r=postamar a=postamar sql: add crdb_internal.upsert_dropped_relation_gc_ttl builtin This new builtin can be used to set the GC TTL for tables, sequences and materialized views which have already been dropped. Fixes #26476. Release note (sql change): administrators may now call a new builtin function crdb_internal.upsert_dropped_relation_gc_ttl to retroactively set the garbage collection TTL on a table, materialized view or sequence which has already been dropped. Effectively, this retroactively performs ALTER TABLE ... CONFIGURE ZONE USING gc.ttlseconds = ... Note that this statement is prevented from being executed on dropped tables because they can no longer be referenced by name at that point. Usage of this builtin is typically in conjunction with the recently added crdb_internal.kv_dropped_relations virtual table. For example, garbage collection can be triggered ASAP for all dropped relations by querying: SELECT crdb_internal.upsert_dropped_relation_gc_ttl(id, '1 second') FROM crdb_internal.kv_dropped_relations; Doing so for all tables in a dropped database requires filtering on the parent_id column, the database name being lost at that point. ---- sql: add crdb_internal.kv_dropped_relations virtual view This commit adds a new virtual view which exposes which relations are currently being dropped and are waiting for garbage collection. Informs #26476. Release note (sql change): users can query crdb_internal.kv_dropped_relation to see which tables, materialized views and sequences are currently already dropped but have not yet been garbage collected, along with the garbage collection TTL setting that's currently in force. This setting originates from the table's own zone configuration, or from its parent database which it inherits, or in turn from the default zone configuration. These settings are typically set using ALTER TABLE ... CONFIGURE ZONE USING gc.ttlseconds = ...; ---- sql: enable comments for virtual views This commit makes it possible to define hardcoded comments for virtual views, the same way it was already possible to do so for virtual tables. Fixes #95427. Release note: None Co-authored-by: Marius Posta <marius@cockroachlabs.com>
If you forget to change a table's GC TTL before you drop it, e.g via.
you won't ever be able to change it after
DROP TABLE foo
. You just can't name the table.🤦♂️
I think @knz might have plans to fix this by allowing you to target tables by ID in DDL statements. Regardless, we'll need to do some work even after we have the syntax to make sure
ALTER TABLE ... EXPERIMENTAL CONFIGURE ZONE
doesn't panic if it loads a dropped table desc.Jira issue: CRDB-5008
The text was updated successfully, but these errors were encountered: