Skip to content

fix(hc): Prevent exception from siloed_atomic #52326

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

Merged
merged 3 commits into from
Jul 6, 2023

Conversation

RyanSkonnord
Copy link
Contributor

An exception rises from router.db_for_write if the database doesn't exist in the environment, as observed with SENTRY_USE_SILOS set to true. Introduce a custom exception type to mark this condition, and catch it when setting the atomic impl. This should be equivalent behavior, as we only care about whether "missing" database is equal to using (which a null value won't be).

An exception rises from `router.db_for_write` if the database doesn't
exist in the environment, as observed with `SENTRY_USE_SILOS` set to
true. Introduce a custom exception type to mark this condition, and
catch it when setting the atomic impl. This should be equivalent
behavior, as we only care about whether "missing" database is equal to
`using` (which a null value won't be).
@RyanSkonnord RyanSkonnord requested a review from a team as a code owner July 6, 2023 00:29
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jul 6, 2023
@RyanSkonnord
Copy link
Contributor Author

Related to #51967.

@GabeVillalobos Let me know if you agree with my take on the error condition. You should be able to reproduce it by running SENTRY_USE_SILOS=1 sentry devserver from master. If you would expect router.db_for_write to return something in the (eventual) siloed production env, then maybe something about our devserver mode isn't behaving correctly.

@codecov
Copy link

codecov bot commented Jul 6, 2023

Codecov Report

Merging #52326 (b8ad81a) into master (56ad71a) will increase coverage by 1.59%.
The diff coverage is 77.77%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #52326      +/-   ##
==========================================
+ Coverage   77.72%   79.32%   +1.59%     
==========================================
  Files        4883     4909      +26     
  Lines      205442   205768     +326     
  Branches    35126    35168      +42     
==========================================
+ Hits       159681   163221    +3540     
+ Misses      40650    37561    -3089     
+ Partials     5111     4986     -125     
Impacted Files Coverage Δ
...zationGeneralSettings/organizationSettingsForm.tsx 91.66% <ø> (ø)
...entry/silo/patches/silo_aware_transaction_patch.py 77.14% <66.66%> (-0.64%) ⬇️
src/sentry/auth/providers/fly/provider.py 84.84% <100.00%> (+1.06%) ⬆️
src/sentry/db/router.py 71.76% <100.00%> (+0.68%) ⬆️

... and 301 files with indirect coverage changes

Resolve some failures in `tests/getsentry/db/test_router.py` where
ValueError is expected. We can make the tests narrower after this change
is pushed up to getsentry.
using == router.db_for_write(ControlOutbox)
and SiloMode.get_current_mode() != SiloMode.CONTROL
):
elif using == control_db and SiloMode.get_current_mode() != SiloMode.CONTROL:
raise MismatchedSiloTransactionError(
f"Cannot use transaction.atomic({using}) in Control Mode"
Copy link
Member

Choose a reason for hiding this comment

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

@RyanSkonnord unsure if these error copies need to be corrected.

Suggested change
f"Cannot use transaction.atomic({using}) in Control Mode"
f"Cannot use transaction.atomic({using}) in Region Mode"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, seems like those should be switched. Or perhaps should say "except in control mode". @GabeVillalobos?

Copy link
Member

Choose a reason for hiding this comment

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

That copy is much better 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great. But it's preexisting, so let's handle it in a separate PR.

Copy link
Member

Choose a reason for hiding this comment

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

Ahh yep 🙈 That's correct. I'll tackle it in this PR #52377 that is split from some of @corps work in Pr #52334

@RyanSkonnord RyanSkonnord merged commit 2da7d38 into master Jul 6, 2023
@RyanSkonnord RyanSkonnord deleted the siloed-atomic-availability-error branch July 6, 2023 18:39
@github-actions github-actions bot locked and limited conversation to collaborators Jul 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants