Skip to content
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

Post Commit step on User Creation can block for a long time #138691

Open
fantapop opened this issue Jan 8, 2025 · 2 comments
Open

Post Commit step on User Creation can block for a long time #138691

fantapop opened this issue Jan 8, 2025 · 2 comments
Assignees
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)

Comments

@fantapop
Copy link
Collaborator

fantapop commented Jan 8, 2025

Describe the problem

When running a CREATE USER statement while other long running transactions are happening, I've observed a long delay at transaction commit time. The new user is visible during this delay when running SHOW USERS.

Expected behavior
Ideally there would be no delay after creating a user amid these transactions.

Additional context

@rafiss has looked into this a bit and provided this high level summary:

when creating the user, we bump the "table version" of the CRDB users table. after committing the transaction that creates the user, there's a post-commit step that waits for all other transactions that are on the old version to finish.
(the "table version" is just a counter; the main purpose of it is to implement online schema changes, but it also helps with the cache we have for users)

He also says:

we're trying to determine if there's a different kind of waiting logic we can use. we don't actually need to wait for all the other long-running transactions, but we do need to wait for the other nodes to receive the cache invalidation signal.

I've created this ticket to track the necessary investigation.

Jira issue: CRDB-46303

@fantapop fantapop added C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) labels Jan 8, 2025
Copy link

blathers-crl bot commented Jan 8, 2025

Hi @fantapop, please add branch-* labels to identify which branch(es) this C-bug affects.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@rafiss
Copy link
Collaborator

rafiss commented Jan 14, 2025

The approach we might be able to use here is to change this logic:

ex.statsCollector.PhaseTimes().SetSessionPhaseTime(sessionphase.SessionStartPostCommitJob, crtime.NowMono())
if err := ex.waitForTxnJobs(); err != nil {
handleErr(err)
}
ex.statsCollector.PhaseTimes().SetSessionPhaseTime(sessionphase.SessionEndPostCommitJob, crtime.NowMono())
// If descriptors are either modified or created wait then we may have to
// wait for one version (if no job exists) or the initial version to be
// acquired.
if ex.extraTxnState.descCollection.HasUncommittedDescriptors() {
cachedRegions, err := regions.NewCachedDatabaseRegions(ex.Ctx(), ex.server.cfg.DB, ex.server.cfg.LeaseManager)
if err != nil {
return advanceInfo{}, err
}
if err := ex.waitOneVersionForNewVersionDescriptorsWithoutJobs(descIDsInJobs, cachedRegions); err != nil {
return advanceInfo{}, err
}
if err := ex.waitForInitialVersionForNewDescriptors(cachedRegions); err != nil {
return advanceInfo{}, err
}
}

Instead of waiting for one version for the system.role_members table (and other system tables), we should be able to wait for the two version invariant. We would need to find a way to only use this different waiting logic for the case of bumping internal system tables for cache invalidation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Projects
None yet
Development

No branches or pull requests

2 participants