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.1k stars 3.81k forks source link

catalog: generalized cross-reference validation #77141

Open postamar opened 2 years ago

postamar commented 2 years ago

It's like double-entry bookkeeping, but for descriptors!

Presently, we have the GetReferencedDescIDs on catalog.Descriptor which returns the a set of descriptor IDs which includes all forward-referenced and back-referenced descriptor IDs. Well, that is, barring any bugs such as #77140.

The descriptor validation logic uses this method when validating a descriptor during its cross-reference checking (these are the checks that run at the catalog.ValidationLevelCrossReferences level). It uses it to load all descriptors to make them accessible via a ValidationDescGetter.

We want an extra generic validation check at the catalog.ValidationLevelCrossReferences level which checks that:

  1. for each validated descriptor,
  2. for each ID returned by GetReferencedDescIDs for the validated descriptor,
  3. the ID set returned by calling GetReferencedDescIDs on the descriptor in step (2) includes the ID of the descriptor in step (1).

This way, we can validate that each forward reference also has a back-reference, and vice-versa.

Jira issue: CRDB-13430

postamar commented 2 years ago

This functionality should be backported, provided that it's not too awkward to do so.

postamar commented 1 year ago

In the 22.2 release cycle, forward- and backward- reference checks are now done separately, which should make this easier.