cockroachdb / cockroach

CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.
https://www.cockroachlabs.com
Other
30.01k stars 3.79k forks source link

schemachanger: Rollback of creating unique index forgets to GC temp index #98340

Open Xiang-Gu opened 1 year ago

Xiang-Gu commented 1 year ago

When we create an unique secondary index that fails at validation step, we rollback. One of the last things rolling back does is to create GC jobs are this unique secondary index and its temp index. This is the case for legacy schema changer but not declarative schema changer, as shown below:

create table t (i int);
insert into t values (0), (0);

set use_declarative_schema_changer = off;
create unique index idx on t(i);
select job_id, job_type, description, statement from [show jobs] order by created desc;
846478262313582593 | SCHEMA CHANGE GC  | GC for temporary index used during index backfill                                                                                                                          
846478262309683201 | SCHEMA CHANGE GC  | GC for ROLLBACK of CREATE UNIQUE INDEX idx ON movr.public.t (i)                                                                                                                    
846478262167175169 | SCHEMA CHANGE     | CREATE UNIQUE INDEX idx ON movr.public.t (i)   

set use_declarative_schema_changer = unsafe_always;
create unique index idx on t(i);
select job_id, job_type, description, statement, status from [show jobs] order by created desc;
846478576135831553 | SCHEMA CHANGE GC  | GC for ROLLBACK of CREATE UNIQUE INDEX idx ON movr.public.t (i)                                           
846478575999778817 | NEW SCHEMA CHANGE | CREATE UNIQUE INDEX idx ON movr.public.t (i) 

Jira issue: CRDB-25201

ajwerner commented 1 year ago

This is bad, but doesn't seem super urgent. Generally we'd expect these temp indexes to not be very big.

We added a builtin to force GC of table data, but we didn't add an equivalent for indexes or an easy way to find such index spans. We could do something parallel to crdb_internal.force_delete_table_data and the virtual table crdb_internal.lost_table_descriptors.

ajwerner commented 1 year ago

Also, for context, this is new in 22.1, when we started using these temp indexes as part of the new index backfill protocol