-
Notifications
You must be signed in to change notification settings - Fork 4.1k
sql: make deterministic descriptor ID generation possible #69226
Description
Is your feature request related to a problem? Please describe.
Descriptor IDs are allocated by incrementing a constant key non-transactionally. This means that descriptor ID generation is non-deterministic in the face of transaction retries. This can be painful for logictests and tests in general which would like to depend on deterministic ID generation. Consider #69225.
The generation occurs here:
cockroach/pkg/sql/catalog/catalogkv/catalogkv.go
Lines 39 to 44 in b711b24
| // GenerateUniqueDescID returns the next available Descriptor ID and increments | |
| // the counter. The incrementing is non-transactional, and the counter could be | |
| // incremented multiple times because of retries. | |
| func GenerateUniqueDescID(ctx context.Context, db *kv.DB, codec keys.SQLCodec) (descpb.ID, error) { | |
| // Increment unique descriptor counter. | |
| newVal, err := kv.IncrementValRetryable(ctx, db, codec.DescIDSequenceKey(), 1) |
Describe the solution you'd like
We should make an interface around descriptor ID generation and then plumb through an implementation of that interface. That may permit deterministic allocation. The wrinkle here is that we'd want such a thing to likely have a handle to a transaction, meaning that it'd likely need to be constructed with a transaction or add a transaction to the API.
Describe alternatives you've considered
We can keep hacking around flakes related to the assumed determinism. Another option is to randomize the allocation under testing to shake out any reliance on the determinism.
Jira issue: CRDB-9500