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

CBG-3382: Catch invalid state transition in asyncDatabaseOnline #6392

Merged
merged 2 commits into from
Sep 7, 2023

Conversation

bbrks
Copy link
Member

@bbrks bbrks commented Sep 6, 2023

Spun out of #6388

CBG-3382

  • Test to force an error from StartOnlineProcesses from asyncDatabaseOnline that causes an invalid state transition via missed return
  • Catch and panic with atomic.CompareAndSwap

Integration Tests

@bbrks bbrks changed the title Catch invalid state transition in asyncDatabaseOnline CBG-3382: Catch invalid state transition in asyncDatabaseOnline Sep 7, 2023
@bbrks bbrks requested a review from torcolvin September 7, 2023 11:23
Comment on lines 936 to 937
// 2nd atomic might end up being Starting here if there's a legitimate race, but it's the most we can do for CAS
panic(fmt.Sprintf("database state wasn't Starting during asyncDatabaseOnline Online transition... now %q", db.RunStateString[atomic.LoadUint32(&dbc.State)]))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we PanicfCtx and say that we can't do anything to recover from this state in the comment?

We can't take down a database because it's already coming online, so the best we can do is take down SG?

Or do you think this is unlikely to get hit and not worth panicking about?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... This was mostly to catch it more obviously via test if we decided to forget another return again. I'm not sure what we should do really. I don't expect this to end up panicing in a released version, but I might expect it in development/testing.

I agree about at least using PanicfCtx over panic though. Better chance of getting that logging captured.

@torcolvin torcolvin assigned bbrks and unassigned torcolvin Sep 7, 2023
@@ -934,7 +934,7 @@ func (sc *ServerContext) asyncDatabaseOnline(nonCancelCtx base.NonCancellableCon

if !atomic.CompareAndSwapUint32(&dbc.State, db.DBStarting, db.DBOnline) {
// 2nd atomic might end up being Starting here if there's a legitimate race, but it's the most we can do for CAS
panic(fmt.Sprintf("database state wasn't Starting during asyncDatabaseOnline Online transition... now %q", db.RunStateString[atomic.LoadUint32(&dbc.State)]))
base.PanicfCtx(ctx, "database state wasn't Starting during asyncDatabaseOnline Online transition... now %q", db.RunStateString[atomic.LoadUint32(&dbc.State)])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does ctx here have the database name? If so, that's a cool benefit of PanicfCtx.

If it doesn't, can you add the database name in the error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@bbrks bbrks merged commit cf74d2e into master Sep 7, 2023
13 checks passed
@bbrks bbrks deleted the fix_invalid_asyncDatabaseOnline_state_transition branch September 7, 2023 13:58
bbrks added a commit that referenced this pull request Sep 19, 2023
bbrks added a commit that referenced this pull request Sep 19, 2023
torcolvin pushed a commit that referenced this pull request Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants