Skip to content

sql: make deterministic descriptor ID generation possible #69226

@ajwerner

Description

@ajwerner

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:

// 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)T-sql-foundationsSQL Foundations Team (formerly SQL Schema + SQL Sessions)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions